Re: peek/poke
- Posted by Brian Broker <bkb at CNW.COM> Mar 27, 2000
- 626 views
On Mon, 27 Mar 2000 14:44:13 -0500, Everett Williams wrote: >On Mon, 27 Mar 2000 14:14:05 -0600, Kat wrote: > >>I have a question too! >>Since we have: >>s = peek({100, 4}) >>where 4 memory locations (100,101,102,103) are read and dropped into s, >>where is the corresponding poke command? What if i want to poke a 80K >>sequence into memory? Can i do: >>poke(s,{location,length(s)}) >>, where each byte of s lands in the next memory location? What if s contains >>nested sequences? It's not in the docs that i can find. What if i want each >>char of s to land in the *same* memory addy? >> >>Kat > >Kat, unless I have completely misread the manual, there is no length >parameter in either poke or poke4. s in your equation must be an atom, >not a sequence. The length of the sequence will determine the length >of the poke.So, you should check the length of the available allocation >from the point of the poke against the length of the sequence before >you start the process. Since nothing in Euphoria that is exposed keeps >track of that remaining length, it is, as usual, an exercise for the user. >That is why, IMO, the examples use an offset rather than changing the >address...it makes the available length more obvious. As for nesting, >another exercise to be tested by the user( I really am not against an >improved manual ) I think you both need to re-read the manual: peek: ===== Syntax: i = peek(a) or ... s = peek({a, i}) Description: Return a single byte value in the range 0 to 255 from machine address a, or return a sequence containing i consecutive byte values starting at address a in memory. (This means you can read a single byte, or consecutive bytes.) poke: ===== Syntax: poke(a, x) Description: If x is an atom, write a single byte value to memory address a. If x is a sequence, write a sequence of byte values to consecutive memory locations starting at location a. (This means you can poke a single byte, or consective bytes.) >>What if i want each >>char of s to land in the *same* memory addy? I have no idea why you would want to do this but you could set up a 'for' loop and poke the contents of a sequence to the same address. (or save yourself the trouble and just poke the last element of the sequence since that is what the end result will be). I don't see how the manual could be more clear about the usage of peek and poke... It seems quite straight-forward to me. -- Brian