guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mixing syntax-rule and indentifier-syntax


From: Tobias Brandt
Subject: Re: Mixing syntax-rule and indentifier-syntax
Date: Wed, 18 Jan 2012 00:26:56 +0100

> 0. I'm sure there is another way, but my mind blanks at the moment

After you got me started, I was able to simplify and generalize it a bit.
(-> is a GOOPS generic accessor I defined elsewhere. It works with
vectors, arrays, strings, etc ...)
(define-syntax with-accessors  (lambda (stx)    (syntax-case stx ()
  ((_ (id ...) exp ...)       #`(begin           #,@(let (;; checks if
arg is in the list of identifiers (id ...)
(in-list? (lambda (arg)                                 (exists
(lambda (x) (bound-identifier=? x arg))
        #'(id ...)))))                ;; transform each expression in
exp ...                (map (lambda (clause)
(syntax-case clause (set!)                         ;; setter
              ((set! (arg idx ...) val)
(in-list? #'arg)                          #'((setter ->) arg idx ...
val))                         ;; getter                         ((arg
idx ...)                          (in-list? #'arg)
     #'(-> arg idx ...))                         (id #'id)))
          #'(exp ...))))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]