[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: special forms, take two (was Re: A lua version of "amb")
- From: Jay Carlson <nop@...>
- Date: Thu, 1 Mar 2012 11:36:37 +0000
On Thu, Mar 1, 2012 at 1:53 AM, Mark Hamburg <email@example.com> wrote:
> On Feb 29, 2012, at 9:31 AM, Jay Carlson wrote:
>> On Tue, Feb 28, 2012 at 1:32 PM, Fabien <firstname.lastname@example.org> wrote:
>>> On Tue, Feb 28, 2012 at 2:41 AM, Jay Carlson <email@example.com> wrote:
>>>> I don't think anybody's been talking about a functional programming style.
>>> Fair enough. However, I believe that if you introduce terse and tempting
>>> lambdas in the language, then you're going to entice people into writing bad
>>> functional-ish code.
>> Smalltalk-80 blocks resembled closures but were not first class
>> values; they were stack-allocated. (I remember bumping my shins on
>> this before implementations fixed it.) Ruby syntax wants you to use
>> blocks a particular way. So I guess both of those languages threw
>> stumbling blocks in front of a functional style.
> If you really want to do control flow, you need blocks rather than closures with the key difference being how return statements work. A block still exists in the control context of its enclosing scope. A closure is its own control context.
>From Scheme's point of view, part of the environment for blocks is the
current continuation of the enclosing method; that is, the method has
a hidden "^" variable in its scope containing a function which will
fall off the end of the method when called. Blocks may capture this
lexically. This "^" upvalue function is guaranteed to be called from a
tail position, so it's a goto, and because it's hidden it can't be
captured. It does leave one with the lingering question, "Say, what
*would* happen if I stored [^3+4] somewhere? Would *this current*
function return again?"
This is a particularly mean and nasty question to ask of such a noble
language, so implementations generally avoided the question.