Re: another newbie question
- Posted by "Glen T. Brown" <gbrown at SAUDIONLINE.COM.SA> Aug 31, 1999
- 365 views
Hi Kat, Hope this helps. > I have ordered an epiphany, and i hope it is delivered soon, so i can really > grasp exactly and fully all the implications of the preceeding and revel in > it, but for now, how do i avoid the following error msg with a test > preceeding the print statement? According to the Euphoria Programming Language Reference Manual: --- 2.1.1 Atoms and Sequences All data objects in Euphoria are either atoms or sequences. An atom is a single numberic value. A sequence is a collection of numeric values. --- Now to me this says that a SEQUENCE is really just a collection of ATOMs all strung together. Also indicated by the fact that while tracing a program any variable that is a 'string' (or collection of readable letters) is displaied as its ASCII value. RDS was thoughtful enough to supply the letter equivelant of any number that is a printable ASCII character along with that number. Now, your problem seems to be getting a handle on nested sequences. Another way to look at a sequence is that it is a one-dimentional array of atoms. With that in mind, a nested sequence is just a multi-dimentional array of atoms. >Given: >sentword = {"test1",{"test2","test3"}} > >printf(1,"%s\n", sentword[1] ) >-- prints: t Given the examples that you provided. The 't' that you ended up with is the first 't' from "test1". You only got the 't' because 'sentword[1]' by itself indicates to Euphoria that you are only interested in an atom. >printf(1,"%s\n", {sentword[1]} ) >-- prints: test1 What you get here is obviously "test1". The '{' and '}' indicate to Euphoria that you are interested in the sequence that is at subscript 1 >printf(1,"%s\n", sentword[2] ) >-- prints: test2 This one is probably where you are getting really confused. I have been messing with it a little and I find it slightly confusing too. If you do some more testing you will find that : printf(1,"%s\n", {sentword[2] }) Generates this error: sequence found inside character string If I understand this correctly with this expression Euphoria is expecting to find a single sequence in subscript two when there is in reality two sequences inside sequence two. {"test2","test3"} This is two sequences of characters. On first glance it would seem that printing sentword[2] would give you a 't' like it did with sentword[1]. However, it looks like since sentword[2] is a subscript itself that Euphoria picks up the first element of the substring. That being "test2". I am reading this as I go and I am starting to confuse myself. I think that we need to look at this problem the way that Euphoria is looking at it. What Euphoria actually sees is more along the lines of : I thik this is a little more obvious. There is a nesting of sequences that is three deep. I think that the following can be extrapilated from this. printfing -- sentword[1] gives the first element that it finds in the first subscript. 116 printfing -- {sentword[1]} gves the first sequence that it finds in the first subscript. 116,101,115,116,49 printfing -- sentword[2] gives the first element that it finds in the second subscript. {116,101,115,116,50} which just happens to be a sequence. printfing -- {sentword[2]} gives an error because it is looking for a sequence and finds a sequence of sequences because you are trying to format it as a string and Euphoria sees a string of strings which is evidently not valid. printfing -- sentword[2][1] gives the first element of the first sub-subscript of the second subscript. 116 printfing -- {sentword[2][1]} gives the sequence that it finds in first sub-subscript of the second subscript. 116,101,115,116,50 Now, after all that. I hope that this at least makes some sense to someone. I am hoping that it makes sense to Kat because that is who it was meant for. I would recomend reading Part I chapter 2 of the Reference Manual. I think that it goes over this stuff quite well. As I am trying to explain this I am reading the manual and playing with Euphoria in another window. Gets a little confusing after a while. Good luck on the arrival of your epiphany. I hope that it is everything that you are expecting. > Kat, > foolishly trying to make it simple. > Or is it too simple already? Till next time. L8R Glen