JamesF wrote:Dude, if you think that's painful, wait 'til you look at the generalised machinery for handling filepaths. It was standardised at a time when there were Unix, DOS, VMS with its built-in file-versioning, other exotic systems floating about, and more being developed. Try handling that in a portable way that's both simple and elegant.
Yep, i've also tripped on that one.
JamesF wrote:
What I think you've just run into is the fact that CL spans the entire gamut from low-level bit-twiddling to high-level metaprogramming. There's a bit of overhead in exchange for the flexibility and scalability. It's also worth remembering that CL has a different imperative to, say, Python: it's for writing big, complex systems whose specs keep changing; beginner-friendliness just isn't a concern. This means that you're in for a hell of a learning curve but, once you've climbed it, the stuff of which awesome is made is at your command. This is also why it's hard to give a simple answer to the periodic question "so what do macros really buy you?" - like ramjets, they just don't make sense at the kind of scale that fits in a forum or mailing-list post.
To address your actual question: although I've not yet had cause to do this kind of thing myself, I'm pretty sure you can just open a file for writing, carefully make sure it's set up for the right kind of encoding, then fling bytes at it with abandon.
So far its kind of frustrating it offers support for things that *dont* exist, and stuff as basic as binary output require you roll a frigging type system on top of the other one.
I got answered very politely on #lisp that what i was looking for was kind of complicated, but that, the functionality was already implemented in libraries like:
http://www.cl-user.net/asp/libs/binary-types
The implementation of binary parsing in practical common lisp chapter 24
Wow, again.
Lets see. In any other language I would be called a fucking retard for doing bulk IO byte by byte.But not in CL.
Apparently here its the only option,THAT, or rolling your own damn type system, but HEY! don't worry! you might say.
CL meta-programming capabilities sure can extend the language in the way you want... syntactically.
You dont have acess to memory ofc so lets use arrays for that!
But now... wait you cant use the data you just read, you need to play with it , a 32bit integer needs to be summed up to translate from 4byte array to
WHATEVER-BIT BENT OVER BACKWARDS your implementation happens to be using.
Fine, Fine , now that we operated with it lets just write it back OOOOOPPPPS we have to turn it back into a non-autistic format so the rest of the motherfucking world understands that is a 32 bit integer.
As i said doing anything similar in any other language would get me flamed but on lisp ITS FINE!
Whats the matter with efficiency? its FAST ENOUGH!
It's like shaving with a damn bowling pin, it might work if you try hard enough , but that doesn't make it the right way to shave nor the most efficient.
After all it frigging compiles to native code RIGHT?
Never mind that you got to be constantly converting out and into the autistic I'm-special-no1-understands-me bit representation right?
But its fine, apparently, after all when the fucking lisp machines come back CL will be prepared and ready, and wont have to play nice with absolutely fucking anything anymore right?
Warren Wilkinson wrote:I just slurp the file into memory and access it with pointers. Something like this (in SBCL):
Code: Select all
(let ((data (read-sequence ...)))
(sb-ext:with-pinned-objects (data)
(let ((sap (sb-sys:vector-sap data)))
(sb-sys:sap-ref-32 sap 0)))) ;; First word.
Files suck in every language, I've always found it easiest to define the data structures as methods to access raw memory. And then serialization is just streaming the raw bits to disk.
That is SBCL dependant.
i know you could do that,whats more , so far when i looked at retarded topics like sockets and this the only sanity came from implementation dependant api.
YET i find it ABSURD that the standard includes completely unnecessary bullshit like dunno, format printing numbers in English or roman notation ,path objects for decades extinct and yet to be invented filesystems, an object system that would make Java cry in a corner...
But no standard way to do IO.
The rage comes from the fact that i was so excited, CL was so great with all that powerful features...
I mean, if you are going to do whatever autistic fuck-you-all-im-special representation in memory, THE LEAST a language should do is provide a STANDARD way to interact with every one else.
BUT NO
Guess what? if people considered its fine to implement every commonly used feature yourself,it woudnt matter as long as the language is turing complete.
Oh ok, ill just go roll my own CLOS on to of BRAINFUCK...
Right now it is SO much more attractive to use the damn FFI and use the SANE clib posix interface, than rollling my fucking own typesystem on top of CL.
Remember that quote that said
"Every sufficiently complicated C program includes an incomplete, bug-ridden implementation of half of Common Lisp?"
Corollary:
"Every sufficiently complicated Common Lisp application includes a slow-as-fuck ,redundant and dependency-ridden implementation of half of POSIX"
The more I look into it the more I see libraries dont really do shit and are mostly FFI wrappers or just portability layers on top of the retarded, balkanized implementation specific API's.
Or give CL up altogether.
I dont know who to blame for it, design by committee, old age... whatever.The only thing im certain its that sane definitely doesnt describe CL.
So, there is not even a pack
http://docs.python.org/library/struct.html
or similar facility in the standard?