by codemac · 4y ago · 0 comments
(peopler-simplifier well people 2 are likely to like this better)
This is where generally macros & helper functions in lisp actually produce a new "syntax", rather than leverage a large language provided one.This to me is actually the crisis for lisp. Any codebase requires you to learn all the various macros that do:
peopler-simplifier == $1->$2[$3].$4($5, $6 $7 $8 $9);What is being discussed in this sub-thread is an oft-cited criticism of Lisp's "power" being too much for its own good, but rarely (if ever) a reflection of idiomatic practice.
Too much power for its own good is one thing, but being just not optimized for the common thing is another. How would the following function, randomly picked from what I have open on github right now, look in "Common" Lisp? And if I ask 3 persons to do it, what is the likelyhood that they would pick more-or-less the same approach?
Edit_Array buffer_batch_array_from_linked_list(Arena *arena, Batch_Edit *batch, i32 count){
Edit_Array result = {};
result.count = count;
result.vals = push_array(arena, Edit, count);
i32 counter = 0;
for (Batch_Edit *node = batch;
counter < count && node != 0;
node = node->next){
result.vals[counter] = node->edit;
counter += 1;
}
return(result);
} (defun buffer-batch-array-from-linked-list (arena batch count)
(let ((result (make-edit-array
:count count
:vals (push-array arena edit count))))
(loop :for counter :below count
:for node := batch :then (next node)
:for vals := (vals result)
:until (null node)
:do (setf (aref vals counter)
(edit node)))
result))
This is very typical Lisp code.Could you adorn this code with type declarations? Yes, and you'd get speed and/or safety benefits by doing so. Depends how much this function "matters" in the larger context.
Edit_Array buffer_batch_array_from_linked_list(Arena *arena, Batch_Edit *batch, i32 count)
{
Edit_Array result(arena, count); // Edit_Array has this thingy called a constructor
foreach (node in batch) // Batch_Edit * is somewhere/somehow declared iterable
{
if (result.full()) // Edit_Array has internal fill index, checked against count
break;
result.add(batch->edit); // Edit_Array has method to add and increment fill index.
}
return result; // not a function, drop the parens
}
The Edit_Array class in the original is of no help whatsoever. Like this coder or language aren't even up to abstract data types with Modula-2.It just uses names operators in prefix position. foo += 1 then is (incf foo). for (...) { ... } is then (loop for ... do ...). ...i32 counter = 0;... is then (let ((counter 0)) (declare (type i32 counter)) ...)
and so on...
(replace (make-array count) batch)After a while I realized it - I may have programmed in Common Lisp but never professionally... on a professional code base. Only ever on open source thingies, and small side projects. Paid or unpaid.
I've never seen industrial common lisp code. My last job had some but I never got to work on that project, and no longer can see it :(
Is there an example somewhere of this? C++ examples would be things like Chrome, C would be lots of open source OS's and kernel drivers. Is there something equivalent for CL?