[gambit-list] destructuring bind define-type

lowly coder lowlycoder at huoyanjinjing.com
Tue Jun 2 23:22:10 EDT 2009


Thanks Marc,

I was pondering on this earlier today, and it struck me a really simple
solution is this:

types.scm <-- not really scheme, but defines the types I want to use

destructure.scm <-- reads data in from types.scm

prog.scm <-- reads data in from types.scm, and executes the right
define-types

:-)


On an unrelated note, what is this "heartbeat-interval", and how can I read
it? (I can only set it via ##thread-heartbeat-interval-set!) ... it seems
very key in the functionality of statprof.scm (it appears that statprof.scm
depends on an interrupt being fired so often, then looking at the current
state of the interpreter, and thus buiding a statistical view of the
program).

Knowing the value of heartbeat-interval is _very_ important to me. In
particular, I have a graphics server running at 100hertz. Suppose
heartbeat-interval is also 100hz, I can easily get highly distorted values
from statprof.scm

Thanks!

On Tue, Jun 2, 2009 at 7:56 AM, Marc Feeley <feeley at iro.umontreal.ca> wrote:

>
> On 2-Jun-09, at 12:24 AM, lowly coder wrote:
>
>  are there any amcros that play well with destructuring bind of
>> define-type's ? I just want to check to see if there's a pre-existing
>> solution before re-inventing my own.
>>
>> I find myself writing way too much code of the form:
>>
>> (define-type foo a b)
>> (define-type bar c d)
>>
>> (lambda (x)
>>  (let ((c (bar-c x) (d (bar-d x)))
>>    (let ((a (foo-a a) (b (foo-b b)) ...
>>
>
> Try this (but beware that the API for the ## procedures may change in the
> future):
>
> (define-macro (def-type . args)
>  (##define-type-parser
>   'def-type
>   #f
>   args
>   (lambda (name
>            flags
>            id
>            extender
>            constructor
>            constant-constructor
>            predicate
>            implementer
>            type-exhibitor
>            prefix
>            fields
>            total-fields)
>     (let ((field-names (map car fields)))
>       `(begin
>          (define-type , at args)
>          (define (,(##symbol-append 'with- name) obj proc)
>            (proc ,@(map (lambda (f)
>                           `(,(##symbol-append name '- f) obj))
>                         field-names))))))))
>
> (def-type point x y)
>
> (define p (make-point 11 22))
>
> (with-point p (lambda (x y) (pp (list 'x+y= (+ x y)))))
>
>
> Marc
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://webmail.iro.umontreal.ca/pipermail/gambit-list/attachments/20090602/2af5d546/attachment.html 


More information about the Gambit-list mailing list