Pack or comPack
Pack or comPack
Hi Lutz,
I was wondering why the pack function has the behaviour of seperated spaces between the "str-format" and not a Perlish compact way ?
Building dynamic binary data currently needs extra spaces inside pack..
(pack "c c c s5" 1 2 3 "hello")
could be like (but less readable, like Perl..)
(pack "cccs5" 1 2 3 "hello")
Any idea if its an option to make it compact?
(Its not a real big deal actualy but in most pack circumstances more handier)
Regards,
Norman.
I was wondering why the pack function has the behaviour of seperated spaces between the "str-format" and not a Perlish compact way ?
Building dynamic binary data currently needs extra spaces inside pack..
(pack "c c c s5" 1 2 3 "hello")
could be like (but less readable, like Perl..)
(pack "cccs5" 1 2 3 "hello")
Any idea if its an option to make it compact?
(Its not a real big deal actualy but in most pack circumstances more handier)
Regards,
Norman.
-- (define? (Cornflakes))
I'm sure somebody can wrap the following into a macro.(pack (comPack "cccs5") 1 2 3 "hello")
Code: Select all
(define (comPack str)
(map (fn (x y) (replace x str y))
'("c" "s" "ld" "lu" "u" "d" "f" "n" "LU" "LD")
'(" c" " s" " LD" " LU" " u" " d" " f" " n" "lu" "ld"))
(slice str 1))
Here's a macro that seems to work:and is called like this:
Code: Select all
(define-macro (compack str)
(define (aux str)
(map (fn (x y) (replace x str y))
'("c" "s" "ld" "lu" "u" "d" "f" "n" "LU" "LD")
'(" c" " s" " LD" " LU" " u" " d" " f" " n" "lu" "ld"))
(slice str 1))
(apply pack (cons (aux str) (rest (args)))) )
Code: Select all
> (compack "cccs5" 1 2 3 "hello")
"\001\002\003hello"