|
Re: How to know where a BlockClosure finish: msg#00238lang.smalltalk.squeak.beginners
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 >>
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: How to know where a BlockClosure finish, Ron Teitelbaum |
|---|---|
| Next by Date: | RE: How to know where a BlockClosure finish, Ron Teitelbaum |
| Previous by Thread: | RE: How to know where a BlockClosure finish, Ron Teitelbaum |
| Next by Thread: | RE: How to know where a BlockClosure finish, Ron Teitelbaum |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |