<div class="gmail_quote"><div>Hi,</div><div><br></div><div>Thanks for all the input guys.  It all makes sense.</div><div><br></div><div>I have a question on the cond/case option though.  More one for StackOverflow really but...</div>
<div><br></div><div><div>(define (make-f)</div><div>  (lambda (message . arguments)</div><div>    (case message</div><div>        (('get!) (display "get"))</div><div>        (('size) (display "size"))</div>
<div>        (else (display "no match")))))</div><div><br></div><div>(define f (make-f))</div><div>(f 'size)</div><div><br></div><div>> "no match"</div><div><br></div><div>(define (make-g)</div>
<div>  (lambda (message . arguments)</div><div>    (display message) (newline)</div><div>    (cond </div><div>        ((eq? message 'get!) (display "get"))</div><div>        ((eq? message 'size) (display "size"))</div>
<div>        (else (display "no match")))))</div><div><br></div><div>(define g (make-g))</div><div>(g 'size)</div><div><br></div><div>> "size"</div></div><div><br></div><div>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?</div>
<div><br></div><div>Thanks,</div><div>Roger.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>---------- Forwarded message ----------<br>
From: "Adrien Piérard" <<a href="mailto:pierarda@iro.umontreal.ca">pierarda@iro.umontreal.ca</a>><br>To: Mikael <<a href="mailto:mikael.rcv@gmail.com">mikael.rcv@gmail.com</a>><br>Cc: <a href="mailto:gambit-list@iro.umontreal.ca">gambit-list@iro.umontreal.ca</a><br>
Date: Thu, 19 Jan 2012 21:50:29 +0900<br>Subject: Re: [gambit-list] Idiomatic Scheme<br>Hi again,<br>
<br>
I couldn't resist answering more :)<br>
<br>
>> 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.<br>

<br>
You'll probably enjoy optional parameters, then, even though my code<br>
sample is not really portable extensible:<br>
<br>
(lambda (message #!optional arg1)<br>
  (case message<br>
    ((:put-name!)<br>
     (push (make-blob-name arg1) unused-name-list)<br>
     (randomise-list))<br>
    ...))<br>
<br>
By the way, why sort the list?<br>
Why not also let the constructor of your data type assign the random value?<br>
I barely use DEFINE-TYPE, but I guess there's a way to make the<br>
constructor call a function to generate the random value or something<br>
like that.<br>
Unfortunately, (random init: (random-integer 42)) doesn't work.<br>
<br>
> maybe switch the cond to a case?<br>
<br>
Indeed, that too.<br>
<br>
P!<br>
--<br>
Français, English, 日本語, 한국어<br>
<br>
<br>_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
<br></blockquote></div><br>