first go at procedural macros pasted by siiky on Mon Feb 7 23:53:21 2022
(import procedural-macros) (import-for-syntax (only srfi-13 string-concatenate) (only srfi-1 any) ) (define (make-name components) (string->symbol (string-join (map symbol->string components) "/"))) (define-macro (defmeth components . optionals) (cond ((null? components) (syntax-error "The endpoint path must not be empty")) ((any (lambda (opt) (not (= (length opt) 2))) optionals) (syntax-error "The optional parameters must have the form (type param)")) (else (let ((name (make-name components))) `(define (,name ,@components) 42))))) (defmeth (a b c)) ; Error: during expansion of (defmeth ...) - unbound variable: make-name ; ; Call history: ; ; <syntax> (##core#begin (defmeth (a b c))) ; <syntax> (defmeth (a b c)) ; <eval> (cdr89 form92) ; <eval> (seq-ref119 seq124 0) ; <eval> (seq-tail121 seq124 1) ; <eval> (null? components) ; <eval> (any (lambda (opt) (not (= (length opt) 2))) optionals) ; <eval> (make-name components) <--
second go at procedural macros pasted by siiky on Tue Feb 8 00:00:42 2022
(import procedural-macros) (import-for-syntax (only srfi-13 string-concatenate) (only srfi-1 any) ) (define (make-name components) (string->symbol (string-join (map symbol->string components) "/"))) ; sorry for crappy indentation (define-macro (defmeth components . optionals) (with-implicit-renaming (=? %name) (cond ((null? components) (syntax-error "The endpoint path must not be empty")) ((any (lambda (opt) (not (= (length opt) 2))) optionals) (syntax-error "The optional parameters must have the form (type param)")) (else (let ((%name (make-name components))) `(define (,%name ,@components) 42)))))) (defmeth (a b c)) ; Error: during expansion of (defmeth ...) - unbound variable: make-name ; ; Call history: ; ; <syntax> (##core#begin (defmeth (a b c))) ; <syntax> (defmeth (a b c)) ; <eval> (cdr89 form92) ; <eval> (seq-ref119 seq124 0) ; <eval> (seq-tail121 seq124 1) ; <eval> (inject94 (quote name)) ; <eval> (null? components) ; <eval> (any (lambda (opt) (not (= (length opt) 2))) optionals) ; <eval> (make-name components) <--
third go at procedural macros added by siiky on Tue Feb 8 00:27:20 2022
(import procedural-macros) (import-for-syntax (only srfi-13 string-join) (only srfi-1 any) ) (define-macro (defmeth components . optionals) (with-implicit-renaming (=? %name) (cond ((null? components) (syntax-error "The endpoint path must not be empty")) ((any (lambda (opt) (not (= (length opt) 2))) optionals) (syntax-error "The optional parameters must have the form (type param)")) (else (let* ((make-name (lambda (components) (string->symbol (string-join (map symbol->string components) "/")))) (%name (make-name components))) `(define (,%name ,@components) 42)))))) (defmeth (a b c)) (print (a/b/c 1 2 3)) ; $ csc pm.scm ; # all is well ; $ ./pm ; Error: unbound variable: a/b/c ; ; Call history: ; ; pm.scm:1: chicken.load#load-extension ; pm.scm:27: a/b/c <--