Re: ignoring { } ?

new topic     » goto parent     » topic index » view thread      » older message » newer message
Kat said...
list &= i == list &= {i} ? 

Your post is a little light on detail, but I'm assuming you are asking the question ...

Why does list &= i and list &= {i} give the same result?

The &= operator concatenates data rather than appends data. By this I mean that & joins two sets of data together while append() adds one item to the end of a sequence.

sequence list = {} 
integer i = 2 
list &= i  -- join everything on the righthand side to the 'list' 
           -- As 'i' is just a single integer, then only one integer is added. 
           -- The 'list' length is increased by 1. 
 --> {2} 
list &= {i}  -- join everything on the righthand side to the 'list' 
             -- As '{i}' is a list containing a single integer, then only one integer is added. 
             -- The 'list' length is increased by 1. 
 --> {2} 
list &= {i,i}  -- join everything on the righthand side to the 'list' 
               -- As '{i,2}' is a list containing two integers, then both are added. 
               -- The 'list' length is increased by 2. 
 --> {2,2} 

The append() operation is different in that it only ever adds one thing to the list. The argument is added as a single element.

list = append(list,i)  -- append the righthand side to the 'list' 
                       -- The 'list' length is increased by 1. 
 --> {2} 
list = append(list, {i})  -- append the righthand side to the 'list' 
                          -- The 'list' length is increased by 1. 
 --> {{2}} 
list = append(list, {i,i})  -- append the righthand side to the 'list' 
                            -- The 'list' length is increased by 1. 
 --> {{2,2}} 


By the way, you don't need to insert manual line breaks inside EUCODE tags.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu