1. Named Elements (Was Re: Eu improvements (part 3))
- Posted by c.k.lester <euphoric at cklester.com> Jan 04, 2007
- 543 views
c.k.lester wrote: > my_record = get_db_record( 3 ) > > -- options > my_record.field1 (field1, field2, etc.) -- no likey this much > my_record.Field_Name -- better, but what about fields with spaces in them? > my_record.'Field Name' > my_record['Field Name'] -- very nice The last option there is, of course, a named element. my_seq = { { "one", "two", "three" }, { 1, 2, 3 } } ? my_seq['one'] -- 1 ? my_seq['two'] -- 2 ? my_seq['test'] -- NULL? error? my_seq[2][1] = { { 'one' }, { 1 } } ? my_seq['one']['one'] -- 1 ? my_seq[2][1][2] -- 1 ? my_seq[2][1][1] -- one ------or sequence my_seq is atom one=1, two=2, three=3 end sequence my_seq seq1 -- can used named parameters or dot notation ? seq1['one'] -- 1 ? seq1.one -- 1 ? seq1['test'] -- NULL? error? etc...
2. Re: Named Elements (Was Re: Eu improvements (part 3))
- Posted by Karl Bochert <kbochert at copper.net> Jan 04, 2007
- 559 views
- Last edited Jan 05, 2007
c.k.lester wrote: > ------or > > sequence my_seq is > atom one=1, two=2, three=3 > end sequence > > my_seq seq1 > > -- can used named parameters or dot notation > ? seq1['one'] -- 1 > ? seq1.one -- 1 > ? seq1['test'] -- NULL? error? I'm confused here. seq1.one is a euphoria object with a value, just as foo is after atom foo Therefore seq1.test is an error because it has not been defined. Is seq1['one'] the same thing written with a different syntax? Or is your intention to provide a dictionary where seq1['test'] returned NULL until after you have done add(seq1, 'test', 0) ? KtB
3. Re: Named Elements (Was Re: Eu improvements (part 3))
- Posted by c.k.lester <euphoric at cklester.com> Jan 04, 2007
- 563 views
- Last edited Jan 05, 2007
Karl Bochert wrote: > c.k.lester wrote: > > > > sequence my_seq is > > atom one=1, two=2, three=3 > > end sequence > > > > my_seq seq1 > > > > -- can used named parameters or dot notation > > ? seq1['one'] -- 1 > > ? seq1.one -- 1 > > ? seq1['test'] -- NULL? error? > > I'm confused here. > seq1.one is a euphoria object with a value, just as foo is after > atom foo > Therefore seq1.test is an error because it has not been defined. Right. I was throwing out a test case that should cause an error... But in these cases, you might need to ask isDefined( seq1, 'test' ) or somesuch... especially working with dynamic or user-generated data/metadata. > Is seq1['one'] the same thing written with a different syntax? Yes.