For Programmers: Free Programming Magazines  


Home > Archive > Scheme > November 2005 > Re: HOF implementation of "until"









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: HOF implementation of "until"
Marcin 'Qrczak' Kowalczyk

2005-11-03, 7:01 pm

Ulrich Hobelmann <u.hobelmann@web.de> writes:

>
> Well, when you have a for-each function that works for all sequences,
> so could the dolist macro...


The point is, what would the macro expand to? It must either pack the
loop body in a closure and pass it to a different function depending
on the sequence type, or pack the iterator in an object and perform an
indirect call for obtaining each element, or jump between the iteration
and the loop body through continuations.

In each case the cost is similar, and there is no gain from iteration
being a macro except that some people might find the macro syntax nicer.

>
> It's mostly shorter because it avoids the verbose lambda.


Indeed, but I gave even explicit lambdas a concise syntax:
?parameters {body} in the general case.

For continuation passing style you can write ?parameters => body
without the closing brace, and with empty parameters the question
mark is not necessary.

If the body consists of a single function call with some arguments
passed from the lambda's parameters (in the same order), you can
write the application with passed parameters replaced by _, e.g.
Write _ "\n" being equivalent to ?s {Write s "\n"}. This is similar
to currying in languages which do curry (the provided arguments are
evaluated when the function is created).

A lightweight syntax for lambdas means that more control structures
can be implemented with regular functions instead of with macros.

--
__("< Marcin Kowalczyk
\__/ qrczak@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com