Evaluate before adding to array

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

Evaluate before adding to array

Fernando Rodríguez
Hi,

Sorry for the weird title, but I don't very well how to explain this
without an example.

Assume I have 2 TextPresenters: firstnamePresenter and
surnamePresenter. I want to create an array the models of those
presenters, so I tried this:

a := #((firstnamePresenter model) (surnamePresenter model)).

It didn't work. How can I tell St to evaluate the expressions (such as
firstnamePresenter model) and insert the _result_ into the array?
Otherwise I get an array of symbols and that's not what I want.

BTW, am I doing something weird or what?


Reply | Threaded
Open this post in threaded view
|

Re: Evaluate before adding to array

Esteban A. Maringolo-2
Fernando escribió:

> Assume I have 2 TextPresenters: firstnamePresenter and
> surnamePresenter. I want to create an array the models of those
> presenters

I don't see why, however...

 > so I tried this:
> a := #((firstnamePresenter model) (surnamePresenter model)).
> It didn't work.

It worked as expected.

> How can I tell St to evaluate the expressions (such as
> firstnamePresenter model) and insert the _result_ into the array?
> Otherwise I get an array of symbols and that's not what I want.

a := Array
        with: firstnamePresenter model
        with: surnamePresenter model

Best regards.


--
Esteban A. Maringolo
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Evaluate before adding to array

Fernando Rodríguez
On Wed, 23 Mar 2005 09:17:50 -0300, "Esteban A. Maringolo"
<[hidden email]> wrote:


>> How can I tell St to evaluate the expressions (such as
>> firstnamePresenter model) and insert the _result_ into the array?
>> Otherwise I get an array of symbols and that's not what I want.
>
>a := Array
> with: firstnamePresenter model
> with: surnamePresenter model

I'm aware of this solution, but I was looking forward to use the
shorter #() syntax. Is it possible?


Reply | Threaded
Open this post in threaded view
|

Re: Evaluate before adding to array

Chris Uppal-3
Fernando,

> I'm aware of this solution, but I was looking forward to use the
> shorter #() syntax. Is it possible?

It's not possible.  You're out of luck, I'm afraid ;-)

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: Evaluate before adding to array

Fernando Rodríguez
Chris Uppal wrote:
> Fernando,
>
> > I'm aware of this solution, but I was looking forward to use the
> > shorter #() syntax. Is it possible?
>
> It's not possible.  You're out of luck, I'm afraid ;-)

Pity. I guess this sort of 'syntactic sugar' is implemented in the VM
and not modifiable by the user. Is this correct?

After googling for a while, I found out that what I was looking for
seems to be available in Squeak:
http://www.smalltalk.org/articles/article_20040920_a2.html

This seems useful. Any chances of it being incorporated into Dolphin?
Andy, Blair? O:-)


Reply | Threaded
Open this post in threaded view
|

Re: Evaluate before adding to array

John Aspinall-5
In reply to this post by Fernando Rodríguez
"Fernando" <[hidden email]> wrote...

> I'm aware of this solution, but I was looking forward to use the
> shorter #() syntax. Is it possible?

You may want to try something similar to the following:

!Object methodsFor!

|| anObject

    ^OrderedCollection with: self with: anObject! !

!OrderedCollection methodsFor!

|| anObject

    ^self
        addLast: anObject;
        yourself! !

With these two methods installed, you can enter

firstnamePresenter model || surnamePresenter model

...which gives you an OrderedCollection, so you may want to say

(firstnamePresenter model || surnamePresenter model) asArray

I originally implemented these as part of a collection-based Excel interface
(hence the double vertical bar, which I chose to suggest a cell divider), but
found them useful elsewhere too.

Best regards,

John Aspinall
Solutions Software


Reply | Threaded
Open this post in threaded view
|

Re: Evaluate before adding to array

Fernando Rodríguez
On Wed, 23 Mar 2005 15:48:56 GMT, "John Aspinall"
<[hidden email]> wrote:

>"Fernando" <[hidden email]> wrote...
>
>> I'm aware of this solution, but I was looking forward to use the
>> shorter #() syntax. Is it possible?
>
>You may want to try something similar to the following:

[snip]

Cute. Good idea. :-)