logo       

RE: How to know where a BlockClosure finish: msg#00239

Subject: RE: How to know where a BlockClosure finish
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@xxxxxxxxxxxxxxxxxxxxxxxxxx [mailto:beginners-
> bounces@xxxxxxxxxxxxxxxxxxxxxxxxxx] 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@xxxxxxxxxxxx
> >
> >> 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@xxxxxxxxxxxxxxxxxxxxxxxxxx
> http://lists.squeakfoundation.org/mailman/listinfo/beginners


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
linux.arklinux....    user-groups.lin...    kde.usability/2...    ietf.ipp/2002-0...    mail.spam.spamc...    os.netbsd.devel...    audio.cd-record...    text.unicode.de...    php.documentati...    games.fps.halfl...    window-managers...    suse.oracle.gen...    bug-tracking.gn...    video.dvdrip.us...    xfree86.cvs/200...    java.netbeans.m...    network.argus/2...    culture.sf.kill...    debian.ports.al...    freebsd.questio...    qplus.devel/200...    handhelds.palm....   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe