[Newbies] How to know where a BlockClosure finish

Ron Teitelbaum Ron at USMedRec.com
Sat Aug 26 01:07:49 UTC 2006


Ok how about:

aBlock := [completed := true.
Some code
Some condition ifTrue: [completed := false. ^completed->someValue].
completed->someValue].

Now 

result := aBlock value.
blockCompleted := result key.
blockResult := result value.

Ron


> -----Original Message-----
> From: beginners-bounces at lists.squeakfoundation.org [mailto:beginners-
> bounces at lists.squeakfoundation.org] On Behalf Of Mathieu
> Sent: Friday, August 25, 2006 8:06 PM
> To: A friendly place to get answers to even the most basic questions
> aboutSqueak.
> Subject: Re: [Newbies] How to know where a BlockClosure finish
> 
> Ron Teitelbaum a écrit :
> > Hi Math,
> >
> > How about just adding a parameter?
> >
> > Blocks are really cool in that they can import context if needed.  This
> is a
> > really amazing feature of blocks for me since the imported context is
> the
> > context when the block was created!
> >
> > So to solve your problem you could just do the following.
> >
> > continue := true.
> >
> > block1 := [someCode.
> > 		someCondition ifTrue: [continue := false. ^someValue]].
> > block2 := [someCode].
> >
> > Then:
> >
> > block1 value.
> > continue ifTrue: [
> >     block2 value
> > ].
> >
> > Hope that helps!
> >
> > Happy coding.
> 
> Thanks Ron but in fact it's in a context that we don't know where are
> the return and we also don't know how many "block" we have. :)
> 
> 
> >
> > Ron Teitelbaum
> > President / Principal Software Engineer
> > US Medical Record Specialists
> > Ron at USMedRec.com
> >
> >> From: Mathieu
> >> Sent: Friday, August 25, 2006 1:10 PM
> >>
> >> Marcus Denker a écrit :
> >>> On 25.08.2006, at 17:14, Mathieu wrote:
> >>>
> >>>> Hi,
> >>>>
> >>>> I want to execute several block:
> >>>>
> >>>> block1 value
> >>>> block2 value
> >>>> block3 value
> >>>>
> >>>> but if one block return from a retrun statement I want to quit.
> >>>>
> >>>> [^3] <- want to quit here
> >>>> [3 + 4]
> >>>>
> >>>> So is there a way to know when a block evaluation finish by a return?
> >>>>
> >>> There is #hasMethodReturn in BlockContext:
> >>>
> >>> [^3] hasMethodReturn --> true
> >>> [3] hasMethodReturn --> false.
> >>>
> >>> But this does a static analysis of the code... even if the ^is not
> >> executed
> >>> (e.g.)
> >>> [nil ifNotNil: [^3]]  hasMethodReturn --> true
> >>>
> >>> so... it would be harder to analyze that dynamically... e.g. (without
> >>> me  thinking
> >>> to much) you could add code (e.g. using ByteSurgeon)
> >>> in front of the return inside a block to set a flag... but I have to
> >>> admit that this
> >>> woud be quite strange stuff...
> >>>
> >>>> I need this to interprete a file containing smalltalk and I want to
> >>>> control the execution beceause I need to add some condition befor
> >>>> evaluate a block.
> >>> Why do you need that? I am sure we can find a simple solution if we
> >>> understand
> >>> the problem better.
> >>>
> >>>    Marcus
> >>>
> >>>
> >> Yes you are right
> >>
> >> In the script I have 2 kind of things:
> >> [
> >> some Smalltalk
> >> ]
> >>
> >> And:
> >>
> >> Class selector
> >> [
> >> some smalltalk
> >> ]
> >>
> >> So my idea was to call
> Compiler>>#evaluate:in:to:notifying:ifFail:logged:
> >> on the string inside the [] for the first things.
> >>
> >> And for the second I don't know yet but I don't think it's a probleme.
> >>
> >> So I evaluate the "block" one by one. I don't think I can put them all
> >> together beceause we can declare new method and use it in the next
> >> "block".
> >>
> >> But may be I shouln't evaluate right now juste store them in a
> >> CompiledMethod...
> >>
> >> Math
> >>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners




More information about the Beginners mailing list