Keith Thompson <kst-> wrote:
> Jorgen Grahn <grahn+> writes:
> [...]
>> Didn't read very carefully, but it's like the Python 'struct' module,
>> isn't it?
>>
>> http://docs.python.org/library/struct.html
>
> It's also reminiscent of Perl's built-in "pack" and "unpack" functions.
> http://perldoc.perl.org/functions/pack.html
> http://perldoc.perl.org/functions/unpack.html
Thanks, Keith (and Jorgen again), that's also incredibly useful.
Lots of food for thought to spec out a C variant. And yet another
format/template to peruse. I really should put some effort into
learning these "little languages".
Despite BartC's remark, "The main problem Python has to deal
with is that the language doesn't have structs", I think this
kind of pack function has valuable uses in C (along with a
scan-like unpack, as suggested by BartC's other remark),
e.g., formatting (and reading) binary blocks/packets/whatever,
which is what brought the idea to my mind. And the fact that
all these little languages have pack/unpack just supports
the notion they're useful funcs. Moreover, I'm sure you can
see they're no great big deal to code. So why not do it
(I'm in the process, but that's no reason others shouldn't
do it differently/better/whatever)? The naysayers can just
ignore it. I'm sure everybody has their favorite C feature
they choose not to use.
Finally, regarding Ian's remarks, pack/unpack would be
a >>lightweight<< alternative to accomplish this kind of
task. Ian's way involves importing additional tool dependencies,
possibly turning what could be just a few lines of code
into a subtask unto itself. For his large project case,
involving lots and lots of different block formats,
that may be the best approach (I've worked with Swift
at Bankers Trust, albeit a while back, and also with various
ticker feeds, etc, etc, and more etc). But that's no reason
not to have a lightweight alternative.
--
John Forkosh ( mailto:
where j=john and f=forkosh )