[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
with-slot syntax how to
From: |
Marco Maggi |
Subject: |
with-slot syntax how to |
Date: |
Thu, 11 Oct 2007 23:01:45 +0200 |
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"
- with-slot syntax how to,
Marco Maggi <=