162 points · by phabian · 11y ago · 100 comments
One difficulty with promoting a more modern layer to common lisp is that Clojure is already such a productive and practical language. I have written a few common lisp books, and remain a fan of the language, and an upgrade does sound good.
I am curious to hear the opinions of the heavy hitters in the common lisp world.
A bit of a tangent, but I've been looking at the series library[0] recently. It makes it possible to write functional style code which is compiled into a loop for efficiency. For example:
(defun integers ()
"Returns a series of all of the integers."
(declare (optimizable-series-function))
(scan-range :from 1))
(defun squares ()
"Returns a series of all of the square numbers."
(declare (optimizable-series-function))
(map-fn t
(lambda (x) (* x x))
(integers)))
(defun sum-squares (n)
"Returns the sum of the first N square numbers."
(collect-sum (subseries (squares) 0 k)))
Although the above definition of sum-squares seems like it would be inefficient, it is roughly the same as the following: (defun sum-squares (n)
"Returns the sum of the first N square numbers."
(loop for i from 1 to n
for square = (* i i)
sum square))
I find it pretty awesome that it is possible to write code that is efficient and functional like that, but I guess series is a bit too magical to be put to actual use. * (disassemble #'(lambda () (loop for i from 1 upto 10 summing i)))
; disassembly for (LAMBDA ())
; Size: 62 bytes. Origin: #x100306FE84
; 84: BB02000000 MOV EBX, 2 ; no-arg-parsing entry point
; 89: 31C9 XOR ECX, ECX
; 8B: EB21 JMP L1
; 8D: 0F1F00 NOP
; 90: L0: 48895DF8 MOV [RBP-8], RBX
; 94: 488BD1 MOV RDX, RCX
; 97: 488BFB MOV RDI, RBX
; 9A: 41BBA0010020 MOV R11D, 536871328 ; GENERIC-+
; A0: 41FFD3 CALL R11
; A3: 488BCA MOV RCX, RDX
; A6: 488B5DF8 MOV RBX, [RBP-8]
; AA: 4883C302 ADD RBX, 2
; AE: L1: 4883FB14 CMP RBX, 20
; B2: 7EDC JLE L0
; B4: 488BD1 MOV RDX, RCX
; B7: 488BE5 MOV RSP, RBP
; BA: F8 CLC
; BB: 5D POP RBP
; BC: C3 RET
; BD: CC0A BREAK 10 ; error trap
; BF: 02 BYTE #X02
; C0: 19 BYTE #X19 ; INVALID-ARG-COUNT-ERROR
; C1: 9A BYTE #X9A ; RCX
Keep in mind that's with full run-time type checking and other nice debugging features. You can hint the compiler to turn these things off in your hardened code sections for even smaller, tighter code.In this case, theirs isn't the opinion that counts.
Take princ #"Hello, ${name}\n". Why not just use print like the rest of the programming world. Okay, some languages use writeln, etc. But princ? Why not print?
A little further down, we see while-let1. Why the number? If you want to call it "Common Lisp in the 21st Century" you need to clean up the syntax.
My 1.5cents
I don't mean that I don't understand it. I even know they come from assembler instruction names. And they still look weird to me and still have no meaning despite having read what the abbreviation expands to three or four times.
You'd be far better off shipping "first" & "rest" and whispering to the old hands that you're sure they know how to "fix" the problem in their code, than presenting new people with car & cdr and then try to wedge an explanation into a brain that just threw an exception and went "Wait, what?"
I like the distinction of car/cdr meaning pointers vs first/rest meaning "start of list/rest of list".
It weirded me out at first, but I came to really appreciate it.
- both 3 letters each
- only differ by 1 letter a|d
None of the alternatives have these symmetry, and it (very subjectively) shows in the code.As funny as it is, people whining about "car/cdr" and saying "language X did it better because it called them first/last, or head/tail" don't realize that it's the language X that lacks semantics to express anything else than lists using cons cells.
If I were doing this I'd also get rid of the * around the hash keyword and either just go with the keyword 'hash' or replace it all together with an operator.
It's almost like lispers want the opposite of java, long verbose keywords and syntax and then as short as possible variable names.
Why not switch the parens to something that's a single keystroke? Why not get rid of the parens in most cases? In some cases this seems to make the parens problem with lisp even worse?
(loop for key being each hash-key of *hash*
using (hash-value val)
when (< (length key) 2)
do (format t "~A~%" val))
with 5 sets of parens turns into (doeach ((key val) *hash*)
(when (< (length key) 2)
(princ #"${x}\n")))
six setsthe former also required fewer shift-character keystroke combinations
( ) * < " ~ %
while the new syntax ends up with ( ) * < # " $ { }
this feels like my hands are wrestling, not typingthis just seems to be moving things around, not really improving anything
I'm not a lisper, so somebody correct me if I'm wrong
(Edit: trying to escape HN formatting conventions.)
Many a well-intentioned Lisper eventually begins to see deficiencies where there are none and attempts to improve their implementation of choice. Common Lisp is one such target because people coming from in-vogue languages are used to the language changing every year or two. Invariably this leads to superficial changes at best which are enabled, surprise of surprises, by Common Lisp because it was designed to be extensible.
My theory is that if your language of choice needs to change its grammar rules to introduce new features you're basically admitting that you should have added macros programmatic access to the reader.
> It's almost like lispers want the opposite of java, long verbose keywords and syntax and then as short as possible variable names.
Well syntax is at a minimum in Common Lisp. It tends to avoid syntactical short-hand. The most common I know of being QUOTE, BACKQUOTE, UNQUOTE, UNQUOTE-SPLICE, and FUNCTION: ' ` , ,@ and #' respectively.
If you read the preface to the first edition of Structure and Interpretation of Computer Programs I think you will find an enlightening explanation of, Why Lisp?. To paraphrase a brief summary: there are very few ways to form compound expressions and hardly any syntax at all so that the programmer can get to the problem at hand within an hour: the language disappears.
The longer names are chosen stylistically based on the maxim that computer programs are meant for humans to read and only incidentally to be executed by a computer.
Lisps are not, contrary to popular mythology, list-processing languages. It's a symbolic language. The relationship between symbol and data allows the programmer to think primarily about the transformations to data without the abstractions becoming weak.
> Why not switch the parens to something that's a single keystroke?
You could. Common Lisp gives you access to the reader. You can write a more fitting syntax you are more comfortable with.
I've written reader macros to parse assembler instructions for an emulator I wrote in Common Lisp.
> this just seems to be moving things around, not really improving anything
That's my impression too. These sorts of experiments are worth trying from time to time in order to see if something can come from them. Maybe something will come out of this.
But ultimately people bike-shed over "car/cdr" and specialized functions for specific data-types (ie: AREF, GET-HASH, etc). You can write higher-order functions to abstract away sequence access and iteration if you want: people have and there are good libraries for it.
The standard hasn't changed AFAIK because:
1. It'd be expensive and nobody wants to fund another ANSI committee.
2. There haven't been any significant proposals the necessitate revisiting the specification.
People complain about the lack of run-time support for concurrency and IO in the specification. I don't think they realize, coming from other languages, that Common Lisp doesn't need it. The specification defines the language and a minimal ball of mud for doing practical work with it. Things like concurrency, threading, and IO are implementation issues and have been solved by high-quality open-source implementations for quite some time. We even have good libraries that provide a cross-platform layer to things like threading.
In that case, it would be useful to newcomers to introduce those facilities into the core of the language. The more batteries are included, the easier language adoption becomes.
> But ultimately people bike-shed over "car/cdr" and specialized functions for specific data-types (ie: AREF, GET-HASH, etc). You can write higher-order functions to abstract away sequence access and iteration if you want: people have and there are good libraries for it.
To me, this is not bike shedding, but user experience design. The more learning that is required to accomplish a given goal the first time, the less productive and more difficult that goal becomes. "car" and "cdr" are not intuitive to me. Why not use "first" and "rest" or "head" and "tail" for CL21 instead?
http://www.lispworks.com/documentation/lw61/CLHS/Body/f_wr_p...
There's usually a very good reason behind all those "unusual names" of Common Lisp. I don't think that dumbing things up so that they look more similar to everything else in a language that is already different from anything else is the way to go.
I really like the direction of this project, but I agree with the parent comment, it doesn't go far enough.
Consequently, just because a language seems superficially familiar, that doesn't make it easy to learn - for programming languages it takes weeks to understand the basic necessities, whereas it takes years to become a master, regardless of the programming language you're talking about.
Also, Erlang's Prolog-like syntax sucks, not because it's unfamiliar, but because it objectively sucks.
From this and the author's name (Eitaro Fukamachi), I wonder if he is not a native English speaker.
This could shed light on differences in aesthetic choices about function names. Difference between "princ" and "print", or awkwardness of "while-let1" may not resonate as much for a non-native speaker.
And no, I do not miss reader macros. Perhaps more surprisingly, I don't miss CLOS at all, much as I always admired its design. It's just... Unnecessary.
What I do enjoy is STM, good performance, Java interop, ClojureScript, core.async and lots of excellent code with fresh ideas popping up all over the landscape.
When I was working with it on a non-trivial project I despised the JVM stack traces, image-less environment, and lack of access to the reader. I assume that eventually Clojure will steal these ideas and adopt it in its own way... but these old, un-modern ideas of conditions and restarts, images, and reader macros are actually really useful. I hope they do take a hint.
For many, Clojure may be a better choice as you suggest: perhaps especially for web projects. But I think for some groups and applications, CL remains a better choice.
Some of them could possible be considered for alexandria https://common-lisp.net/project/alexandria/. Admittedly I am not sure how alive development is but it certainly would be worth breathing new life into as it is probably the most heavily used CL library.
As things like STM and lazy which Clojure has, they have been implemented at the library level for CL.
https://common-lisp.net/project/cl-stm/
The beauty about a Lisp is that you can easily add so much on top of the language that will feel as if it was always there. CLOS is a good example of this.
In the case of JVM with CLojure, and of course others will disagree, I don't think accessing the Java ecosystem is a good thing. The mindset there is monolith "Enterprise Solutions" "Inversion of Control frameworks" which invariable mean systems that are so complex the authors don't even understand them and lets write XML above all else.
Also if you want CL->Javascript; Parenscript.
https://common-lisp.net/project/iterate/
In my personal opinion, the iterate loops read better than the code samples of the main page.
1. It has CLOS but it doesn't really embrace it in standard library. You have list, vector, hash-table, each with its own iterator function. You have lots of #with-xxx macro. All modern languages utilize the idea of common interface like #iterator or #dispoable. You can clearly see CLOS library and pre-CLOS library in CL. CL needs to eat its own dog food (CLOS) more.
2. It lacks basic practical API library, while another containing big complicate academic functions. Its #format function is probably Turing complete. It has function to format number in Roman numeral. But it doesn't have function to deal with datetime. No networking IO function. No Threading library.
3. Condition and Restart could take the idea from Dylan. Tying condition to available restarts, and making class hierarchy of them, is a better idea. This problem stems from CL not actually utilizing CLOS.
Also, PACKAGE should take the idea of LOCALE, allowing easier local package rename, and less symbol conflicts problem.
One of my main gripes with Common Lisp is its complexity. When I started learning Lisp, I expected to find a beautiful and elegant language, one without a need for syntax. The way C is almost an elegant assembly. Maybe I should have tried Scheme instead.
Common Lisp is anything but elegant. Instead of a regular syntax, you get all these "mini-languages", like the format syntax e.g.
(format t "~{~a~^, ~}" '(1 2 3))
; prints out
; 1, 2, 3
This works fine for list, but not for vectors, which is a problem, since I needed vectors often (for random access).The loop macro is also quite powerful and complicated. e.g.
(loop :for i :from 1 :to 1000 :collect (* i i))
will create a list of square of 1 to 1000. The loop macro can become really convoluted, not at all simple.The fact that Common Lisp is a Lisp-2 makes treating functions as first-class as rather awkward. I could never remember when I needed to prepend a lambda with #'.
This article may be of interest http://xahlee.info/comp/Common_Lisp_quotations.html
I found much of the elegance I was expecting in Haskell. But maybe Scheme is a better lisp.
Also, Java/JVM suck ass, why would anyone willingly work with that whole mess?