It's to change the endianess of an integer. It's quite common in all kinds of binary parsing code such as code accessing binary files, network protocols and so on. >>3
In Lisp you still have to write similar code, even if I usually just autogenerate the code, that way it can be reused regardless of the size and shape of the data.
The Lisp weenies are awful militant lately. Used to be a lot less Lisp vs. C, and almost never an unprovoked attack against C by a Lisper. Obv. trolling I guess. It's unbecoming though.
Name:
Anonymous2011-05-18 17:15
>>10
In Lisp I'll have no need for "(U32)(x)) & U32_CONST(" and I'll autogen swab_16 swab_32 swab_64, 128, 256,...
>>17
So get the fuck out we don't like you I hope you die of testicular cancer you're the reason Lisp is hated by the mass you cretin smug weenie I hope you'll get anally raped and get AIDS.
>>15
That name died out in the 1960's. You don't happen to be using PDP-10 machines do you? Do you currently refer to PC's as microcomputers? No? Then you don't use LISP until you return to 1960.
Name:
Anonymous2011-05-18 22:26
>>20 LISP (all caps in bold, preferable in Closter Black) makes the name stand for its own. Being a marketing move, it also shows timeless power and stability of this 50-year old language. The best of all: you cant do the same with your Python or Ruby. Too bad for you and your inferior lowercase languages.
COBOL (all caps in bold, preferabele Closter Black) makes the name stand for its own. Being a marketing move, it also shows timeless power and stability of this 50-year old language. The best of all: you cant do the same with your Python or Ruby. Too bad for you and your inferior lowercase languages.
>>10, 12
So, let's see some auto generated code, then.
Name:
Anonymous2011-05-19 9:29
>>28
If you insist. I didn't have any handy code which does actual byteswapping as the data was read in in the proper endianess in the first place without requiring further swapping, but as the task itself is easy, I wrote this code to illustrate how to implement such a thing:
;;; Utilities
(defmacro with-gensyms((&rest names) &body body)
`(let ,(loop for name in names collect `(,name (gensym ,(string name))))
,@body))
If this were not meant to be an example, some of those defmacro's would be written as macrolet's and the inner defun may be written as a compiler macro or as a macro (if support for old implementation which can't inline is to be considered), but the difference in the implementation is too small to be worth showing, so only this inlining version is shown.
Also to show some alternate uses of the same code. Let's say you don't have 8bit bytes, or you want to reverse a string of arbitrary bits, you can do it just as well using this:
CL-USER> (setf *print-base* 2 *print-radix* t)
T
CL-USER> (define-byte-swapper bswap8bits :byte-count 8 :byte-size 1)
BSWAP8BITS
CL-USER> (bswap8bits #b11001010)
#b1010011
It truly shows that you only have to write code once and use anywhere. The exception to this rule is when you can find a much better way to optimize a specific case and you need that speed.
Name:
Anonymous2011-05-19 9:49
The teams of more humble craftspeople I've worked with have been compellingly more productive. I find it a joy to hear "I'm not really that great a programmer, I was a History major -- but let me show you the way that we combined Visitor and Strategy in our last project, I really liked how it came out" ... and onto my whiteboard flows an elegant, terse work of beauty. I respond to the humility, to the shift from "I" to "we", and to the obvious appreciation for the abstraction itself.
>>29-30
For how much I love your clean coding style, your CL knowledge and your BBCode-Lisp-Beautifier, I must say that YHBT.
Name:
Anonymous2011-05-19 9:51
>>29
>(declaim (inline ,name))
AFAIK, SBCL does this automatically.
Name:
Anonymous2011-05-19 9:53
>>31
OK, I think we're violently agreeing here. One of the best programmers (as in useful to the organization) I've worked with recently was a convert from Human Resources, and fits the pattern you describe.