unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Tobias Brandt <tob.brandt@googlemail.com>
To: Ian Price <ianprice90@googlemail.com>
Cc: guile-user@gnu.org
Subject: Re: Mixing syntax-rule and indentifier-syntax
Date: Wed, 18 Jan 2012 00:26:56 +0100	[thread overview]
Message-ID: <CAOOWqir6ON_69fdYbN0hq-V6u0CES_Ei+LNkBrPC_byWZxGsdg@mail.gmail.com> (raw)
In-Reply-To: <87aa5mhu6r.fsf@Kagami.home>

> 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	other threads:[~2012-01-17 23:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-16 23:11 Mixing syntax-rule and indentifier-syntax Tobias Brandt
2012-01-17  9:22 ` Andy Wingo
2012-01-17 21:53 ` Ian Price
2012-01-17 23:26   ` Tobias Brandt [this message]
2012-01-18 16:23     ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOOWqir6ON_69fdYbN0hq-V6u0CES_Ei+LNkBrPC_byWZxGsdg@mail.gmail.com \
    --to=tob.brandt@googlemail.com \
    --cc=guile-user@gnu.org \
    --cc=ianprice90@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).