Re: Newbie question. Difficulty understanding a few things.
- Posted by Mike777 <anon4321 at gmail?c?m> May 25, 2008
- 685 views
Rob H. wrote: > > > Hello. I've been reading "A beginner's guide to euphoria". > This question pertains to demo program 43 in that tutorial... I don't quite > understand a few things. I would appreciate if somebody could tell me what's > going on in this code... > > }}} <eucode> > for element = 1 to length(seek_positions) do > status = seek(file_id,seek_positions[element][1]-1) > if status = 0 then > puts(file_id,seek_positions[element][2]) > end if > </eucode> {{{ > In the second line. I don't understand what the [1]-1 is doing... can somebody > please explain? Both this question and the one below require you to understand how sequences work. Think of them as what other languages typically describe as an "array". But it is more like "an array on steroids" as the language interfaces with sequences in ways that other languages do not interface with arrays. And the fact that the language interfaces with sequences provides a lot of power. In the specific line of code above, you are calling a function (seek) which takes two arguments. The second argument is a number. That number is determined by going to the seek_positions sequence and then looking at what would be referenced in another language as an array, with something like "seek_positions(element,1)" and once that number is retrieved, subtract one from that. > Also, what's the [2] in the 4th line doing...? Same as above. > > Then > > Further down in the code... > > }}} <eucode> > while compare(input_line,-1) != 0 do > puts(1,input_line) > input_line = gets(file_id) > end while > </eucode> {{{ > > Why are they comparing input_line to -1?? Do you have the documentation? If you look up the "compare" library routine you will see that it is comparing the value if "input_line" to "-1". > I'm sorry. I'm a newbie, and there isn't enough documentation available about > Euphoria to satisfy all of my questions... Oh, it is there. You just have to get used to using it. Use this in a google search and select the first link: "sequences are it" euphoria That should get you going. Welcome and good luck. Mike > > > Thanks for the help!