1. Generic symbolic sequence assignment

Could we use any kind of symbolic sequence in LHS of assignment ?

For example, would the following assignment be possible?

{{a,b},c} = {{d,e},f}

- Fernando

new topic     » topic index » view message » categorize

2. Re: Generic symbolic sequence assignment

Fernando said...

Could we use any kind of symbolic sequence in LHS of assignment ?

For example, would the following assignment be possible?

{{a,b},c} = {{d,e},f} 

Yes, we could. My first implementation doesn't have this (it's very simple), but there's no technical reason why we couldn't. I wasn't sure if we wanted to go down this route, although I could see the usefulness.

Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: Generic symbolic sequence assignment

mattlewis said...
Fernando said...

Could we use any kind of symbolic sequence in LHS of assignment ?

For example, would the following assignment be possible?

{{a,b},c} = {{d,e},f} 

Yes, we could. My first implementation doesn't have this (it's very simple), but there's no technical reason why we couldn't. I wasn't sure if we wanted to go down this route, although I could see the usefulness.

Matt

Isn't this simplier and faster ...

a = d 
b = e 
c = f 
new topic     » goto parent     » topic index » view message » categorize

4. Re: Generic symbolic sequence assignment

DerekParnell said...
mattlewis said...
Fernando said...

Could we use any kind of symbolic sequence in LHS of assignment ?

For example, would the following assignment be possible?

{{a,b},c} = {{d,e},f} 

Yes, we could. My first implementation doesn't have this (it's very simple), but there's no technical reason why we couldn't. I wasn't sure if we wanted to go down this route, although I could see the usefulness.

Matt

Isn't this simplier and faster ...

a = d 
b = e 
c = f 

Probably, in this specific case. However, the LHS generic symbolic sequence shows its usefulness when the RHS is a function that returns a generic sequence.

- Fernando

new topic     » goto parent     » topic index » view message » categorize

5. Re: Generic symbolic sequence assignment

This whole assignment thing is getting out of hand.

According to the manual (and how much user-code?)

 {a,b,c} = {d,e,f} returns {a=d,b=e,c=f} 

Surely you don't want to break something as basic as that merely to have multiple and/or generic assignment!

new topic     » goto parent     » topic index » view message » categorize

6. Re: Generic symbolic sequence assignment

bill said...

This whole assignment thing is getting out of hand.

According to the manual (and how much user-code?)

 {a,b,c} = {d,e,f} returns {a=d,b=e,c=f} 

Surely you don't want to break something as basic as that merely to have multiple and/or generic assignment!

This would still work. The expression you mentioned is a RHS value. There is no LHS value there:

s = {a,b,c} = {d,e,f} 
-- s is {a=d, b=e, c=f} 
 
{a, b, c } = { d, e, f} 
-- a is assigned the value of d 
-- b is assigned the value of e 
-- c is assigned the value of f 

In any case, these literal examples are useful for describing what happens, but would not be the most common way they would actually be used. The real utility comes from functions that return multiple results. This avoids the need to store the result, then break out the values, like this:

-- old way: 
s = value( x ) 
success = s[1] 
val     = s[2] 
 
-- new way: 
{success, val} = value( x ) 

Matt

new topic     » goto parent     » topic index » view message » categorize

7. Re: Generic symbolic sequence assignment

bill said...

This whole assignment thing is getting out of hand.

According to the manual (and how much user-code?)

 {a,b,c} = {d,e,f} returns {a=d,b=e,c=f} 

Surely you don't want to break something as basic as that merely to have multiple and/or generic assignment!

I see your point, but the example you have is out of context. The '=' symbol here is not an assignment operator but a comparison operator.

sequence x 
x = {a,b,c} = {d,e,f} -- The first '=' is assignment, the 2nd is comparison. 
 
x = {a=d, b=e, c=f} -- Result in x is a set of 1's and 0's. 
-- Similar to ... 
x = {a,b,c} < {d,e,f} 
x = {a<d, b<e, c<f} -- Result in x is a set of 1's and 0's. 
 
-- Currently this next line is invalid in Eu 
{a,b,c} = {d,e,f} -- An assignment, not a comparison  
new topic     » goto parent     » topic index » view message » categorize

8. Re: Generic symbolic sequence assignment

bill said...

This whole assignment thing is getting out of hand.

According to the manual (and how much user-code?)

 {a,b,c} = {d,e,f} returns {a=d,b=e,c=f} 

Surely you don't want to break something as basic as that merely to have multiple and/or generic assignment!

There is no break. That is true only when it represents a comparison (ex.: after an if or while), not an assignment. For example, in the following valid code:

o = o = o

The first '=' is the assignment operator and the second '=' is the equality operator.

- Fernando

new topic     » goto parent     » topic index » view message » categorize

9. Re: Generic symbolic sequence assignment

Fernando said...

Probably, in this specific case. However, the LHS generic symbolic sequence shows its usefulness when the RHS is a function that returns a generic sequence.

Yes, I was thinking of that, but I'm not yet sure of practical that might be.

Here is an obviously contrived example, but it does highlight problems with functions that return different structures based on the input data.

function FUNC(object x) 
  if x > 0 then 
      return {x, {x * x, sqrt(x)}} 
  elsif x = 0 then 
      return x 
  else 
      return {-x, x * x} 
  end if 
end function 
 
{a,{b,c}} = FUNC( userdata ) 
new topic     » goto parent     » topic index » view message » categorize

10. Re: Generic symbolic sequence assignment

DerekParnell said...
Fernando said...

Probably, in this specific case. However, the LHS generic symbolic sequence shows its usefulness when the RHS is a function that returns a generic sequence.

Yes, I was thinking of that, but I'm not yet sure of practical that might be.

Here is an obviously contrived example, but it does highlight problems with functions that return different structures based on the input data.

function FUNC(object x) 
  if x > 0 then 
      return {x, {x * x, sqrt(x)}} 
  elsif x = 0 then 
      return x 
  else 
      return {-x, x * x} 
  end if 
end function 
 
{a,{b,c}} = FUNC( userdata ) 

Yes. The generic symbolic sequence assignment is, basically, practical only when the structure of the returned object is constant and compatible with the structure of LHS symbolic sequence. But I think there are many cases in this situation.

- Fernando

new topic     » goto parent     » topic index » view message » categorize

11. Re: Generic symbolic sequence assignment

Fernando said...

Could we use any kind of symbolic sequence in LHS of assignment ?

For example, would the following assignment be possible?

{{a,b},c} = {{d,e},f} 

Brilliant idea!

DerekParnell said...

Isn't this simplier and faster ...

a = d 
b = e 
c = f 

Shame on you!

FWIW, Phix has, or will have:
= - the "ambiguous" (ie context-dependent) operator as per OpenEU
:= - the explicit assignment operator (not properly implemented yet)
== - the explicit equality operator

Note that Phix only permits these explicit operators as an aid for legibility; it does NOT extend functionality, so both

  a==0 

and

  if a:=0 then 

generate compiler errors

Pete
Forked into: Phix language

new topic     » goto parent     » topic index » view message » categorize

12. Re: Generic symbolic sequence assignment

Yuck. I've always despised using ":=" or "==" when "=" works just fine for both assignment and equality.

Just like I never wrote "let" in BASIC.

new topic     » goto parent     » topic index » view message » categorize

13. Re: Generic symbolic sequence assignment

petelomax said...

FWIW, Phix has, or will have:
= - the "ambiguous" (ie context-dependent) operator as per OpenEU
:= - the explicit assignment operator (not properly implemented yet)
== - the explicit equality operator

Yeah, I've consider these and I'm not unhappy about the idea.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu