1. peek/poke
- Posted by Kat <gertie at ZEBRA.NET> Mar 27, 2000
- 629 views
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
2. Re: peek/poke
- Posted by Everett Williams <rett at GVTC.COM> Mar 27, 2000
- 633 views
On Mon, 27 Mar 2000 14:14:05 -0600, Kat <gertie at ZEBRA.NET> 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 ) Everett L.(Rett) Williams rett at gvtc.com
3. Re: peek/poke
- Posted by Brian Broker <bkb at CNW.COM> Mar 27, 2000
- 627 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
4. Re: peek/poke
- Posted by Brian Broker <bkb at CNW.COM> Mar 27, 2000
- 614 views
On Mon, 27 Mar 2000 15:02:53 -0500, Brian Broker wrote: > >I think you both need to re-read the manual: > I'd better be careful here. I was originally confused by Rett's reply but after re-reading it, I see that his statements are indeed true. I just don't want to start anything here... -- Brian
5. Re: peek/poke
- Posted by Irv Mullins <irv at ELLIJAY.COM> Mar 27, 2000
- 619 views
On Mon, 27 Mar 2000, you 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)}) Yep, but it looks like this: poke(addr, sequence) The entire length of the sequence is poked into memory, starting at addr. > , 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. You'll get an error message: "Sequence to be poked must contain only atoms". >What if i want each char of s to land in the *same* memory addy? Make a loop. You'll be doing some processing in between each poke, right? Regards, Irv
6. Re: peek/poke
- Posted by Everett Williams <rett at GVTC.COM> Mar 27, 2000
- 606 views
Brian Broker wrote: snip >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. snip >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 Since we both know that sequences are essentially infinite in structure and length, what does happen when you poke s where s ={"xxx","yyy","zzz"}. Yes I know it can be checked, but it is anything but clear from the manual what would happen in this situation, much less more complicated ones. The examples carefully shy away from anything complex, and the definition does not rule them out. I'll pull out one of Knuth's most famous quotes about a piece of code that he had sent to another person. "I've only proven that it is correct, not tested it." Yes, we do have to try things, but it would be nice if the manual gave us a few clues ahead of time. Everett L.(Rett) Williams rett at gvtc.com
7. Re: peek/poke
- Posted by Everett Williams <rett at GVTC.COM> Mar 27, 2000
- 605 views
Irv Mullins wrote: >You'll get an error message: "Sequence to be poked must contain only atoms". I wasn't aware that any sequence contained anything other than atoms or the typeless things that atoms become when they participate in a sequence. > >>What if i want each char of s to land in the *same* memory addy? > >Make a loop. You'll be doing some processing in between each poke, right? > By the way, thanks for the acknowledgement, Brian. I'm only almost as stupid about the manual as Irv thinks I am . And thankyou, Irv, for the information. There is no clue to this in the definition to poke, though one might guess at it. This points out one area that the manual is desperately lacking in. There is no appendix of error messages. What would actually be nicer is a list of the most common error messages specific to a particular primitive, function, or procedure associated with the description thereof. That, along with a little more specifity in the actual definitions themselves and life would be quite a bit simpler. Everett L.(Rett) Williams rett at gvtc.com
8. Re: peek/poke
- Posted by Brian Broker <bkb at CNW.COM> Mar 27, 2000
- 586 views
- Last edited Mar 28, 2000
On Mon, 27 Mar 2000 17:54:29 -0500, Everett Williams wrote: >Since we both know that sequences are essentially infinite in structure and >length, what does happen when you poke s where s ={"xxx","yyy","zzz"}. >Yes I know it can be checked, but it is anything but clear from the manual >what would happen in this situation, much less more complicated ones. >The examples carefully shy away from anything complex, and the definition >does not rule them out. I'll pull out one of Knuth's most famous quotes >about a piece of code that he had sent to another person. "I've only >proven that it is correct, not tested it." Yes, we do have to try things, >but it would be nice if the manual gave us a few clues ahead of time. Personally, I prefer documentation that tells me what a routine CAN/WILL do, not a slew of info about what it CAN'T do (because, quite frankly, it would either confuse me or bore me). In the particular case of your example, I would assume that we should get an error (the procedure can be passed a sequence, not a sequence of sequences, or nested sequence, or whatever else you want to throw at it). The documentation 'shys away from anything complex' because it's not supposed to be complex. Would you rather see a list of examples that would be considered ERRORS? I know I wouldn't for the reason's mentioned above. I suppose that the documentation could be a bit more specific in this case: instead of just: If x is a sequence, write a sequence of byte values to consecutive memory locations starting at location a. add the following note: NOTE: Sequence to be poked must only contain atoms. (Which happens to be the error message you get if you try your example.) Simply put, in this case, it wouldn't even occur to me that I might be able to do what you suggested; it just doesn't make sense in the context of the procedure definition. Of course, people who want to think outside of the box will receive an error that points to the faulty line of code and a clear description of the problem with that code. ...poketest.exw:14 sequence to be poked must only contain atoms --> see ex.err where line 14 is: poke( a, {"xxx", "yyy", "zzz" } ) -- Brian
9. Re: peek/poke
- Posted by Brian Broker <bkb at CNW.COM> Mar 27, 2000
- 606 views
- Last edited Mar 28, 2000
On Mon, 27 Mar 2000 18:12:56 -0500, Everett Williams wrote: >Irv Mullins wrote: > >>You'll get an error message: "Sequence to be poked must contain only atoms". > > I wasn't aware that any sequence contained anything other than >atoms or the typeless things that atoms become when they participate in >a sequence. I think you should re-read the definitions of the atom, sequence, and object. In this case, I think you are confusing the atom and object (which is the typeless thing). From the refman: "All data objects in Euphoria are either atoms or sequences. An atom is a single numeric value. A sequence is a collection of numeric values. The objects contained in a sequence can be an arbitrary mix of atoms or sequences." By this definition, an atom cannot be a sequence, it can only be a single numeric value. -- Brian
10. Re: peek/poke
- Posted by Everett Williams <rett at GVTC.COM> Mar 27, 2000
- 606 views
- Last edited Mar 28, 2000
Brian Broker wrote: >On Mon, 27 Mar 2000 17:54:29 -0500, Everett Williams wrote: > >>Since we both know that sequences are essentially infinite in structure and >>length, what does happen when you poke s where s ={"xxx","yyy","zzz"}. >>Yes I know it can be checked, but it is anything but clear from the manual >>what would happen in this situation, much less more complicated ones. >>The examples carefully shy away from anything complex, and the definition >>does not rule them out. I'll pull out one of Knuth's most famous quotes >>about a piece of code that he had sent to another person. "I've only >>proven that it is correct, not tested it." Yes, we do have to try things, >>but it would be nice if the manual gave us a few clues ahead of time. > >Personally, I prefer documentation that tells me what a routine CAN/WILL >do, not a slew of info about what it CAN'T do (because, quite frankly, it >would either confuse me or bore me). In the particular case of your >example, I would assume that we should get an error (the procedure can be >passed a sequence, not a sequence of sequences, or nested sequence, or >whatever else you want to throw at it). The documentation 'shys away from >anything complex' because it's not supposed to be complex. Would you >rather see a list of examples that would be considered ERRORS? I know I >wouldn't for the reason's mentioned above. I suppose that the documentation >could be a bit more specific in this case: > >instead of just: >If x is a sequence, write a sequence of byte values to consecutive memory >locations starting at location a. > >add the following note: >NOTE: Sequence to be poked must only contain atoms. > >(Which happens to be the error message you get if you try your example.) > >Simply put, in this case, it wouldn't even occur to me that I might be able >to do what you suggested; it just doesn't make sense in the context of the >procedure definition. Of course, people who want to think outside of the >box will receive an error that points to the faulty line of code and a >clear description of the problem with that code. > >...poketest.exw:14 >sequence to be poked must only contain atoms >--> see ex.err > >where line 14 is: >poke( a, {"xxx", "yyy", "zzz" } ) > I knew how to test it, and my statement was that I should not have to, to learn the basic limits of the procedure. You may note that the original question about non-atom sequences was Kat's, not mine. I was attempting to answer her question by perusing the manual. Sometimes a definition is more easily closed by inclusion, sometimes easier by exclusion. Whichever way is simplest, is sufficient. Your solution was by inclusion for this procedure and it appeared to be complete. Others might need different techniques. The error routine suggestion was not mine, but ripped from dozens of manuals that I have seen that use that technique. As for an example of a poke of the form that you say makes no sense, what if I wanted to poke a series of lines from an editor contained as subsequences within a sequence. List items are another possibility. Since poke only takes one byte from each atom, it readily fits with the model for expression of strings in memory. Seems logical to me. Maybe you don't do things like that. Everett L.(Rett) Williams rett at gvtc.com
11. Re: peek/poke
- Posted by Brian Broker <bkb at CNW.COM> Mar 27, 2000
- 608 views
- Last edited Mar 28, 2000
On Mon, 27 Mar 2000 20:19:48 -0500, Everett Williams wrote: >As for an example of a poke of the form that you say makes no sense, I didn't say that it makes no sense.<--period! I said that it didn't make sense in the context of the procedure description. Let's break it down again: Poke let's you write one or more bytes into memory. A byte can only be represented by an atom. Poke let's you pass either an atom or a sequence. Since a byte can only be represented by an atom, it follows that your sequence must a sequence of atoms. Now that is how I think and that's why I said it doesn't make sense to pass a sequence of sequences. It just doesn't fit into the definition of the procedure. >what if I wanted to poke a series of lines from an editor contained as >subsequences within a sequence. List items are another possibility. >Since poke only takes one byte from each atom, it readily fits with the >model for expression of strings in memory. Seems logical to me. Maybe >you don't do things like that. Now that I've elaborated on the "it doesn't make sense" (that you ripped out of context), let's take a look at your case: seems like it would be a neat feature (one that would surely be documented if it was something that 'poke' could do). So why not write a function similar to 'allocate_string' (in machine.e) and modify it to suit your needs? It's a rather trivial solution (just make sure to null-terminate your strings). I'll leave it as an exercise for the reader to do this one. So I guess another point is: If it doesn't do what you want "out of the box" then take some initiative and make something that will do what you want. This is how many great libraries get started and this is how the language grows. -- Brian
12. Re: peek/poke
- Posted by Everett Williams <rett at GVTC.COM> Mar 27, 2000
- 597 views
- Last edited Mar 28, 2000
Brian Broker wrote: >On Mon, 27 Mar 2000 20:19:48 -0500, Everett Williams wrote: > >>As for an example of a poke of the form that you say makes no sense, > >I didn't say that it makes no sense.<--period! I said that it didn't make >sense in the context of the procedure description. Let's break it down >again: Poke let's you write one or more bytes into memory. A byte can only >be represented by an atom. Poke let's you pass either an atom or a >sequence. Since a byte can only be represented by an atom, it follows that >your sequence must a sequence of atoms. Now that is how I think and that's >why I said it doesn't make sense to pass a sequence of sequences. It just >doesn't fit into the definition of the procedure. I think that I said that you might have been able to guess that. My point was that you should not have to guess. Your suggested change to the documentation was entirely adequate and wouldn't have cost much. Another way to handle such things is to have an appendix with the formal definitions in it. They are needed and could save much fiddling. In the absence of your additional doc, one could think that sequences of sequences of atoms might work when the string form might not....though that runs against the definition that says those forms are equal. In any case, one has to get an error message before one really knows. >>what if I wanted to poke a series of lines from an editor contained as >>subsequences within a sequence. List items are another possibility. >>Since poke only takes one byte from each atom, it readily fits with the >>model for expression of strings in memory. Seems logical to me. Maybe >>you don't do things like that. > >Now that I've elaborated on the "it doesn't make sense" (that you ripped >out of context), let's take a look at your case: seems like it would be a >neat feature (one that would surely be documented if it was something >that 'poke' could do). So why not write a function similar >to 'allocate_string' (in machine.e) and modify it to suit your needs? It's >a rather trivial solution (just make sure to null-terminate your strings). >I'll leave it as an exercise for the reader to do this one. > >So I guess another point is: If it doesn't do what you want "out of the >box" then take some initiative and make something that will do what you >want. This is how many great libraries get started and this is how the >language grows. > Remember, this was Kat's request, not mine. I would only use peek and poke if I had to do it in Euphoria and couldn't find any other way. The method would be fairly trivial. Extract each second level sequence, poke it, and add the length to the location in memory. Her second request was a little more obscure, but I think I know the general heading. Writing bytes to an IO location and toggling the IRQ would be an IO technique for several types of IO. In some situations, no IRQ is necessary, polling is used, so you just have to wait for the byte to change, indicating it has been read. The IBM mainframes had a fantastic system level instruction for this purpose called compare and swap. Everett L.(Rett) Williams rett at gvtc.com
13. Re: peek/poke
- Posted by Kat <gertie at ZEBRA.NET> Mar 28, 2000
- 597 views
----- Original Message ----- From: "Everett Williams" <rett at GVTC.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Monday, March 27, 2000 9:16 PM Subject: Re: peek/poke > > > Remember, this was Kat's request, not mine. I would only use peek and > poke if I had to do it in Euphoria and couldn't find any other way. The > method would be fairly trivial. Extract each second level sequence, poke it, > and add the length to the location in memory. Her second request was > a little more obscure, but I think I know the general heading. Writing bytes > to an IO location and toggling the IRQ would be an IO technique for > several types of IO. Generally, that's one thing i had in mind, yes. But it was a question, to see if this was an undocumented function, or one anyone else had thought of, that's all. Kat