Newbie question

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

Re: Newbie question

Klaus D. Witzel
On Mon, 30 Jul 2007 18:04:04 +0200, J J (in a hard-to-read HTML message :)  
wrote:

>
> Well, it's syntactic sugar.  It looks pretty alien in Smalltalk, but  
> other languages support multiple-assignment (e.g. "swap"  {a. b} := {b.  
> a}).  Of course this gets tricky because if you have multiple assignment  
> it seems natural to return multiple values from a function (e.g. {a. b}  
> := a swapWith: b).  That would probably require a big change to  
> implement and you end up with something Smalltalk can already do other  
> ways, and become (more) incompatible with other dialects.

You can always do ^ {this. and / or. that} for returning multiple values,  
without any change in Squeak.

> To: [hidden email]> From: [hidden email]>  
> Date: Mon, 23 Jul 2007 12:58:25 -0700> Subject: Re: Newbie question> >  
> On Mon, 23 Jul 2007 12:27:21 -0700, subbukk <[hidden email]> wrote:>  
> > > On Monday 23 July 2007 11:39 pm, Bert Freudenberg wrote:> >> >> Now,  
> at one point the compiler even supported this:> >>> >> {a. b} := {1.  
> 2}> >>> >> which I found cool but was considered evil, even by those  
> who> >> tolerate the braces ...> > What would this do? It looks like  
> you're assigning a literal to another  > literal?>
> _________________________________________________________________
> Don't get caught with egg on your face. Play Chicktionary!  
> http://club.live.com/chicktionary.aspx?icid=chick_wlmailtextlink



Reply | Threaded
Open this post in threaded view
|

Re: Newbie question

Jason Johnson-5
On 7/30/07, Klaus D. Witzel <[hidden email]> wrote:
On Mon, 30 Jul 2007 18:04:04 +0200, J J (in a hard-to-read HTML message :)
wrote:

> That would probably require a big change to
> implement and you end up with something Smalltalk can already do other
> ways, and become (more) incompatible with other dialects.

You can always do ^ {this. and / or. that} for returning multiple values,
without any change in Squeak.


Yes, that's why I said "something Smalltalk can already do".  But  what Smalltalk couldn't do here (without modifications) is catch that return in two (or more) separate  values in one line as:

|a b|
{a.b} := someFunctionReturningTwoValues



Reply | Threaded
Open this post in threaded view
|

Re: Newbie question

Klaus D. Witzel
On Mon, 30 Jul 2007 19:58:34 +0200, Jason Johnson wrote:

> On 7/30/07, Klaus D. Witzel <[hidden email]> wrote:
>> On Mon, 30 Jul 2007 18:04:04 +0200, J J (in a hard-to-read HTML message  
>> :) wrote:
>>
>> > That would probably require a big change to
>> > implement and you end up with something Smalltalk can already do other
>> > ways, and become (more) incompatible with other dialects.
>>
>> You can always do ^ {this. and / or. that} for returning multiple  
>> values,
>> without any change in Squeak.
>
>
>
> Yes, that's why I said "something Smalltalk can already do".  But  what
> Smalltalk couldn't do here (without modifications) is catch that return  
> in
> two (or more) separate  values in one line as:
>
> |a b|
> {a.b} := someFunctionReturningTwoValues


If the vars are allocated consecutively (in address space) then you must  
now wait for language extension to happen: ugly, but it works

| a b |
  a := b := 1.
  (1 to: 2) with: {a + 3. b + 4}
   do: [:ix :val | thisContext tempAt: ix put: val].
  ^ {a. b}

Same for iVars, example #forceNewFrom: :| and other clients of  
#instVarAt:put: ...


12