[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] hygienic egg PORT-A-MANIA!
From: |
John Cowan |
Subject: |
Re: [Chicken-users] hygienic egg PORT-A-MANIA! |
Date: |
Mon, 25 Aug 2008 12:36:17 -0400 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
Alan Post scripsit:
> I've been watching the progress on the hygenic branch, but I haven't
> been worried about porting code until now. I tend to use macros
> here and there, but almost always in very simple #define-like uses:
>
> (define-macro (char->number ch)
> `(- (char->integer ,ch)
> (char->integer #\0)))
>
> (define-macro (0= n)
> `(= 0 ,n))
Note that as written, these will not work properly if - or char->integer
or = have been redefined at the point of use: you'll get the local
definitions rather than the global definitions you expect. (This isn't
as much of an issue in Common Lisp, where redefinition of standard
functions is not allowed, and variable names and function names are in
separate namespaces.)
On the other hand, it's trivial to rewrite these using syntax-rules, thus:
(define-syntax char->number (syntax-rules ()
((char->number ch) (- (char->integer ch) (char->integer #\0)))))
(define-syntax 0= (syntax-rules ()
((=0 n) (= 0 n))))
For more explanations of syntax-rules, read the excellent
"JRM's Syntax-rules Primer for the Merely Eccentric" at
http://www.xs4all.nl/~hipster/lib/scheme/gauche/define-syntax-primer.txt .
But on the gripping hand, defining little things like this as procedures
rather than macros is not likely to cost you very much. Premature
optimization is the root of all evil.
--
John Cowan address@hidden http://www.ccil.org/~cowan
O beautiful for patriot's dream that sees beyond the years
Thine alabaster cities gleam undimmed by human tears!
America! America! God mend thine every flaw,
Confirm thy soul in self-control, thy liberty in law!
--one of the verses not usually taught in U.S. schools
- Re: [Chicken-users] hygienic egg PORT-A-MANIA!, (continued)
- Re: [Chicken-users] hygienic egg PORT-A-MANIA!, felix winkelmann, 2008/08/25
- Re: [Chicken-users] hygienic egg PORT-A-MANIA!, Ivan Raikov, 2008/08/25
- Re: [Chicken-users] hygienic egg PORT-A-MANIA!, Elf, 2008/08/25
- Re: [Chicken-users] hygienic egg PORT-A-MANIA!, felix winkelmann, 2008/08/26
- Re: [Chicken-users] hygienic egg PORT-A-MANIA!, Ivan Raikov, 2008/08/26
- Re: [Chicken-users] hygienic egg PORT-A-MANIA!, Elf, 2008/08/26
- Wiki HTML structure (Was: Re: [Chicken-users] hygienic egg PORT-A-MANIA!), Peter Bex, 2008/08/26
- Re: [Chicken-users] hygienic egg PORT-A-MANIA!, felix winkelmann, 2008/08/26
- Re: [Chicken-users] hygienic egg PORT-A-MANIA!, felix winkelmann, 2008/08/26
Re: [Chicken-users] hygienic egg PORT-A-MANIA!, Alan Post, 2008/08/25