1. Basic Euphoria Sequences
- Posted by Some Slacker <some_slacker at yahoo.com> Feb 10, 2006
- 488 views
Ok, I know, I'm a moron, but I really need a helping hand making new sequences, specifically... the number of elements in each sequence is a set of 14 (I think) sequences 2 of these sequences are themselves sequences but of an unknown length perhaps one element but maybe more, and I need each sequence to be able to be looked at like sequence[1][3] for obviously the third element of the first record... I'm not really sure how to set this sequence in motion
NewRecord=repeat(0,14) -- this will make a 14 element sequence of 0's I know that, but how -- then do I make say elements 5 and 6 themselves sequences (with their -- own list of records) sequence[1][5][1..or more]
I know this is a basic question, and I probably already know the answer, but until I see it... heh. Thanks in advance, Some Slacker
2. Re: Basic Euphoria Sequences
- Posted by don cole <doncole at pacbell.net> Feb 10, 2006
- 452 views
Some Slacker wrote: > > Ok, I know, I'm a moron, but I really need a helping hand making > new sequences, specifically... > the number of elements in each sequence is a set of 14 (I think) > sequences 2 of these sequences are themselves sequences but of > an unknown length perhaps one element but maybe more, and I need > each sequence to be able to be looked at like sequence[1][3] for > obviously the third element of the first record... I'm not really > sure how to set this sequence in motion > }}} <eucode> > NewRecord=repeat(0,14) > -- this will make a 14 element sequence of 0's I know that, but how > -- then do I make say elements 5 and 6 themselves sequences (with their > -- own list of records) sequence[1][5][1..or more] > </eucode> {{{ > > I know this is a basic question, and I probably already know the > answer, but until I see it... heh. > > Thanks in advance, > Some Slacker I'm not sure what your trying to do but I would think: </eucode> {{{ --Writing: seq[1][1]=atom_data seq[1][5]=seq_data --Reading: for x=1 to 14 do if atom(seq[1][x]) then treat_as_atom() elsif sequence(seq[1][x]) then treat_as_sequence() end for --or for x=1 to 14 do if length(seq[1][x])=1 then treat_as_atom() elsif length(seq[1][x])>1 then treat_as_sequence() end for Hope this helps, Don Cole A Bug is an un-documented feature. A Feature is a documented Bug.
3. Re: Basic Euphoria Sequences
- Posted by Some Slacker <some_slacker at yahoo.com> Feb 10, 2006
- 472 views
don cole wrote: > I'm not sure what your trying to do but I would think: > > </eucode> {{{ > --Writing: > seq[1][1]=atom_data > seq[1][5]=seq_data > > --Reading: > > for x=1 to 14 do > if atom(seq[1][x]) then > treat_as_atom() > elsif sequence(seq[1][x]) then > treat_as_sequence() > end for > > --or > > for x=1 to 14 do > if length(seq[1][x])=1 then > treat_as_atom() > elsif length(seq[1][x])>1 then > treat_as_sequence() > end for > > Hope this helps, > > Don Cole This is somewhat helpful, but I'm still unsure how to best start this sequence. To be more specific the 14 elements will all be sequences for things like timestamps, strings, numbers, more strings, more numbers etc. now for some of the strings i need to be able to seperate out the strings to be a list(for a listview, or a combo box for example) so that some of the elements of the sequence are single strings or just atoms, or formatted for time or currency etc. and some of the elements are themselves their own list of strings... if the data could look something like... {{{time},{time2},{time3},{time4},{string},{string2},{atom},{atom (formatted for currency)}, {atom (again currency)}, {string3} etc. }} now what if the strings are lists for a combo box, can i just add elements to each of these strings? {{{time},{time2},{time3},{time4},{{string1},{string1a}},{{string2},{string2a}}, {atom},{atom (formatted for currency)}, {atom (again currency)}, {string3} etc. }} I hope this makes my problem just a bit clearer, I know I'm unclear, but I don't know what it is I want, I just know I want it!!! LOL! thanks again, Some (Serious) Slacker
4. Re: Basic Euphoria Sequences
- Posted by don cole <doncole at pacbell.net> Feb 10, 2006
- 466 views
Some Slacker wrote: > > don cole wrote: > > I'm not sure what your trying to do but I would think: > > > > </eucode> {{{ > > --Writing: > > seq[1][1]=atom_data > > seq[1][5]=seq_data > > > > --Reading: > > > > for x=1 to 14 do > > if atom(seq[1][x]) then > > treat_as_atom() > > elsif sequence(seq[1][x]) then > > treat_as_sequence() > > end for > > > > --or > > > > for x=1 to 14 do > > if length(seq[1][x])=1 then > > treat_as_atom() > > elsif length(seq[1][x])>1 then > > treat_as_sequence() > > end for > > > > Hope this helps, > > > > Don Cole > > This is somewhat helpful, but I'm still unsure how to best start > this sequence. To be more specific the 14 elements will all be sequences > for things like timestamps, strings, numbers, more strings, more numbers > etc. > > now for some of the strings i need to be able to seperate out the strings > to be a list(for a listview, or a combo box for example) so that some > of the elements of the sequence are single strings or just atoms, or > formatted for time or currency etc. and some of the elements are themselves > their own list of strings... > > if the data could look something like... > > {{{time},{time2},{time3},{time4},{string},{string2},{atom},{atom (formatted > for currency)}, {atom (again currency)}, {string3} etc. }} > > now what if the strings are lists for a combo box, can i just add elements > to each of these strings? > > > {{{time},{time2},{time3},{time4},{{string1},{string1a}},{{string2},{string2a}}, > {atom},{atom (formatted for currency)}, {atom (again currency)}, > {string3} etc. }} > > I hope this makes my problem just a bit clearer, I know I'm unclear, > but I don't know what it is I want, I just know I want it!!! LOL! > > thanks again, > Some (Serious) Slacker Hello Some Slacker, I have similar thing I am doing to keep track of Movie inventory.
rec[1]=movie_num rec[2]-title rec[11]=history rec[11][1]=date rec[11][2]=item--purchased ,sold,rented,traded etc. rec[11]3]=amount --as you can see record 11 could be of any length. A movie could be bought, --sold, bought back again ,rented 3 times and then sold again. A long history.
The best way to keep track of everything is with an index. For my index I use movie number. Maybe you could use something like transaction number. Make that rec[1].
--add a new movie database=append(database,rec) index=append(index,rec[1]) --find a movie a=find(movie_num,index) title=database[a][2]
So on and so forth. There are A lot of database programs in the Archives you could look over. But for your purposes it would be best to construct your own. Starting off with transaction num being rec[1] and building on that. Don Cole A Bug is an un-documented feature. A Feature is a documented Bug.
5. Re: Basic Euphoria Sequences
- Posted by Rad <radhx at rediffmail.com> Feb 10, 2006
- 491 views
Some Slacker wrote: > > now for some of the strings i need to be able to seperate out the strings > to be a list(for a listview, or a combo box for example) so that some > of the elements of the sequence are single strings or just atoms, or > formatted for time or currency etc. and some of the elements are themselves > their own list of strings... > > if the data could look something like... > > {{{time},{time2},{time3},{time4},{string},{string2},{atom},{atom (formatted > for currency)}, {atom (again currency)}, {string3} etc. }} > > now what if the strings are lists for a combo box, can i just add elements > to each of these strings? > > > {{{time},{time2},{time3},{time4},{{string1},{string1a}},{{string2},{string2a}}, > {atom},{atom (formatted for currency)}, {atom (again currency)}, > {string3} etc. }} > You have to define an original sequence containing sequences. Hope following example will help.
sequence testSeq testSeq = repeat({}, 14) for i = 1 to 14 do testSeq[i] = append(testSeq[i], i) -- first item of testSeq[1] is atom testSeq[i] = append(testSeq[i], {}) -- second item of testSeq[1] itself is a sequence testSeq[i][2] = append(testSeq[i][2], i) -- first item of the testSeq[1][2] is again atom... and so on end for VOID = message_box(sprintf("Length of testSeq: %d", length(testSeq)), "Info", MB_ICONINFORMATION) VOID = message_box(sprintf("Length of testSeq[1]: %d", length(testSeq[1])), "Info", MB_ICONINFORMATION) VOID = message_box(sprintf("Length of testSeq[1][2]: %d", length(testSeq[1][2])), "Info", MB_ICONINFORMATION)
Regards, Rad.
6. Re: Basic Euphoria Sequences
- Posted by ags <eu at 531pi.co.nz> Feb 10, 2006
- 460 views
Some Slacker wrote: > > Ok, I know, I'm a moron, but I really need a helping hand making > new sequences, specifically... > the number of elements in each sequence is a set of 14 (I think) > sequences 2 of these sequences are themselves sequences but of > an unknown length perhaps one element but maybe more, and I need > each sequence to be able to be looked at like sequence[1][3] for > obviously the third element of the first record... I'm not really > sure how to set this sequence in motion > }}} <eucode> > NewRecord=repeat(0,14) > -- this will make a 14 element sequence of 0's I know that, but how > -- then do I make say elements 5 and 6 themselves sequences (with their > -- own list of records) sequence[1][5][1..or more] > </eucode> {{{ This is not a specific answer (as sequences themselves are so versatile) but some practices I use. They may or may not suit you. If I'm using sequences as records, I always define constants for the 'fields' eg:
sequence records constant REC_ID = 1, -- atom REC_NAME = 2, -- string sequence REC_DATE = 3, -- DateTime sequence structure REC_DIRENT = 4, -- output of dir(...) REC_PATH = 5 -- string sequence
I then immediately manually define a 'blank' record. This allows you to have certain defaults if you wish not to fill out all of them at the time of record creation. It also gives you a visual clue of what your records look like:
constant blank_record = {-1, "", {}, {}, ""}
When creating a new record I fill in a copy of the blank record:
sequence newrec newrec = blank_record newrec[REC_ID] = get_next_id() -- as an example newrec[REC_NAME] = file_name newrec[REC_DATE] = nowDateTime() newrec[REC_DIRENT] = dir(current_path & "\\" & file_name) newrec[REC_PATH] = current_path
Then I append the new record to the sequence containing the records:
records = append(records, newrec)
I find this the most reliable in terms of readability (you can see what is being assigned to which field of a record), flexibility (you can assign to newrec in any order) and expandability (by changing the REC_* constants and the blank_record you can alter the structure of the records with minimum recoding). Imagine you assign the records like:
sequence newrec newrec = {get_next_id(),file_name,nowDateTime(), dir(current_path & "\\" & file_name), current_path)
And then you realise that storing file_name is not necessary. You can leave it in and ignore it at the expense of memory/complexity, or you can modify the constants, the blank_record and any part of the code that refers to [REC_NAME] (which is easy to search, rather than going cross-eyed looking at sequence curly brackets). In general terms in answer to your question, if you want record[4] to be a sequence, or sequence of sequences then you just assign a sequence to that position, eg record[4] = {1, 2, 3, 4} but I would create a function to return the sequence structure you are after. Hope this helps Gary
7. Re: Basic Euphoria Sequences
- Posted by don cole <doncole at pacbell.net> Feb 10, 2006
- 477 views
ags wrote: > > This is not a specific answer (as sequences themselves are so versatile) but > some practices I use. They may or may not suit you. > > If I'm using sequences as records, I always define constants for the 'fields' > eg: > }}} <eucode> > sequence records > > constant REC_ID = 1, -- atom > REC_NAME = 2, -- string sequence > REC_DATE = 3, -- DateTime sequence structure > REC_DIRENT = 4, -- output of dir(...) > REC_PATH = 5 -- string sequence > > </eucode> {{{ > > I then immediately manually define a 'blank' record. This allows you to have > certain defaults if you wish not to fill out all of them at the time of record > creation. It also gives you a visual clue of what your records look like: > }}} <eucode> > constant blank_record = {-1, "", {}, {}, ""} > </eucode> {{{ > > When creating a new record I fill in a copy of the blank record: > }}} <eucode> > sequence newrec > newrec = blank_record > newrec[REC_ID] = get_next_id() -- as an example > newrec[REC_NAME] = file_name > newrec[REC_DATE] = nowDateTime() > newrec[REC_DIRENT] = dir(current_path & "\\" & file_name) > newrec[REC_PATH] = current_path > </eucode> {{{ > Then I append the new record to the sequence containing the records: > }}} <eucode> > records = append(records, newrec) This I highly approve of. Don Cole A Bug is an un-documented feature. A Feature is a documented Bug. >
8. Re: Basic Euphoria Sequences
- Posted by Some Slacker <some_slacker at yahoo.com> Feb 10, 2006
- 473 views
don cole wrote: > > ags wrote: > > > > > This is not a specific answer (as sequences themselves are so versatile) but > > some practices I use. They may or may not suit you. > > > > If I'm using sequences as records, I always define constants for the > > 'fields' > > eg: > > }}} <eucode> > > sequence records > > > > constant REC_ID = 1, -- atom > > REC_NAME = 2, -- string sequence > > REC_DATE = 3, -- DateTime sequence structure > > REC_DIRENT = 4, -- output of dir(...) > > REC_PATH = 5 -- string sequence > > > > </eucode> {{{ > > > > I then immediately manually define a 'blank' record. This allows you to > > have > > certain defaults if you wish not to fill out all of them at the time of > > record > > creation. It also gives you a visual clue of what your records look like: > > }}} <eucode> > > constant blank_record = {-1, "", {}, {}, ""} > > </eucode> {{{ > > > > When creating a new record I fill in a copy of the blank record: > > }}} <eucode> > > sequence newrec > > newrec = blank_record > > newrec[REC_ID] = get_next_id() -- as an example > > newrec[REC_NAME] = file_name > > newrec[REC_DATE] = nowDateTime() > > newrec[REC_DIRENT] = dir(current_path & "\\" & file_name) > > newrec[REC_PATH] = current_path > > </eucode> {{{ > > Then I append the new record to the sequence containing the records: > > }}} <eucode> > > records = append(records, newrec) > > > This I highly approve of. > > Don Cole > > > Yeah, I hate to say it but for this code... "I'm Lovin' It!"