Re: named array

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

Hi

I'am not sure if my english is good enough, but i will try to explain somethings. If someone knows it better i will be happy if he/she helps with this.

What you do in ruby is very different to what you do in Euphoria. In Ruby you give an 'Object a Name' this name is only valid in the context of the object.

object = { :x => 100, :y => -200, :z => 300 }  
puts object[ :z ]  
object1= { :z => 100, :y => -200, :x => 300 }  
puts object1[ :z ]  
If you try this, you will see that :z is different.
In Euphoria you declare a constant with enum, the 'Z' will always be the same in whatever context you use it. In the case below 'Z' is 3
You can replace every 'Z' with a '3' and the program also will work.

include std/console.e -- for any_key() 
enum X, Y, Z -- I need to name coordinates externally (in public? not very useful)  
sequence Object = {0, 0, 0} -- I can't say Object = {}, because sequences not able to auto-expand  
Object[X] = 100  
Object[Y] = -200  
Object[Z] = 300  
puts(1, sprintf("%d",Object[Z])&"\n") 
 
sequence o2= {100,-200,300} 
puts(1, sprintf("%d",o2[Z])&"\n") 
 
sequence o3={} 
o3 &= 100 
o3 &= -200 
o3 &= 300 
puts(1, sprintf("%d",o3[Z])&"\n") 
 
sequence o4={} 
o4=append(o4,Object) 
o4=append(o4,o2) 
o4=append(o4,o3) 
 
puts(1, sprintf("%d",o4[X][Y])&"\n") 
 
print (1,o4) 
puts(1,"\n") 
 
 
sequence o5={} 
for i = 1 to Z do 
	o5=append(o5,o4) 
end for 
 
puts(1, sprintf("%d",o5[X][Y][Z])&"\n") 
 
print (1,o5) 
puts(1,"\n") 
 
 
any_key() 
 

What i try to say is, you are comparing different Programming paradigm, this will not really work.
From the Programming paradigm, you maybe better compare Euphoria to 'C' or 'Pascal' not to an OO Language (if I'am wrong feel free to correct me).

Andreas

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

Search



Quick Links

User menu

Not signed in.

Misc Menu