Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: How to know where a BlockClosure finish: msg#00238

lang.smalltalk.squeak.beginners

Subject: Re: 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
>>


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

Recently Viewed:
qnx.openqnx.dev...    gcc.libstdc++.c...    solaris.opensol...    information-ret...    misc.misterhous...    web.catalyst.ge...    apache.webservi...    redhat.release....    hardware.lirc/2...    kernel.autofs/2...    technology.sust...    linux.vdr/2003-...    editors.lyx.gen...    org.user-groups...    netbsd.devel.pk...    xdg.devel/2004-...    version-control...    jakarta.slide.d...    debian.packages...    creativecommons...    ports.ppc.embed...    bug-tracking.bu...   
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