From: "Marco Maggi" <marco.maggi-ipsu@poste.it>
To: "guile-user" <guile-user@gnu.org>
Subject: with-slot syntax how to
Date: Thu, 11 Oct 2007 23:01:45 +0200 [thread overview]
Message-ID: <JPRMEX$0A9D5243D56741F4339DB1CF6AE105FF@poste.it> (raw)
Ciao,
in my quest for learning how to write syntaxes
I tried to write a WITH-SLOTS, getter only
version. I was not able to write it with SYNTAX-RULES only,
My better result so far is the dirty:
(define-module (hurt-me)
#:use-module (ice-9 syncase)
#:use-module (oop goops)
#:duplicates merge-generics)
(define-macro (gee-p-with-slots ?bindings . ?forms)
(let ((result ?forms))
(for-each (lambda (object-bindings)
(set! result `((with-slots ,object-bindings ,@result))))
?bindings)
(car result)))
(define-syntax with-slots
(syntax-rules ()
((_ (() ?object) ?form ...)
(begin ?form ...))
;; only one parens level in the 'with-slots' first arg
((_ ((?sym ...) (?slot ...) ?object) ?form ...)
(let ((?sym (slot-ref ?object '?slot))
...)
?form ...))
;; two parens level in the 'with-slots' first arg
((_ (((?sym ...) (?slot ...) ?object)) ?form ...)
(let ((?sym (slot-ref ?object '?slot))
...)
?form ...))
((_ (((?sym ...) (?slot ...) ?object) ...) ?form ...)
(gee-p-with-slots (((?sym ...) (?slot ...) ?object)
...) ?form ...))))
(define-class <C> ()
(a #:init-keyword #:a)
(b #:init-keyword #:b)
(c #:init-keyword #:c))
(define A (make <C>
#:a 1 #:b 2 #:c 3))
(define B (make <C>
#:a 4 #:b 5 #:c 6))
(with-slots (((d e f) (a b c) A)
((g h i) (a b c) B))
(write (list d e f g h i)))
is it even possible to write it with SYNTAX-RULES only?
--
Marco Maggi
"Now feel the funk blast!"
Rage Against the Machine - "Calm like a bomb"
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
next reply other threads:[~2007-10-11 21:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-11 21:01 Marco Maggi [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-10-13 6:12 with-slot syntax how to Marco Maggi
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='JPRMEX$0A9D5243D56741F4339DB1CF6AE105FF@poste.it' \
--to=marco.maggi-ipsu@poste.it \
--cc=guile-user@gnu.org \
/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).