212 points · by varjag · 1y ago · 61 comments
Common Lisp implementations like SBCL have static typing, performance, instant (and effortless) compilation to native machine code, and so on. No need to deal with Leiningen or copy-pasting a deps.edn / build.clj template across projects. If I want to experiment with SIMD intrinsics with the comfort of a REPL, I can't do that with Clojure, but I can do that with SBCL and a built-in library (SB-SIMD).
Note: I have used Clojure professionally and still use it for some personal projects, but I try to be aware of the trade-offs when deciding to use Clojure / Common Lisp / any other programming language.
Common Lisp is fun to code in, and the tooling is top-tier.
Besides, there's more to Lisp than Clojure.
Other known examples of Lisps are Emacs Lisp, Common Lisp and Scheme.
Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.
I am old enough to remeber the days any junior Assembly programmer could easily outperform any machine code generated by the C compilers of the day.
https://benchmarksgame-team.pages.debian.net/benchmarksgame/
...including Common Lisp.
A Java runtime... running on a Java runtime... Hmm, maybe not. But could be possible.
https://winworldpc.com/product/ibm-visualage-for-java/10
QUOTE: VisualAge for Java is based on an extended Smalltalk virtual machine which executes both Smalltalk and Java byte codes. Java natives were actually implemented in Smalltalk. Later versions were implemented on regular Java.
Obviously not the same....
> A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Joke aside, that is an amazing project.
example: we could have a `case` that works as follows and adheres to Scheme/Lisp style (using parentheses to clearly specify blocks):
(case name
(is_string? (print name))
(#t (print "error - name must be a string"))
)
OR we could also have a "convention" and treat test-conseq pairs implicitly, and save a few parentheses: (case name
is_string? (print name)
#t (print "error ...")
)
what do you think about this? obviously we can implement this as a macro, but I'm wondering why this style hasn't caught on in the Lisp community.Notice that I'm not saying we should use indentation—that part is just cosmetics. in the code block above, we simply parse case as an expression with a scrutinee followed by an even number of expressions.
Alternatively, one might use a "do" notation to avoid using (do/begin/prog ...) blocks and use a couple more parentheses:
(for my_list i do
(logic)
(more logic)
(yet more logic)
)
again, we simply look for a "do" keyword (can even say it should be ":do") and run every expression after it sequentially.See e.g. cond in clojure: https://clojuredocs.org/clojure.core/cond
Clojure also reduces parentheses by introducing more characters for various data-structures (good and bad, many would say), like [] for vectors, which are for example used for arguments when defining functions
(def add-five [a]
(+ a 5))So, in pseudocode:
(print (+ 1 2))
(exit 1)
becomes: print (1 + 2); // "+" is the 2nd place because it's a method call on "1"
exit 1;
Both variants are valid; semicolons are just syntactic sugar to reduce the number of parentheses. In the AST, they represent the exact same expressions.For function bodies, I also introduced an extension to make lambdas stand out more from the rest of the code by using curly braces:
(0 to 10) loop ^(i) {
print i; // Internally transformed to (print i)
}
// clarification:
// 1. The "to" method of the 0 object creates a Range object, which has a "loop" method that accepts a lambda.
// 2. The ^ symbol is just a shorthand for "lambda".
As you can see, this wasn't a Lisp dialect (and I'm no expert at Lisps), but I liked the idea of having a universal expression structure in the AST, however I eventually ended up extending it with two additional modifications that made it more readable (at least for me) (loop for i in my-list
do (logic)
(more logic)
(yet more logic))the parens are just a textual representation of a tree. once you have a proper editor, then the eliminated parens actually become an obstacle.
(typecase name
(String (print name))
(otherwise (print "error: name must be a string!")))
And if that Lisp had some kind of Object System, we may even go further and have stuff like... (defmethod namecall ((name String))
(print name))
(defmethod namecall ((name Number))
(print "I am not a number, I am a free man!"))There are a lot more hairy/pressing issues given how old the CL spec is (the type-system esp. comes to mind).