**** Posted from RemarQ - http://www.remarq.com - Discussions Start Here (tm) ****
lambda expressions, which are more powerful than blocks, of course, but
also slightly more verbose unless you invent your own syntax, which is
also trivial to do.
#:Erik
--
@1999-07-22T00:37:33Z -- pi billion seconds since the turn of the century
A block is pretty much like a lambda expressions in Lisp, and FUNCALL
is the equivalent of sending the value message:
(setf f #'(lambda ()
(+ 1 2)))
(funcall f) -> 3
But you can also do rather more than this:
(setf f #'(lambda (y)
(+ 2 y)))
(funcall f 3) -> 5
(setf f (let ((v 0))
#'(lambda (&optional (inc 1))
(setf v (+ v inc)))))
(funcall f) -> 1
(funcall f) -> 2
(funcall f 11) -> 13
--tim
| lambda expressions, which are more powerful than blocks, of course, but
| also slightly more verbose unless you invent your own syntax, which is
| also trivial to do.
How are lambda expressions more powerful than Smalltalk blocks? I'm much
more familiar with Scheme, but lambdas in Scheme appear to be equivalent
to blocks in Smalltalks that implement full closure semantics.
--
-- Tim Olson
faa
Tim Olson <t...@jumpnet.com> wrote in message
news:tim-300599...@jump-tnt-0006.customer.jump.net...
| Except that the Smalltalk standard (IIRC) does not require that variables in
| methods and blocks be lexically closed.
The draft version I have (1.9) does seem to require that blocks be
implemented as closures:
-----
Section 3.4.4 Blocks
Expressions within a block may reference temporary variables and arguments
of the functions that enclose the block. Each block object is an
independent closure that captures the current bindings for any enclosing
functions' arguments or temporaries that are referenced from within the
block's <block constructor>. Any such captured bindings and their
associated discrete variables or objects must be preserved as long as the
block object continues to exist and is available for evaluation. Note that
the values of any such captured discrete variables and the state of any
object captured by an argument binding remain subject to possible
modification.
-----
You are correct that Squeak does not currently implement blocks like this,
but as far as I know all other Smalltalks do (and most folks are pushing
to have Squeak do so, as well).
--
-- Tim Olson
faa
Tim Olson <t...@jumpnet.com> wrote in message
news:tim-300599...@jump-tnt-0130.customer.jump.net...
Lambda expressions certainly resemble blocks *quite*
closely. Why do you insist on the feature that
"most closely" resembles blocks. Homework?
among symbols, complex numbers, hash tables, closures, streams, classes,
conditions, and a better syntax, just to take a few Lisp features, it
_still_ looks like closures most closely resemble Smalltalk blocks.
your question looks facetious. why are you asking such a funny question
and being so serious about it? what are you _really_ wondering about?