Pack?

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Pack?

Post 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 ;-)
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Locked