* with-slot syntax how to
@ 2007-10-11 21:01 Marco Maggi
0 siblings, 0 replies; 2+ messages in thread
From: Marco Maggi @ 2007-10-11 21:01 UTC (permalink / raw)
To: guile-user
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: with-slot syntax how to
@ 2007-10-13 6:12 Marco Maggi
0 siblings, 0 replies; 2+ messages in thread
From: Marco Maggi @ 2007-10-13 6:12 UTC (permalink / raw)
To: guile-user
damn:
(define-syntax with-slots
(syntax-rules ()
;;this is here only to let me remove the bindings
while
;;debugging the form
((_ ((() () ?object)) ?form ...)
(begin ?form ...))
((_ (((?sym ...) (?slot ...) ?object)) ?form ...)
(let ((?sym (slot-ref ?object '?slot))
...)
?form ...))
((_ (((?sym1 ...) (?slot1 ...) ?object1)
((?sym2 ...) (?slot2 ...) ?object2)
...) ?form ...)
(with-slots (((?sym1 ...) (?slot1 ...) ?object1))
(with-slots (((?sym2 ...) (?slot2 ...) ?object2) ...)
?form ...)))))
--
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-10-13 6:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-11 21:01 with-slot syntax how to Marco Maggi
-- strict thread matches above, loose matches on Subject: below --
2007-10-13 6:12 Marco Maggi
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).