Basic Sequences -- Jim C.
- Posted by Al Getz <Xaxo at aol.com> Mar 16, 2001
- 479 views
Hi Jim, Here is some info to supplement what's already been posted. It helps to think of a sequence as a list, as that's what it really is anyway. To access items of the list, simply use the name of the list followed by the number of the element in the list enclosed in [ ] like this: name[2] -- to access the second item on the list. name[3] -- to access the third item on the list. Here's an example: --an enumerated real world list called 'list A': [1] cat [2] dog [3] mouse [4] 3.14159 --let's code that same list in Euphoria: sequence A A={"cat","dog","mouse",3.14159} --let's print out that A list to the screen: puts(1,A[1]) puts(1,'\n') puts(1,A[2]) puts(1,'\n') puts(1,A[3]) puts(1,'\n') print(1,A[4]) --use 'print' for a number puts(1,'\n') --now let's view the structure of the first item on the list --instead of just displaying it in the usual way: print(1,A[1]) puts(1,'\n') Some notes to think about: Take note that puts(1,A[1]) and print(1,A[1]) give us two different views of the same item of the list. Like Kat was saying, you may want to experiment with various ways of printing your sequence items before you get involved with command_line() arguments. Learning to print out data is an important part of programming, at some point or another you will need to print out your data correctly in order to effectively debug your advanced programs. Also note that in order to access an item, say A[3], that item must already exist. In our list above (list A) we wouldnt be able to execute: puts(1,A[5]) for the simple reason that we didnt store anything on the list at would-be-location A[5] yet. In this case an error would occur and the program would halt. Sequences are a little strange even for experienced programmers who are used to using more 'well defined' data types. Once they are mastered, the problems diminish rapidly. Good luck with it. --Al "Understanding is just around the corner from experimentation."