<div dir="auto">I read somewhere to never write ^ in a block you intend to give out.  I use it to abandon methods in assertions and never any other time.<div dir="auto"><br></div><div dir="auto">One thing I do know from experimentation is it marks the method finished, so you can't call the block twice.  You'll get BlockCannotReturn nowadays.  It used to be a segmentation fault.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 28, 2022, 04:33 LawsonEnglish <<a href="mailto:LEnglish5@cox.net">LEnglish5@cox.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">OK, thanks.<br>
<br>
I had thought perhaps it would act more like a break and take one to the outside of the block, but instead it returns to the caller, as I should have realized.<br>
<br>
Stilly me.<br>
<br>
L<br>
<br>
<br>
> On Nov 28, 2022, at 04:15, Tobias Pape <<a href="mailto:Das.Linux@gmx.de" target="_blank" rel="noreferrer">Das.Linux@gmx.de</a>> wrote:<br>
> <br>
> Hi Lawson<br>
> <br>
> good to see you.<br>
> <br>
>> On 28. Nov 2022, at 11:58, LawsonEnglish <<a href="mailto:LEnglish5@cox.net" target="_blank" rel="noreferrer">LEnglish5@cox.net</a>> wrote:<br>
>> <br>
>> I was trying to test some ideas and was using the new FullBlockClosure to return values for further use in a workspace.<br>
>> <br>
>> This works with “print it”:<br>
>> <br>
>> [Transcript show: 2;cr. ^2] value => 2<br>
>> <br>
>> This does not work:<br>
>> <br>
>> test := [Transcript show: 2;cr. ^2] value <do it><br>
>> <br>
>> test => nil.<br>
> <br>
> Yes, and that is expected.<br>
> <br>
> Two things: <br>
> First, it seems you want to assign the _return value_ of a block to a variable.<br>
> To achieve this, do<br>
>       test := [Transcript show: 2;cr. 2] value "Note the missing caret/return"<br>
> <br>
> This is because the last statement of a block will be its return value.<br>
> <br>
> Second, yes, the return/caret in the block does something but apparently not the thing you expected.<br>
> The effect for caret/^/return is:<br>
> <br>
>       ^ statement "Returns the value from statement from the method"<br>
> <br>
> The last word is crucial. You return from the method, regardless of the block you are in.<br>
> <br>
> Like so:<br>
> <br>
> fooo<br>
> <br>
>  Transcript showln: 'foo 1'.<br>
>  self bar: <br>
>    [Transcript showln: 'block 1'.<br>
>    ^ 1].<br>
>  Transcript showln: 'foo 2'.<br>
>  ^ 2.<br>
> <br>
> <br>
> bar: aBlock<br>
> <br>
>  Transcript showln: 'bar 1'.<br>
>  aBlock value.<br>
>  Transcript showln: 'bar 2'.<br>
> <br>
> <br>
> If you send #foo, transcript will contain<br>
> <br>
> foo 1<br>
> bar 1<br>
> block 1<br>
> <br>
> an the return value will be 1.<br>
> <br>
> This is because the Return in the block will return form the _method #foo_  (where the block is defined) and not only from the block.<br>
> <br>
> What does that have to do with the Workspace???<br>
> <br>
> Workspaces create artificial methods for doIts and PrintIts.<br>
> <br>
> Hence, your actually sent method looks like that:<br>
> <br>
> DoIt<br>
>  test := [Transcript show: 2;cr. ^2] value<br>
> <br>
> If you run that method as print-it, "^2" returns form the DoIt method and the workspace can print the 2.<br>
> If you run that method as print-it, "^2" returns form the DoIt method but the assignment has never taken place, so test remains at its previous value, wich is nil.<br>
> <br>
> I hope this helps.<br>
> <br>
> Best regards<br>
>       -Tobias<br>
> <br>
>> <br>
>> nor does this:<br>
>> <br>
>> test :=( [Transcript show: 2;cr. ^2] value) <do it><br>
>> <br>
>> test => nil<br>
>> <br>
>> print it still works:<br>
>> <br>
>> test := ([Transcript show: 2;cr. ^2] value) => 2<br>
>> <br>
>> test => nil.<br>
>> <br>
>> In all cases, a 2 appears in the Transcript window, so I know that *something* is happening.<br>
>> <br>
>> I would have thought that if print-it and  do-it work, then the returned value would be put in the test variable, but that is not the case.<br>
>> <br>
>> I can use a  workspace global variable to access the output, but that kinda makes the ^ a one-trick-pony: useful for breaking out of loops, but not giving me access to the return value.<br>
>> <br>
>> <br>
>> [test := 2. Transcript show: test;cr. ^test] value => 2<br>
>> <br>
>> test => 2<br>
>> <br>
>> Is this an oversight or bug or feature for workspaces, or is it working as intended?<br>
>> <br>
>> <br>
>> Lawson<br>
>> <br>
>> <br>
>> <br>
> <br>
> <br>
> <br>
<br>
<br>
</blockquote></div>