> > It's different because evaluated only once, either at method compilation
> or at first execution (lazy initialization).


{ localVar1. instVar1. 'asd'->123 }

is great.. and would suffice for many use cases, it does evaluate at method execution. But bound execution at later point that BlockClosure gives is interesting.

>>
What you seek is something like
- Dolphin ##( ) construction
- or VW [] once trick from Travis Grigg based on using the #become: power
(search once upon a time or something like that on his blog)
I was thinking of this very subject recently and have a draft proposition
not really ready (must think of it twice).
>>

Other stuff I will eagerly wait for..
Well, I am not aware of Dolphin syntax as much, but in VA it is for evaluate once at method compilation.
VW I have not known any ecquivalent... so Travis's is news ...

To the current point: {...} is good.. and usable.. but this also gives a possibility to clean up:
BlockClosure>>asArray

��� |� stmts anArray� |

��� stmts := self decompile statements.
��� anArray := Array new: stmts size.
��� stmts doWithIndex: [ :eaNode :indx|
��� ��� anArray at: indx put: (Compiler evaluate: eaNode ).
��� ���� ].
��� ^anArray

or something more cleaner..� would allow late bound executions... and hold for all other use cases..

-Skrish

On Thu, Jul 22, 2010 at 5:39 PM, Sudhakar Krishnamachari <skrishnamachari@gmail.com> wrote:
Would this be of interest in general... I have always wanted a more capable literal array than what we have now..

#( 123 23 'das' )
whynot:
#( 'ac'->23� 2->'casd' myVar1)� ... evaluates to a collection..

so I just tried this out with a BlockClosure:

asArray

��� |� stmts anArray� |

��� stmts := self decompile statements.
��� anArray := Array new: stmts size.
��� stmts doWithIndex: [ :eaNode :indx| | start end value|
��� ��� start := (eaNode asString indexOf: ${)+1.
��� ��� end := (eaNode asString lastIndexOf: $})-1.
��� ��� value := Compiler evaluate: (eaNode asString copyFrom: start to: end) for: self receiver logged: false.
��� ��� anArray at: indx put: value].
��� ^anArray

So we could do:
['abc'->123. 'def'->456. 'efg'->789. 'hij'->123. 'klm'->456.] asArray.
[self checkThisUsingKeywordMethod: 'abc' with:'efg'. localVar1. instanceVar1 ] asArray


to yield arrays.. not neat, I would much rather prefer the literals do their job their way...
but works.. for the narrow set I have tried so far..

Any comments..
-Skrish