packprocedure (or macro). That's simply because I wrote specific procedures to handle binary packing each time. However it's better to have generic one.
Then I need to consider its interface. I was thinking something similar with Industrial's pack however I have re-read this tweet (it's in Japanese):
Sagittarius scheme には pack ないのか。 サイズが一定ならバイトベクタを確保して並べるのも手間っていう程ではないのだが、不定長になると一気に面倒くさくなるんだよなぁ。
— (32) 齊藤敦志さん (@SaitoAtsushi) 1月 22, 2013
Does it handle indefinte size?
I actually have 2 problems to implement: Firstly, I'm not good with
packstuff. Even when I was still using Perl,
packis only for hex to ascii or other way around (you can easily guess what is for :-) ). Secondly, if we support indefinate length, what would be the better solution?
The first thing, I just need to learn so it just takes fine time. The second one, I don't have much use cases so all what I can is guessing. There are, I think, 2 ways to implement indefinate length. One is like Perl way using some keyword inside of the format string (
+?). The other one is providing a procedure to pre-compute the given data and generate format string. So it must be like this;
;; #\C is u8 (let ((fmt (generate-format-string #\C indefinite-bv))) (pack fmt indefinte-bv)) #| Let's say indefinite-bv has 8 bytes then format string would be "CCCCCCCC". Or if we use #\L as a bace character then format string would be "LL" |#The problem of this is that we can't optimise it in macro. So it always needs to be computed in runtime. I don't think this will be a big problem, though.
Ah, wait, format string can have indefinite marker if I check it macro expansion time. Hmm, which way is better?