[plt-scheme] redefining set!

From: Hans Oesterholt-Dijkema (hdnews at gawab.com)
Date: Mon Jun 18 18:19:49 EDT 2007

Hmm, I'm not sure if I'm going to win a lot with this
excersize:

 > (define (f x) (if (> x 0) (begin (g x) (f (- x 1))) #t))
 > (define (g x) x)
 > (time (f 10000000))
cpu time: 1572 real time: 1572 gc time: 0
#t
 > (define v (vector g))
 > (define (h x) (if (> x 0) (begin ((vector-ref v 0) x) (h (- x 1))) #t))
 > (time (h 10000000))
cpu time: 2023 real time: 2033 gc time: 0   (123%)
#t
 > (time (h 10000000))
cpu time: 1903 real time: 1913 gc time: 0  (117%)
#t
 > (define k (make-hash-table))
 > (hash-table-put! k 'g g)
 > (define (l x) (if (> x 0) (begin ((hash-table-get k 'g) x) (l (- x 
1))) #t))
 > (time (l 10000000))
cpu time: 2113 real time: 2123 gc time: 0  (130%)

 > (define-syntax q
(syntax-rules ()
((_ g a1 ...) (g a1 ...))))
 > (define (z x) (if (> x 0) (begin (q g x) (z (- x 1))) #t))
 > (time (z 10000000))
cpu time: 1663 real time: 1663 gc time: 0  (100%)
#t
 > (time (f 10000000))
cpu time: 1632 real time: 1632 gc time: 0
#t

--Hans


Jens Axel Søgaard schreef:
> Hans Oesterholt-Dijkema skrev:
>> Hmm,
>>
>> If instead of defining a procedure, I'd define a
>> macro, I would be able to do
>
>> (define x (cl 5))
>>
>> instead of  (define-instance x (cl 5))
>
> The macro define-instance receives both x and cl,
> and can thus record that x is an instance of
> the class cl.
>
> In
>
>   (define x (cl 5)
>
> the macro call (cl 5) doesn't receive the x,
> and thus can't record that x is a cl class.
>
>> However. How can I create a result that will
>> be able to be called like a macro. I cannot return
>> a macro as a value can I?
>
> No, not at runtime.
>
>> So I can associate cl with m alright. 
>
> Yes.
>
>> But that would require defining something like:
>>
>> cl->
>>
>> wouldn't it?
>>
>> And then, "transforming" (-> x m 8) to something like
>> (cl-> x m 8). However, how can I turn -> into cl->?
>
> In def-class you need to record that cl is associated
> with cl-> . There is a record example in
>
>   Composable and Compilable Macros
>   Flatt
>   http://www.cs.utah.edu/plt/publications/macromod.pdf
>
> that might be used for inspiration.
>
>



Posted on the users mailing list.