[Prev][Next][Index][Thread]
Re: Dylan Features
In article <rFfj5.6913$FZ1.98384@news20.bellglobal.com>,
maury_markowitz@hotmail.com says...
> "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.
No, it's the formal parameter of the anonymous method which is itself the
second actual parameter of "fact". A good way to think of continuations,
and the one that inspired the name, is that they represent what happens
in a program after the current statement. They are very important in
denotational semantics, where they are used to describe the meaning of
control flow constructs in a particular context. The nice thing about
using continuations to represent "the rest of the program" explicitly
is that you can ignore them: for instance, the meaning of "GOTO L" in
the context of a continuation K does *not* use K at all, because control
flow goes away from this part of the program altogether. In fact, the
label L is represented by a continuation, which describes the meaning
of the rest of the program after the label.
Does that make sense?
Peter.
--
peter@harle Harlequin Ltd, Barrington Hall,
quin.co.uk Barrington, Cambs CB2 5RG, England.
References: