Home > Archive > Scheme > October 2004 > redefining define
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Hans Oesterholt-Dijkema 2004-10-29, 3:58 pm |
| L.S.,
In order to make a generic function implementation
with macros, I'd like to redefine 'define' (in order
to get transparency).
Does anyone know how to remember the orginal 'define' form
and call it from within the new 'define' macro?
Thanks in advance,
Hans Oesterholt-Dijkema
| |
| Hans Oesterholt-Dijkema 2004-10-29, 3:58 pm |
| In gauche it can be done example:
gosh> (define %define #f)
%define
gosh> (set! %define define)
#<syntax define>
(define-syntax define
(syntax-rules ()
((define (f a ...) b)
(begin
(%define (f a ...) b)
(set! L (cons (list 'f f) L))))
((define a b) (%define a b))))
#<macro define>
gosh> (define a 10)
a
gosh> a
10
gosh> (define L (list))
L
gosh> (define (f a b) (* a b))
((f #<closure 0x10047930(a b)> ))
gosh> f
#<closure 0x10047930(a b)>
gosh> (f 4 3)
12
gosh> L
((f #<closure 0x10047930(a b)> ))
gosh> (assoc 'f L)
(f #<closure 0x10047930(a b)> )
gosh> ((cadr (assoc 'f L)) 4 5)
20
gosh> (exit)
Any suggestions for other schemes?!
Thanks in advance,
Hans Oesterholt-Dijkema
| |
| Anton van Straaten 2004-10-29, 3:58 pm |
| > Any suggestions for other schemes?!
If implementation-specific techniques are OK, there's a clean way to do it
using modules in PLT Scheme:
(module foo mzscheme
(define-syntax my-define
(syntax-rules ()
((_ name val)
(define name (cons 'bar val))))) ; arbitrary definition for DEFINE
(provide (rename my-define define)))
Any code which loads module FOO will have DEFINE redefined.
Anton
| |
| Hans Oesterholt-Dijkema 2004-10-30, 8:56 am |
| On Fri, 29 Oct 2004 18:14:43 +0000, Anton van Straaten wrote:
>
> If implementation-specific techniques are OK, there's a clean way to do it
> using modules in PLT Scheme:
>
Thanks!
Btw. Would you know of a portable solution?
---
hans
|
|
|
|
|