Ensure: -- extension ...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Ensure: -- extension ...

Dennis smith-4
Has anyone but me ever wanted a parameter to the ensure block?

    [
       ...
       ... ^23
       ...
    ] ensure: [:r | ... r is 23 ...]

I need this so I know if the return value is in fact true or false so I
know whether to do
a gemstone commit or abort (this code runs on the client side).

I have in fact coded this, but it requires mods in multiple classes and
if the mods are loaded in
the wrong order VW freezes -- as I found out trying to build a new image
from visual.im and store.

Just wondered if anyone has needed this and if so how they went about it??

(its trivial on gemstone because the stack is intact at the time the
ensure block is invoked so the
   returned value is sitting there).

--
Dennis Smith                        [hidden email]
Cherniak Software Development Corporation       +1 905.771.7011
400-10 Commerce Valley Dr E                Fax: +1 905.771.6288
Thornhill, ON Canada L3T 7N7    http://www.CherniakSoftware.com

Reply | Threaded
Open this post in threaded view
|

Re: Ensure: -- extension ...

Chris Winemiller
Dennis,

Wouldn't the following do just as well?

    | result |
    [   result := nil.
       ...
       ^result := 23
       ...
    ] ensure: [ ... result = 23 ifTrue: [...]...]

Chris

Dennis Smith wrote:

> Has anyone but me ever wanted a parameter to the ensure block?
>
>    [
>       ...
>       ... ^23
>       ...
>    ] ensure: [:r | ... r is 23 ...]
>
> I need this so I know if the return value is in fact true or false so
> I know whether to do
> a gemstone commit or abort (this code runs on the client side).
>
> I have in fact coded this, but it requires mods in multiple classes
> and if the mods are loaded in
> the wrong order VW freezes -- as I found out trying to build a new
> image from visual.im and store.
>
> Just wondered if anyone has needed this and if so how they went about
> it??
>
> (its trivial on gemstone because the stack is intact at the time the
> ensure block is invoked so the
>   returned value is sitting there).
>

Reply | Threaded
Open this post in threaded view
|

Re: Ensure: -- extension ...

Michael Lucas-Smith
In reply to this post by Dennis smith-4
What is 'r' in the ensure block if the value block curtails?

> Has anyone but me ever wanted a parameter to the ensure block?

>     [
>        ...
>        ... ^23
>        ...
>     ] ensure: [:r | ... r is 23 ...]

Reply | Threaded
Open this post in threaded view
|

Re: Ensure: -- extension ...

Dennis smith-4


Michael Lucas-Smith wrote:
What is 'r' in the ensure block if the value block curtails?
  
Its the value being returned to the invoking method (in this case of the block contains the statement
    ^23
it will be 23.

My case is simple, I am using gemstone.  I have a construct which wraps the enclosed actions in a
gemstone transaction (commit) -- the content of the block can return at any point, or it can just
end the block with a result.  In EITHER case, the resulting value (or return value) can be
   - true  - indicating success of the block
   - false - indicating failure
   - an errorMsg (its an object) indicating failure with a message
If it fails, the wrapping code must abort the transaction, if it succeeds it must commit.
To be flexible for the application developers, I don't want to say you cannot return from the block,
so I need the returned value in the ensure block.

On Gemstone this is simple -- I can look on the stack, but in VW the stack has been unwound so I have
to modify code to retain and pass around the result value.

  
Has anyone but me ever wanted a parameter to the ensure block?
    

  
    [
       ...
       ... ^23
       ...
    ] ensure: [:r | ... r is 23 ...]
    

  

-- 
Dennis Smith                        [hidden email]
Cherniak Software Development Corporation       +1 905.771.7011
400-10 Commerce Valley Dr E                Fax: +1 905.771.6288
Thornhill, ON Canada L3T 7N7    http://www.CherniakSoftware.com
Reply | Threaded
Open this post in threaded view
|

Re[2]: Ensure: -- extension ...

Michael Lucas-Smith

Yes but ensure: also does ifCurtailed: so if you have the following code:


[ .. for some reason we terminate or break, eg:

Processor activeProcess terminate

.. or

Error raise]

       ensure: [:mysteryArgument | .... ]


What is the mysteryArgument when this happens? The block you're running has not completed and has not returned.


Cheers,

Michael


>



Michael Lucas-Smith wrote: 

What is 'r' in the ensure block if the value block curtails?  

Its the value being returned to the invoking method (in this case of the block contains the statement

    ^23

it will be 23.


My case is simple, I am using gemstone.  I have a construct which wraps the enclosed actions in a

gemstone transaction (commit) -- the content of the block can return at any point, or it can just

end the block with a result.  In EITHER case, the resulting value (or return value) can be

   - true  - indicating success of the block

   - false - indicating failure

   - an errorMsg (its an object) indicating failure with a message

If it fails, the wrapping code must abort the transaction, if it succeeds it must commit.

To be flexible for the application developers, I don't want to say you cannot return from the block,

so I need the returned value in the ensure block.


On Gemstone this is simple -- I can look on the stack, but in VW the stack has been unwound so I have

to modify code to retain and pass around the result value.



  

Has anyone but me ever wanted a parameter to the ensure block?   

  

    [       ...       ... ^23       ...    ] ensure: [:r | ... r is 23 ...]

  



-- Dennis Smith                       [hidden email] Cherniak Software Development Corporation       +1 905.771.7011 400-10 Commerce Valley Dr E                Fax: +1 905.771.6288 Thornhill, ON Canada L3T 7N7 http://www.CherniakSoftware.com

Reply | Threaded
Open this post in threaded view
|

Re: Ensure: -- extension ...

Dennis smith-4


Michael Lucas-Smith wrote:

Yes but ensure: also does ifCurtailed: so if you have the following code:


[ .. for some reason we terminate or break, eg:

Processor activeProcess terminate

.. or

Error raise]

       ensure: [:mysteryArgument | .... ]


What is the mysteryArgument when this happens? The block you're running has not completed and has not returned.

OK -- depends on what the innerResult is in 'nonLocalReturn: innerResult through: firstUnwindContext
    as invoked in BlockClosure -- by black-box experiment, its some BlockClosure -- looks like an on:do:
    case.
    Thanks for pointing that out -- I suspect its the culprit in a few strange gemstone commits
    which seem to occur in cases where they should not -- I will do something about it.


Cheers,

Michael


>



Michael Lucas-Smith wrote: 

What is 'r' in the ensure block if the value block curtails?  

Its the value being returned to the invoking method (in this case of the block contains the statement

    ^23

it will be 23.


My case is simple, I am using gemstone.  I have a construct which wraps the enclosed actions in a

gemstone transaction (commit) -- the content of the block can return at any point, or it can just

end the block with a result.  In EITHER case, the resulting value (or return value) can be

   - true  - indicating success of the block

   - false - indicating failure

   - an errorMsg (its an object) indicating failure with a message

If it fails, the wrapping code must abort the transaction, if it succeeds it must commit.

To be flexible for the application developers, I don't want to say you cannot return from the block,

so I need the returned value in the ensure block.


On Gemstone this is simple -- I can look on the stack, but in VW the stack has been unwound so I have

to modify code to retain and pass around the result value.



  

Has anyone but me ever wanted a parameter to the ensure block?   

  

    [       ...       ... ^23       ...    ] ensure: [:r | ... r is 23 ...]

  



-- Dennis Smith                       [hidden email] Cherniak Software Development Corporation       +1 905.771.7011 400-10 Commerce Valley Dr E                Fax: +1 905.771.6288 Thornhill, ON Canada L3T 7N7 http://www.CherniakSoftware.com


-- 
Dennis Smith                        [hidden email]
Cherniak Software Development Corporation       +1 905.771.7011
400-10 Commerce Valley Dr E                Fax: +1 905.771.6288
Thornhill, ON Canada L3T 7N7    http://www.CherniakSoftware.com
Reply | Threaded
Open this post in threaded view
|

RE: Ensure: -- extension ...

Terry Raymond

Dennis

 

You could use nil as the return value if the block is curtailed but it

would be more appropriate to use a separate block or an additional

argument to indicate it was curtailed.

 

Terry

===========================================================
Terry Raymond       Smalltalk Professional Debug Package
Crafted Smalltalk
80 Lazywood Ln.
Tiverton, RI  02878
(401) 624-4517      [hidden email]
<http://www.craftedsmalltalk.com>
===========================================================


From: Dennis Smith [mailto:[hidden email]]
Sent: Tuesday, July 11, 2006 7:22 AM
To: Michael Lucas-Smith
Cc: VWNC,
Subject: Re: Ensure: -- extension ...

 



Michael Lucas-Smith wrote:

Yes but ensure: also does ifCurtailed: so if you have the following code:

 

[ .. for some reason we terminate or break, eg:

Processor activeProcess terminate

.. or

Error raise]

       ensure: [:mysteryArgument | .... ]

 

What is the mysteryArgument when this happens? The block you're running has not completed and has not returned.

OK -- depends on what the innerResult is in 'nonLocalReturn: innerResult through: firstUnwindContext
    as invoked in BlockClosure -- by black-box experiment, its some BlockClosure -- looks like an on:do:
    case.
    Thanks for pointing that out -- I suspect its the culprit in a few strange gemstone commits
    which seem to occur in cases where they should not -- I will do something about it.


 

Cheers,

Michael

 

> 

 

 

Michael Lucas-Smith wrote: 

What is 'r' in the ensure block if the value block curtails?  

Its the value being returned to the invoking method (in this case of the block contains the statement

    ^23

it will be 23.

 

My case is simple, I am using gemstone.  I have a construct which wraps the enclosed actions in a

gemstone transaction (commit) -- the content of the block can return at any point, or it can just

end the block with a result.  In EITHER case, the resulting value (or return value) can be

   - true  - indicating success of the block

   - false - indicating failure

   - an errorMsg (its an object) indicating failure with a message

If it fails, the wrapping code must abort the transaction, if it succeeds it must commit.

To be flexible for the application developers, I don't want to say you cannot return from the block,

so I need the returned value in the ensure block.

 

On Gemstone this is simple -- I can look on the stack, but in VW the stack has been unwound so I have

to modify code to retain and pass around the result value.

 

 

  

Has anyone but me ever wanted a parameter to the ensure block?   

  

    [       ...       ... ^23       ...    ] ensure: [:r | ... r is 23 ...]

  

 

 

-- Dennis Smith                       [hidden email] Cherniak Software Development Corporation       +1 905.771.7011 400-10 Commerce Valley Dr E                Fax: +1 905.771.6288 Thornhill, ON Canada L3T 7N7 http://www.CherniakSoftware.com



-- 
Dennis Smith                        [hidden email]
Cherniak Software Development Corporation       +1 905.771.7011
400-10 Commerce Valley Dr E                Fax: +1 905.771.6288
Thornhill, ON Canada L3T 7N7    http://www.CherniakSoftware.com