RE: listed subscripting

new topic     » goto parent     » topic index » view thread      » older message » newer message

Juergen Luethje wrote:
> 
> Antonio Alessi wrote:
> 
> > Juergen Luethje wrote:
> >> .. ..
> > 
> >> -- elegant swap:
> >> {a,b} = {b,a}
> >> 
> >> -- current swap:
> >> temp = a
> >> a = b
> >> b = temp
> >
> > 
> > Hello Juergen,
> > 
> > why temp? 
> > 
> > line = {1, 2}
> > 
> > EU plain swap:
> > 
> > line = line[2]&line[1]
> 
> What I wrote is the classic algorithm for swapping the values of two
> variables, in German called "zyklische Vertauschung" (translates in
> English probably to something like "cyclic exchange").
> 
> In your code not the values of two variables are swapped, but the values
> of two elements of one variable. I was not talking about a variable
> 'line', which is a sequence of two elements, but of two separate
> variable 'a' and 'b'.
> 
> Code similar to yours that does what I had described would look like this:
> line = {a, b}
> a = line[2]
> b = line[1]
> 
> So your 'line' is a temp variable in disguise. smile
> I don't consider this way more elegant than the classic "cyclic exchange".
> 
> Regards,
>    Juergen


Sorry Juergen, but on the Euphoria ground I have to contradict what you say.
Perhaps to write {a, b} = {b, a} may look "elegant", but it is not logic:
the {a, b} notation, in lack of oneness is nothing, does not make sense.
If you want to treat that as an entity, you must assign a Label to, 
i.e. identify in a unity. Cannot move two things toghether if we don't 
put them into the same "box". When you write an expression as  
{a, b} = , you introduce the concept of a variable anyhow.

Fortunately Euphoria makes this possible, bringing in the concept of sequence,
that overlaps without invalidating the independence of the two values; 
if we say:

Label = {a, b}

in order to handle them, we don't alter the original meaning of variable 'a'
and the separate variable 'b'; simply we can hold them like an ensemble too, 
swapping and even using them for an expression like that of Christian:

Label = doSomething({n1,n2,s1,s2,s3})

even simpler than:
{n1,n2,s1,s2,s3} = doSomething({n1,n2,s1,s2,s3})

provided that:

function doSomething(sequence vars)
return {n1,n2,s1,s2,s3}

	
end function

All that with no need to add thereafter:

n1 = Label[1]
s1 = Label[3]

since n1 IS Label[1] already; we have just to change our habit conceiving and 
using L[1] in place of n1, both being able to assume any kind of value. 
Other "programming" languages (we do not make literature here) may 'not to
allow' this, as every element of an array can assume a single value, but 
cannot BE an unlimited sequence (a world, or individual) in itself.

So your quote
"In your code not the values of two variables are swapped, 
but the values of two elements of one VARIABLE"

should be replaced with:

"In your code not the values of two variables are swapped, 
but the values of two elements of one SEQUENCE", where

the values of two variables,                and
the values of two elements of one sequence

become the same thing, so that here we can directly do what you'd like to,
respecting the taste of gracefulness in the form as well as into the idea.
This is the 'soul' of Euphoria and I find it a waste to insist 
interpreting and using the way of any other "more traditional" language.

Regards,
  antonio

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu