2 ms·
> It's considerable boilerplate No, it's not boilerplate, it's actually functional. Type declarations in Lisp are optional (because they are there only to imp
by lisper 7y ago
> It's considerable boilerplate
No, it's not boilerplate, it's actually functional. Type declarations in Lisp are optional (because they are there only to improve performance, not to change the semantics of the code).
> > Is that what you want to see, a cleaner syntax for type declarations?
> Of course, that's what I wanna see. Haven't seen it yet.
OK, here is one possibility:
(deftype u8 () '(unsigned-byte 8))
(deftype u32 () '(unsigned-byte 32))
(deftype array-of (type &optional size) `(simple-array ,type ,(or size '(*))))
(defmacro c-defun (name args &body body)
`(defun ,name ,(loop for (var) on args by #'cddr collect var)
(declare ,@(loop for (var type) on args by #'cddr collect `(type ,type ,var))
(optimize (speed 3) (debug 0) (space 0) (safety 0)))
,@body))
(defmacro c-let (vars &body body)
`(let ,(loop for (var nil val) in vars collect (list var val))
(declare ,@(loop for (var type) in vars collect `(type ,type ,var)))
,@body))
Now you can write:
(c-defun update-crc32-checksum (crc u32 buffer (array-of u8) end fixnum)
(c-let ((cur u32 (logxor crc #xffffffff))
(table (array-of u32 256) (get-crc-table)))
(dotimes (i end)
(c-let ((index u8 (logand #xff (logxor cur (aref buffer i)))))
(setq cur (logxor (aref table index) (ash cur -8)))))
(logxor cur #xffffffff)))
Better?
> Show me and tell me all the reasons why that's not worse than just writing it in C.
I didn't say it was better to write this code in Lisp. I said it was easier to make this kind of change in Lisp if you want to.
- jstimpfle 7y ago> Better? I can empathize with your enthusiasm that you can improve the situation a little on the surface, which feels like an achievement, but frankly, I think the code still sucks a lot... There's no way I could sustain writing the kind of code I like to write in this fashion. From an engineering standpoint, using this was probably a poor choice (again, think error messages, tooling, mindshare...) The metaprogramming code looks ugly and brittle to me, although I'm not in a position to judge.
- lisper 7y ago> I think the code still sucks a lot.. Why? How would you want it to be different?
- jstimpfle 7y agoI've already written so much and don't want to repeat myself anymore. Certainly the use of a macro that transforms basically all of the code must be one of the biggest problems, because it makes communication between compiler and programmer extremely hard (tooling, error messages, ...). Besides that, there is still considerable overhead compared to the C version (which was written once here, never changed, and is still effortlessly the clearest version), and I miss some punctuation (not just parens) to be able to make sure everything is closed correctly, indented correctly, etc. Having to manually space out variables and types as pairs is also bad ergonomics. And I miss some operators (assignment, subscripting, distinct function call syntax) that give visual cues that allow the skimmer to quickly find what happens in a function. Fun story: Larry Wall once said, Lisp looks like oatmeal with finger clippings mixed in. I can't disagree, and it's a serious problem for ergonomics.