Page 1 of 1

Pack?

Posted: Fri Apr 25, 2008 9:51 am
by newdep
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 ;-)

Posted: Fri Apr 25, 2008 10:23 am
by Lutz
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:

Code: Select all

>
> (set 'T '("one" " two " " three"))
("one" " two " " three")
> (set 'adr (pack "lululu" T))
"\016b\016\000 b\016\0000b\016\000"
> (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/newlis ... .html#pack

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