newLISP Fan Club

Forum => newLISP in the real world => Topic started by: newdep on April 25, 2008, 02:51:23 AM

Title: Pack?
Post by: newdep on April 25, 2008, 02:51:23 AM
Lutz.. What happens here?



..It looks like a coincidence to me..





>(set 'T ("one" " two " "  three"))

>(pack "%s5" T)



" two "



> (pack "%1s7" T)



"  three"





If its not a coincidence, then how do I get to "one" ?





PS: yes its a strange way of getting to a variable ;-)
Title:
Post by: Lutz on April 25, 2008, 03:23:07 AM
This is just pure coincidence of a wrong format string in your 'pack'.



This is the correct way to pack lists into an array of string pointers:


>
> (set 'T '("one" " two " " three"))
("one" " two " " three")
> (set 'adr (pack "lululu" T))
"16b1600 b16000b1600"
> (map get-string (unpack "lululu" adr))
("one" " two " " three")
>


There is also a similar example about this in the manual: http://www.newlisp.org/downloads/newlisp_manual.html#pack



And a pattern in the second to last table here: http://www.newlisp.org/CodePatterns.html#extending