From: david@allouche.net
Cc: guile-user@gnu.org
Subject: Re: Quasi-macros ?
Date: Mon, 10 Feb 2003 17:33:19 +0100 [thread overview]
Message-ID: <20030210163319.GH3810@joe.xlii.org> (raw)
In-Reply-To: <Pine.GSO.3.96.1030209201831.26546C-100000@anh>
On Sun, Feb 09, 2003 at 08:23:23PM +0100, Joris van der Hoeven wrote:
>
> (define (define-table-decls name l)
> (if (null? l) l
> (cons `(hash-set! ,name ',(caar l) ',(cadar l))
> (define-table-decls name (cdr l)))))
>
> (define-macro (define-table name . l)
> `(begin
> (define ,name (make-hash-table ,(+ (* (length l) 2) 1)))
> ,@(define-table-decls name l)))
>
> (define-table test
> (hello hoi)
> (joke grapje)
> (gnu blauwbilgorgel))
>
> This allows you to define many tables in a nice way.
> Sometimes however, it would be nice to write things like
>
> (define-table the-question
> (two ,(+ 1 1))
> (four ,(* 2 2)))
>
> Someone has an idea of how to do this *without* explicitly
> using 'eval', which might result in loosing the context?
It looks like quasiquote has special behaviour when it comes to
quoting himself... However, with a bit of hacking you can do what you
want.
(define (define-table-decls h l)
(define (sub ll) (hash-set! h (car ll) (cadr ll)))
(for-each sub l))
(define-macro (define-table name . l)
`(begin
(define ,name (make-hash-table ,(+ (* (length l) 2) 1)))
(define-table-decls ,name ,(list 'quasiquote l))))
(define-table the-question
(two ,(+ 1 1))
(four ,(* 2 2)))
--
David Allouche | GNU TeXmacs -- Writing is a pleasure
Free software engineer | http://www.texmacs.org
http://ddaa.net | http://alqua.com/tmresources
david@allouche.net | allouche@texmacs.org
TeXmacs is NOT a LaTeX front-end and is unrelated to emacs.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
prev parent reply other threads:[~2003-02-10 16:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-09 19:23 Quasi-macros ? Joris van der Hoeven
2003-02-10 16:33 ` david [this message]
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=20030210163319.GH3810@joe.xlii.org \
--to=david@allouche.net \
--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).