Re: Printed representation of (char 0) ?
On Tue 13 Feb 2024 at 08:35, Thorsten Jolitz wrote: > But shouldn't hex 23232424 print to something like ##^N^N$$ > instead of no ^N could mean SO character with byte value 14 see the program ascii a NUL character would be displayed as ^@ > So the printed ASCII string (as char) carries all the information from the > hex string, and can be converted back to the exact same hex string? no, you are using wrong tool for the job as Alex said, a picolisp string cannot contain NUL byte > At least in some special cases when it's needed? arbitrary binary data is not a string parse the binary data properly -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Printed representation of (char 0) ?
Hi Thorsten, > But shouldn't hex 23232424 print to something like ##^N^N$$ instead of > ##$$ ? The problem is that you try to handle binary data as symbols. This is not a good idea. Binary data are numbers. First of all, do you really have a hex message? Where does it come from? Normally I would expect a list of numbers as obtained with e.g. (make (do 96 (link (rd 1 If it is really a hexadecimal string, you can obtain the list of numbers with : (make (for (L (chop "23232424") (cut 2 'L)) (link (hex @ -> (35 35 0 0 36 36) ☺/ A!ex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Printed representation of (char 0) ?
Hi Alex, Thomas, thanks for your input, this is actually what I was looking for : [image: image.png] or even better: [image: image.png] I wonder if there actually is a way to directly print ^@ in PicoLisp for a "non-printable" hex "00", instead of NIL? Wrt the application, I just have to deal with fixed length hex strings (!) where the values at certain offsets carry semantics, conversions are done, and it's crucial that values stay in that position, the NUL values matter. And I don't want to write a PicoLisp application for this, I just wanted an easy way to produce the expected conversion result in PicoLisp as a reference for comparison, and the above solution is fine for that. Am Di., 13. Feb. 2024 um 09:09 Uhr schrieb Alexander Burger < picolisp@software-lab.de>: > Hi Thorsten, > > > But shouldn't hex 23232424 print to something like ##^N^N$$ instead > of > > ##$$ ? > > The problem is that you try to handle binary data as symbols. This is not > a good > idea. Binary data are numbers. > > First of all, do you really have a hex message? Where does > it come from? Normally I would expect a list of numbers > as obtained with e.g. > >(make (do 96 (link (rd 1 > > If it is really a hexadecimal string, you can obtain the list > of numbers with > >: (make (for (L (chop "23232424") (cut 2 'L)) (link (hex @ >-> (35 35 0 0 36 36) > > ☺/ A!ex > > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >
Re: Printed representation of (char 0) ?
Hi Thorsten, I agree with the others, that's not a string you are processing. Strictly speaking, PicoLisp text functions and PicoLisp strings (and symbol names) must not contain NULL character. How about processing this fixed-size values in binary, using (rd 'cnt) and (wr 'cnt) ? Important: The alternative argument of (rd) makes it work very differently, the default behavior with 'sym argument is for PLIO (the picolisp binary format). It's also usually a bad idea to mix binary and text processing when working with the same input channel, unless you really know about how picolisp text procressing works (the character buffering, with a character potentially being 1-4 bytes), so careful with that. Greetings, beneroth On 13.02.24 20:30, Thorsten Jolitz wrote: Hi Alex, Thomas, thanks for your input, this is actually what I was looking for : image.png or even better: image.png I wonder if there actually is a way to directly print ^@ in PicoLisp for a "non-printable" hex "00", instead of NIL? Wrt the application, I just have to deal with fixed length hex strings (!) where the values at certain offsets carry semantics, conversions are done, and it's crucial that values stay in that position, the NUL values matter. And I don't want to write a PicoLisp application for this, I just wanted an easy way to produce the expected conversion result in PicoLisp as a reference for comparison, and the above solution is fine for that. Am Di., 13. Feb. 2024 um 09:09 Uhr schrieb Alexander Burger : Hi Thorsten, > But shouldn't hex 23232424 print to something like ##^N^N$$ instead of > ##$$ ? The problem is that you try to handle binary data as symbols. This is not a good idea. Binary data are numbers. First of all, do you really have a hex message? Where does it come from? Normally I would expect a list of numbers as obtained with e.g. (make (do 96 (link (rd 1 If it is really a hexadecimal string, you can obtain the list of numbers with : (make (for (L (chop "23232424") (cut 2 'L)) (link (hex @ -> (35 35 0 0 36 36) ☺/ A!ex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Printed representation of (char 0) ?
Hi Thorsten, > I wonder if there actually is a way to directly print ^@ in PicoLisp for a > "non-printable" hex "00", instead of NIL? As we see from the previous discussion, this is not an issue of printability. Other control characters may also be non-printable. It is an issue of binary data vs. symbol names. But you can of course print a caret and an at-mark instead of NIL (prin (or (something) "\^@")) > Wrt the application, I just have to deal with fixed length hex strings (!) > where the values at certain offsets carry semantics, conversions are done, > and it's crucial that values stay in that position, the NUL values matter. Yes, but why do you need to convert it to a string? I would process these data all exclusively as a list of numbers, and do the final printing explicitly (if needed at all). This printing may print '0' as "\^@", and also take care of other control characters and non-printable stuff. ☺/ A!ex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe