[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Quasi-macros ?
From: |
david |
Subject: |
Re: Quasi-macros ? |
Date: |
Mon, 10 Feb 2003 17:33:19 +0100 |
User-agent: |
Mutt/1.4i |
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
address@hidden | address@hidden
TeXmacs is NOT a LaTeX front-end and is unrelated to emacs.
- Quasi-macros ?, Joris van der Hoeven, 2003/02/09
- Re: Quasi-macros ?,
david <=