Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!gatech!bloom-beacon.mit.edu!news.kei.com!nntp.et.byu.edu!news.mtholyoke.edu!world!jhaungs
From: jhaungs@world.std.com (Jim Haungs)
Subject: Re: ^[^self]
Message-ID: <D8vp5n.6ww@world.std.com>
Organization: The World Public Access UNIX, Brookline, MA
References: <3pira6$446@PEAK.ORG>
Date: Sat, 20 May 1995 13:22:35 GMT
Lines: 36

kolstadj@PEAK.ORG (Joel Kolstad) writes:

>Ok, someone posted the question "What does ^[^self] do?" the other day, and
>I'm just curious enough to want an answer.

>My answer: It returns a black (context) object, specifically #[^self].
>However, if you were to evaluate that block (send it a value message), 
>you'll generate an error, since Smalltalk will attempt to return from
>the method that returned the block... that's already been returned from,
>hence generating a "you can only return once" error.

>Is this correct?

>I'm not sure I'd use the veracity of someone's answer to this as a basis for
>employment. :-)

>					---Joel Kolstad


I just tried this in VisualWorks 2.0, and, as expected, the expression
itself returns a BlockContext, which, when sent the #value message,
gives a walkback saying "Context cannot return."

Since literal method contexts are bound to the method in which they
are compiled, the self refers to stack frames that disappear when the
method returns, so of course you can't return from something you
just returned from.  The explanation for this is that self and super
are compiled (hard-coded) when the method is compiled.  I've never
seen this come up in practice; it's sort of like wishing for a good
answer to division by zero.

Patient: "Doctor, it hurts when I do this."
Doctor: "Well, don't do that."

Jim

