Re: named array

new topic     » goto parent     » topic index » view thread      » older message » newer message
enum 
	CITIZEN_FIRST,  
	CITIZEN_LAST,  
	CITIZEN_INCOME  
  
enum  
	SUPERHERO_FIRST,  
	SUPERHERO_LAST,  
	SUPERHERO_TASK  
  

This kind of thing makes the accessing much faster than using find with a string. It is easy to write in EUPHORIA:

sequence stephen_hawking = { "Stephen", "Hawking", 120_000 } 

The problem is the code requires the coder to know how the structure members are ordered. The above line breaks 'data encapsulation'. Really you want to combine these with a function struct_assign:

sequence stephen_hawking = struct_assign({ CITIZEN_FIRST, "Stephen",  
                                            CITIZEN_LAST, "Hawking",  
                                          CITIZEN_INCOME, 120_000 }) 

The implementation of struct_assign is an exercise for the reader. :) Remember to replace 'sequence' with your own user defined type to save you from blunders.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu