[Prev][Next][Index][Thread]

Re: Dylan Features



In article <rFfj5.6913$FZ1.98384@news20.bellglobal.com>,
Maury Markowitz <maury_markowitz@hotmail.com> wrote:
>"Bruce Hoult" <bruce@hoult.org> wrote in message
>bruce-D2F886.11172406082000@news.akl.ihug.co.nz">news:bruce-D2F886.11172406082000@news.akl.ihug.co.nz...
>> You can convert this (manally or automatically) into
>> "continuation-passing style":
>>
>>   define method fact(n, return)
>>      if (n = 0)
>>        return(1)
>>      else
>>         fact(n - 1, method (val) return(n * val) end)
>>      end
>>   end;
>>
>> Now, instead of calling this as...
>>
>>   format-out("factorial 5 is %=\n", fact(5));
>>
>>  ... you'd call it as ...
>>
>>   fact(5, method (val) format-out("factorial 5 is %=\n", val) end);
>
>  I think I understand the idea, but I'm still unclear on some of the
>details.  For instance, is "val" a keyword?  I'm also unclear why you'd want
>to do this, the second example makes my eyes cross.

"val" is the parameter to the unnamed method.  If you're familiar with
Lisp, "method" is analogous to "lambda".

-- 
Barry Margolin, barmar@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



References: