From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Marco Maggi" Newsgroups: gmane.lisp.guile.user Subject: with-slot syntax how to Date: Thu, 11 Oct 2007 23:01:45 +0200 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1192136547 2513 80.91.229.12 (11 Oct 2007 21:02:27 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 11 Oct 2007 21:02:27 +0000 (UTC) To: "guile-user" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Oct 11 23:02:25 2007 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Ig5Ac-0008Sz-FS for guile-user@m.gmane.org; Thu, 11 Oct 2007 23:02:14 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ig5AW-0003uB-HU for guile-user@m.gmane.org; Thu, 11 Oct 2007 17:02:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ig5AD-0003e0-P0 for guile-user@gnu.org; Thu, 11 Oct 2007 17:01:49 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ig5AC-0003cK-Ke for guile-user@gnu.org; Thu, 11 Oct 2007 17:01:49 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ig5AC-0003bz-Dr for guile-user@gnu.org; Thu, 11 Oct 2007 17:01:48 -0400 Original-Received: from relay-pt4.poste.it ([62.241.4.118]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Ig5AB-0005JA-Q2 for guile-user@gnu.org; Thu, 11 Oct 2007 17:01:48 -0400 Original-Received: from poste.it (192.168.144.52) by relay-pt4.poste.it (7.3.122) (authenticated as marco.maggi-ipsu@poste.it) id 470D59E00001FE02 for guile-user@gnu.org; Thu, 11 Oct 2007 23:01:45 +0200 X-Sensitivity: 3 X-XaM3-API-Version: 4.3 (R1) (B3pl19) X-SenderIP: 83.190.104.87 X-detected-kernel: by monty-python.gnu.org: Solaris 9 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6212 Archived-At: 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 () (a #:init-keyword #:a) (b #:init-keyword #:b) (c #:init-keyword #:c)) (define A (make #:a 1 #:b 2 #:c 3)) (define B (make #: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