0
votes

I'm trying to write let over lambda defmacro/g! in guile scheme. I have this:

(use-modules (srfi srfi-1))

(define (flatten x)
    (let rec ((x x) (acc '()))
         (cond ((null? x) acc)
               ((not (pair? x)) (cons x acc))
               (else
                (rec (car x)
                     (rec (cdr x) acc))))))

(define (g!-symbol? s)
  (and (symbol? s)
       (let ((symbol-string (symbol->string s)))
         (and (> (string-length symbol-string) 2)
              (equal? (string-downcase (substring symbol-string 0 2)) "g!")))))


(define-macro (define-macro/g! name-args . body)
    (let ((syms (delete-duplicates
                 (filter g!-symbol? (flatten body)))))
    `(define-macro ,name-args
         (let ,(map
                (lambda (s)
                  `(,s (gensym ,(substring (symbol->string s) 2))))
                syms)
           ,@body))))

but when I try to macro expand define-macro/g! using this:

(use-modules (language tree-il))
(tree-il->scheme (macroexpand '(define-macro/g! (foo . body) `(let ((g!car ,(car body))) g!car))))

I've got this:

$15 = (if #f #f)

why I've got this result? How can I expand define-macro/g!?

1
I don't really understand what you are trying to achieve. Do you want to filter an argument list? Are you sure that syntax-rules isn't what you want?Michael Vehrs

1 Answers

0
votes

I need to use this code:

(define macro '(define-macro/g! (foo . body) `(let ((g!car ,(car body))) g!car)))
(tree-il->scheme (macroexpand macro 'c '(compile load eval)))