[gambit-list] Idiomatic Scheme

Roger Wilson misterrogerwilson at gmail.com
Thu Jan 19 18:39:32 EST 2012


Hi,

Thanks for all the input guys.  It all makes sense.

I have a question on the cond/case option though.  More one for
StackOverflow really but...

(define (make-f)
  (lambda (message . arguments)
    (case message
        (('get!) (display "get"))
        (('size) (display "size"))
        (else (display "no match")))))

(define f (make-f))
(f 'size)

> "no match"

(define (make-g)
  (lambda (message . arguments)
    (display message) (newline)
    (cond
        ((eq? message 'get!) (display "get"))
        ((eq? message 'size) (display "size"))
        (else (display "no match")))))

(define g (make-g))
(g 'size)

> "size"

How do I get the make-f variant using case to do what I want?  I guess this
is a eqv? vs eq? thing, or am I missing a quote somewhere?

Thanks,
Roger.



>
> ---------- Forwarded message ----------
> From: "Adrien Piérard" <pierarda at iro.umontreal.ca>
> To: Mikael <mikael.rcv at gmail.com>
> Cc: gambit-list at iro.umontreal.ca
> Date: Thu, 19 Jan 2012 21:50:29 +0900
> Subject: Re: [gambit-list] Idiomatic Scheme
> Hi again,
>
> I couldn't resist answering more :)
>
> >> In particular I'm unhappy with the way the message arguments are
> accessed as (car arguments) rather than by explicit name.  I can see that
> being a potential cause of bugs if the number of arguments grows and they
> vary with each message.
>
> You'll probably enjoy optional parameters, then, even though my code
> sample is not really portable extensible:
>
> (lambda (message #!optional arg1)
>  (case message
>    ((:put-name!)
>     (push (make-blob-name arg1) unused-name-list)
>     (randomise-list))
>    ...))
>
> By the way, why sort the list?
> Why not also let the constructor of your data type assign the random value?
> I barely use DEFINE-TYPE, but I guess there's a way to make the
> constructor call a function to generate the random value or something
> like that.
> Unfortunately, (random init: (random-integer 42)) doesn't work.
>
> > maybe switch the cond to a case?
>
> Indeed, that too.
>
> P!
> --
> Français, English, 日本語, 한국어
>
>
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20120119/acc9e406/attachment.htm>


More information about the Gambit-list mailing list