264 points · by macco · 9y ago · 199 comments
The more I use Common Lisp, the more disappointed I am that it hasn't become more popular. It really is higher level than Python, Ruby, or Perl but with nearly the performance of C and C++.
It's nice to hear that I'm the only one. I, not too long ago, picked up Common Lisp and after a bit of "getting it", it suddenly became one of my favourite languages. And by "getting it", I'm not talking about the difficulties people normally refer to when talking about learning lisps, it was learning how to develop with it.
There's a huge productivity boost in just the fact that your development process is as follows: boot REPL, run your program and then modify your program (while running). If anything is to break, or hasn't been implemented, the debugger just stops your program, let's you inspect your program state freely and you can update the code that failed and have another go.
I'm normally very much to the strong, static typing side of languages. But to me, the Common Lisp experience is dynamic done right, it gives all the tools to handle the problems that arise from a dynamically typed language (even though Common Lisp is actually partially strongly typed) with is a great boon to productivity.
Those are some examples off the top of my head, but the general point is that unlike mainstream languages, Lisp languages evolved into environment for interactive construction and modification on a continuously running program, which is a bit different way of working than the regular write-compile-run cycle.
To me the thing that CL has that has yet to be matched by any other languages, REPL-based or not, static or not, is the amazing condition system and dynamic restarts for handling problems. For building and debugging systems this is an utterly amazing thing. It also allows composing exceptional conditions in a reasonable way.
Every other language I use (e.g., Clojure these days a lot) I constantly miss this amazing stack-walking ability and conditional restarts.
Every time I boot my old Symbolics computers and something happens and I get a GUI restart, I'm just amazed at what we have lost through two decades of non-CL living.
Or to put it another way, trace is an option that is passed to the Python interpreter. In Common Lisp (trace ...) is a function that can be called in the REPL.
Python really has a glorified edit-compile-run cycle. The interpreter loop is nice for quick tests or calculations, but isn't too helpful for the incremental development of your program.
It also supports writing condition handlers that can do all of the above under program control, rather than under human control. In other languages you would say "exception handlers", but Common Lisp conditions include representations of situations and responses that exceptions typically don't.
These facilities, along with things like a debugger, a tracer, support for built-in documentation, a compiler, and a disassembler, are part of the language standard, not the development environment.
Common Lisp is a language designed from the ground up for writing programs by interacting with them as they run. There aren't very many other languages like that. Smalltalk is one of them.
* Python REPL does not check and warn the trivial type/arguments errors when a function is defined. It is only after the program reaches that erroneous line that an error is signaled. SBCL always warns about the function signature. Perhaps this may be customized by some global variable or a command line option, but not being warned by default is a huge waste of time, as it takes non-negligible amount of time to reach there (specifically because it is a ML task). (SBCL also warns me about type errors in most of the standard functions as well as ftype'd functions.)
* Python does not have restarts. I mean the condition system in Common Lisp. This again imposes a significant amount of slowdown on the debugging cycle as an error may be signaled only after a multi-hundreds-MB data file is loaded in the beginning of a function and then the erroneous line of code is run. In CL, when an error is signaled, the program enters the debugger and halts there, during which you can correct the program, redefine the function, then resume the code from one or two stacks above the current. In python an error always rewind the stack to the toplevel, so you have to rerun the whole function, loading that huge data file again in the middle of the stack. Don't say you are afraid of some side effects in the code, I follow "Mostly Functional Style" in CL.
* Python debugger shows the stack frame, but does not by default show the values of the arguments in the function call stack when an error is signaled. It forces you to use an ugly printf debugging style. I would like to know if it is possible to alter the way the stack is printed. In CL, a debugger is just a function stored in debugger-hook. I hope you can do something similar.
* Somehow Emacs C-M-f selects the whole line, not an expression.
For those interested buying a copy of Common Lisp Recipes: I think Edi said that for the author it is financially better to go via his page:
But then, supporting a local bookstore might also be an option. Though I have to confess, I got my printed copy from Edi as a gift... :-)
But why can't we have nice things back?
Consider a language like Python. Aggressive duck typing means consistent syntax for different data structures and types. Stuff "just works" without a deep understanding of how it works.
CL is the opposite. What is the difference between setp, setf, defvar, and defparameter? Why is the documentation so technical and dense? What is a "form"? What are multiple return values and how do I get to them? Should I spend time learning the loop macro DSL?
I find it similar to Haskell in this regard. The base level of knowledge to use the language is so high that you pretty much need a book, or a degree, to be able to get started. That's a huge barrier to entry.
> The base level of knowledge to use the language is so high that you pretty much need a book (...) to be able to get started.
I wonder what that says about developers these days.
Ever since I started 'till this very day, it was obvious for me that if you want to learn something, you go pick a book about it. Books aren't scary. They have one of the highest knowledge-transfer-to-time ratios out of any sources you could find; they easily beat videotutorials and text tutorials. Most programming books I've read are also quite pleasant and easy to follow (better than some novels I've read...).
Are people scared of books these days?
I mean, I accept that the power of a tool can be a limiting factor to adoption, but I'm deeply saddened by it. Learning and understanding things isn't hard.
--
> CL is the opposite. What is the difference between setp, setf, defvar, and defparameter? Why is the documentation so technical and dense? What is a "form"? What are multiple return values and how do I get to them? Should I spend time learning the loop macro DSL?
The answer to that is simple: go and read a book :). Practical Common Lisp is available on-line for free, and it's a current best introductionary book for CL.
Given the amount of video tutorials on YouTube, I would say yes.
No, but books are more difficult to access than online tutorials and more expensive.
If I suddenly decide I want to learn Common Lisp one night, I'm going to Google "learn common lisp" and read/watch tutorials before I buy/borrow a book. That's not to say I won't move to a book eventually, but tutorials are infinitely easier to access.
Really? I've never seen such a leaky set of abstractions as Python's collection library. It's ridiculous how very often I find something irritating and the reason behind it is, "This was the first implementation and therefore was crowned 'the simplest.'" That seems to be the pattern in general with Python.
A great example is Python's complex iteration system. You have 2 ways to deal with it; a sophisticated but very limited list comprehension syntax and a absolutely primitive direct object iterator that barely abstracts over a coroutine.
You mention the cognitive cost of deciding what to learn, but this is actually a split responsibility between the language community and you personally. You need to make that call, and it speaks to a broader phenomenon.
> I find it similar to Haskell in this regard. The base level of knowledge to use the language is so high that you pretty much need a book, or a degree, to be able to get started. That's a huge barrier to entry
The thing that's so irritating to me about this argument is that nearly everyone who has learned to program falls into one of two categories:
1. Someone who spent a lot of time self-starting in the core principles of OO and imperative programming.
2. Someone who took a class or read a book to help get those principles down.
Folks offer objections to going back to novice status after they've done it once. But, Haskell and Lisp offer totally alternative programming paradigms, paradigms that mainstream scripting languages have been watering down and implementing in a limited context for years. It's only natural that there is a lot of stuff there. There was a lot of stuff to learn for OO scripting languages like Python!
And yet, the idea of learning these with the same methods new programmers use to learn OO patterns is panned as "unfriendly to beginners." I think in reality it's only unfriendly to intermediates.
A good part of that reluctance is entirely rational.
There are many dozens of programming languages that might be worth learning based on what communities of current users say about them.
But you can't tell if they're really worth investing all over again what you already invested in other languages without, well, investing.
It's a lemon market. Sellers know more than you about the true value of the car, err, language, but they have incentive to tell you it's great. Even worse, with programming languages even the most honest sellers might not know how their language really stacks up to the ones you already know because by symmetry they are underinformed too.
For example, I tried getting into Smalltalk based on the intense hype coming from the community, but I came to suspect it really doesn't offer that much of an advantage over languages I know better and stopped. But maybe it really is better... I'll probably never know.
Python is definitely a simpler language. At some point it gets more complicated, when you need to move out of the comfort zone. For example last I looked the main Python implementation had a GIL (Global Interpreter Lock) which makes multi-core concurrent execution a problem. Common Lisp has more sophistcated implementations which don't have a GIL and easier use of multi-core threading.
Yes, you need to learn the difference between setting a variable and defining a global variable.
A 'form' is any valid expression in the Lisp programming language:
This is a valid Lisp form: (+ 1 2) It computes to 3.
This is not a valid Lisp form: (1 2 -). Trying to execute it is an error. The list is a valid s-expression, a list with three elements. But it is not a valid Lisp program, because Lisp expects the operator as the first element of a list and 1 is not a valid operator.
This idea of s-expressions and some of them are valid expressions in a programming language is different from Python, which does not have the idea of code-as-data. Thus you have more to learn and it is more complicated. But it makes many forms of computing with code easy.
Yes, you will have to learn about functions being able to return more than one value.
Yes, learning LOOP is useful. It's not the most elegant construct but it is quite powerful. There is a slightly more elegant and even more powerful alternative: Iterate. But it is a library and LOOP is already built-in.
Yes, a book helps. Luckily there are many. See the here mentioned Common Lisp Cookbook.
As introductions see:
Practical Common Lisp from Peter Seibel. http://www.gigamonkeys.com/book/
Common Lisp: A gentle introduction to symbolic computation. https://www.cs.cmu.edu/~dst/LispBook/ You can download the older version for free as a PDF.
Good luck with learning it!
https://www.amazon.com/Land-Lisp-Learn-Program-Game/dp/15932...
To me there are different kinds of iterations. Many are naturally written as MAPCAR/REDUCE because the iterations are all independent. Iterations where there's lots of state carried from one iteration to the next are more naturally written with DO or even using tail recursion, if the implementation you're using supports that (most do these days). The theory behind LOOP is that all iterations are fundamentally the same ("one macro to rule them all" I guess). I think this is fundamentally wrong-headed. I want to be able to see at a glance what kind of iteration it is by seeing how it is written.
If later it needs optimization I'll give it a better look. (I've rarely needed to do this.)
I like my iterations to look the same so the source as a whole will be easier to grasp (for me and someone else).
Then again, you're Scott Burson and I'm just an anonymous Lisper so the parent should definitely give your opinion more weight.
[1] And DO has always looked ready unclear to me.
$ txr
This is the TXR Lisp interactive listener of TXR 180.
Quit with :quit or Ctrl-D on empty line. Ctrl-X ? for cheatsheet.
1> [mapcar succ "abc"]
"bcd"
2> [mapcar succ #(1 2 3)]
#(2 3 4)
3> [mapcar succ '(1 2 3)]
(2 3 4)
4> ["abc" 1]
#\b
5> ['(0 1 2) 1]
1
6> [#H(() (2 two) (1 one)) 1] ;; #H = hash literal
one
7> (car "abc")
#\a
8> (cdr "abc")
"bc"
9> (car "a")
#\a
10> (cdr "a")
nil
11> (ldiff "abcd" "cd")
"ab"
However, your understanding has to be deeper to grok how this works. It is simpler for mapcar to just reject strings and be described only as a list operation.Common Lisp does have the the concept of sequences: a collection of generic operations over vectors, strings and lists. It just doesn't "go to town" with it. Common Lisp offers compilation to fast code. Really fast. Python-will-never-get-there fast.
All of those things are there for a reason, and most of them are very well thought out, documented, and are useful. If someone does not like having a lot of tools, they can use a poorer programming language. What kind of contribution do you think that someone with an attitude of "stuff "just works" without a deep understanding of how it works" can make to a community? Popularity and fads only have value to technical book publishers and conference organizers.
From reading about the history of LISP I'm not sure I agree. My take on it is that It was never meant to become a real language as it is now, some guy hacked together an interpreter for the s-expressions because it looked fun and easy, no-one ever bothered to take it further, and here we are.
LISP seems to be the bare mininum required to do whatever McCarthy was starting to explore and these days a lot of LISP nuts seem to think it is the coolest thing ever because of its minimalism without realising it was never meant to be that way.
Yeah, you can express anything in lists. You can also express any program in a turning machine. Doesn't mean you should.
But I don't know LISP well enough to say whether people who are commercially successful with LISP owe it to the language, or they would have been whatever language they use.
I'm not convinced it is just 'what is the difference between setp, setf, defvar, and defparameter?' I think it is fundamentally different to how I approach programming.
I learned programming back in the 8-bit era, taught myself assembly, etc. I'm almost a hard-coded imperative programmer. I took to C and Java like a duck to water, and I'm guessing LISP advocates think I'm irreparably broken.
I agree with TeMPOraL that picking up a book to learn things is a good way to go and shouldn't be seen as a black mark against a language. The problem these days is that most books are rubbish. Every Clojure book I've seen is just garbage. I'm guessing CL books are better in regards to technical quality because not every average programmer can vomit one up but everything I've encountered invariably harps on about how much better LISP is than every other idea ever, and how concise and elegant it is, and the general smugness drives me nuts.
Practical Common LISP is better than most in that regard but it still falls into the trap about how expressive and concise and elegant and awesome LISP is right before showing 3 lines of code I have to spend a long time digesting.
I assume I'll get it one day, but it's like turning a container ship going really fast at the moment.
I'm wondering if the best way to understand LISP is to write a CL interpreter.
In very simplified terms:
Use defparameter to define a variable at top level (let's call it "global" for simplification.)
Defvar does the same, but if the variable already had a value, then it won't change that value.
Once you define them you can later change the value using setq or setf.
Setf does everything setq does and more. Setf can change the value of "places". "Places" is a great fundamental concept of CL.
> Why is the documentation so technical and dense?
Because Common Lisp is technical and dense. But it is that way for a reason, and as a reward, it "just works" and allows you to do things impossible or really difficult on other languages. It has no limits. CL is dense in features. It isn't a "watered down" language like python (btw i like python and use it). Python is restrained on features (compared to CL) thus there is less to learn. Thus it is easier to learn.
> What are multiple return values and how do I get to them?
Functions can return more than one value. This is not the same as putting many values on a list and returning said list. CL also allows true multiple return values.
This is explained on the CLHS. Use "multiple-value-bind" to get them.
To answer your specific questions, "form" is just a generic term for any sort of lisp code, whether it's an expression, quoted data, or a special form like defun, if, cond, lambda, etc.
Yes, you should learn the LOOP macro, the simpler iteration macros such as DO-LIST, as well as primitive types of loops (a function that recursively walks down a list, for example). You should learn the primitives because you this is how the nicer macros are implemented. The macros are there to save you time, so you'll end up mostly using them rather than writing everything out long-hand.
There is no setp, but setq is the primitive operation of setting a variable whose name is given by an unquoted symbol: (setq foo 42) sets the variable called foo to the value 42.
setf is magic. It generalizes setq to operate not just on variables but on places. A "place" is any expression that would ordinarily access some value. For example, if I have a list called foo, then the third item in the list is (third foo). I can get the value of that item by calling (third foo), and I can _set_ that value by calling (setf (third foo) 42).
defvar and defparameter are not very different from each other, except that defvar assigns the initial value to the named variable only if the variable isn't yet bound, while defparamter always sets the variable to the inital value you give. This means that if you load a file that has (defvar foo 42) in it, the foo variable will have the value 42. If you then change that value (by running (setf foo 24), for example), and then reload the file, the defvar form in the file won't overwrite the value you've set foo to, while a defparameter would.
For these kinds of questions I recommend the Common Lisp HyperSpec: http://www.lispworks.com/documentation/HyperSpec/Front/index...
The Permuted Symbol Index is usually where I start; it a sorted index of all the symbols, but symbols show up once for each word in their name. For example, if you go to the "I" page of the index (http://www.lispworks.com/documentation/HyperSpec/Front/X_Per...) you'll see that IF is listed, as you would expect, but also FIND-IF and MEMBER-IF. This is super useful, because you might only partially remember the name of what you're looking for, or you might be interested in these other related items that would have been hidden away in a normal index.
No affiliation -- just checked for myself.
vindarel on Github has been doing an enormous amount of contributions in the past two weeks, and the modern look and feel (and some of the more modern content bits) are entirely due to their hard work.
eudoxia0 spent some time prior to that converting it and getting it modernized.
I'd like to congratulate them on their work, since we're on the front page of HN.
(I sort of steward the GH fork of the cookbook these days).
I maintain code from the 1980, part of which is in Common Lisp and part of which is in C. The C code breaks. The latest failure seems to be caused by the GCC compiler changing the semantics of 'inline'. The include files differ between platforms.
The Lisp code just runs.
There are no arguments like Python 2.7 vs Python 3.x. No arguments about C++11 vs C++14. No arguments about Clojure from 4 years ago and Clojure today. No arguments about any of that.
There is a standard. ONE standard. It only matters when you have to maintain someone else's legacy code. But it really matters.
C++ issues a "new standard" every 3 years or so which is just nonsense. Even Stroustrop said that the "new C++" is not the "old C++". They are adding ideas (e.g. Concepts) that virtually no one is asking for or knows how to use. Ten years from now that C++ maintenance job you have will be a nightmare. PL/I tried to be everything to everyone for every task and eventually disappeared. C++ is on the same long-term death march. You heard it here first.
Possible tip: sneak in ABCL when they're not looking. ABCL is a Common Lisp implementation for JVM, with (what seems like) relatively OK interop between Lisp and Java code.
The whole thread is about primarily Common Lisp; people who enjoy the design choices made by the CL standardization committee and subsequent evolution of the language's ecosystem would most likely want to know that there exists a proper CL implementation for JVM.
Well, it's definitely a Lisp; however, I don't think the "nice" qualifier fits here.
Clojure has a few interesting features which are well integrated with each other, but it also comes with a lot of opinionated choices one might not like. Another thing - not a language issue per-se - is that relying on Java ecosystem can be painful (and ClojureScript, fortunately finally bootstrapped a while back, is not quite the same language).
Personally, I feel that, in pursuit of simplicity, Clojure dropped a lot of useful features. As an example, in both CL and Racket, you have 2-3 times more ways of structuring your code than in Clojure. This is important, because different parts of a codebase benefit from different structuring mechanisms - and the more choice you have, the easier it is to find the right one. In Clojure, all you have are maps and defrecord, with the latter being almost never used.
Of course, you have macros to combat this, but then you're put in the shoes of language inventor and implementer, which is a lot more complexity than most programmers would like to fight just to be able to order the function definition the way they want.
To summarize: in my opinion, Clojure did some things right but then got locked into that single track and refused to incorporate additional features (and lessons learned) from other Lisps. So no, I don't think it's a "nice Lisp." OTOH, it may well be a good language, especially if your problem and domain are a good fit for it.
It's 'Lisp'-like where the basic primitive list processing has been replaced with a different higher-level data structure (persistent sequences) built on top of an alien infrastructure which leaks through everywhere and which was not developed for interactive programming (the JVM)... That was one of its original design decisions: being hosted on top of the JVM.
Clojurescript, which is nearly identical semantics to Clojure, also is quite a practical skill for front-end development.
It's important to note here though that this is a feature, not a bug. CL is a multi-paradigm and extremely pragmatic language.
1) I never said it was a bug. 2) Whether CL's multi-paradigm nature is an advantage or not is subjective.
Where do you live?
Yes, that's dumb.
http://phoe.tymoon.eu/clus/doku.php
It's based on the last pre-ANSI CL standard sources.
I have been in the JS, Java, Python world for a while and this looks like a language that could stretch my brain a little bit.
None of this is because Common Lisp is a bad language. However, it does show its age in so far as its approach to documentation and user expectations. Using Common Lisp is similar to using the Unix/Linux command line. The expectation is that the user is willing to read text files that read like man pages and work their way through deep technical documentation...or to put it another way, it is very common to use EMACS when coding Common Lisp [though commercial editors are available].
To me, Clojure reflects a lot of Common Lisp's assumptions about the user being a professional programmer...to the point EMACS is pretty much the default programming environment [though other environments are available that reflect Clojure's Java heritage].
Since I mentioned EMACS twice, EMACS Lisp is another Lisp that is well documented and easy to install (in addition to being a road to EMACS). While it may be called 'a scripting language', on contemporary hardware that doesn't mean much. Just about anything a person would write for learning will run sufficiently fast within EMACS using EMACS Lisp.
Common Lisp was designed early as a more practical language.
Take for example error handling: Common Lisp has a nice error handling system integrated into the language since the mid 80s. Scheme never had something comparable specified in its standards. Sure you can add error handling on top, but it won't be integrated well into the wider language.
There are many aspects where Scheme was underspecified for decades and efforts to redesign the core language were slow, controversial and not really providing nice results. Many Scheme designers wanted the language to be kept as small as possible (R5RS level). The R6RS design was controversial and R7RS 'large' is a very slow effort...
In many ways, Common Lisp is as a practical Lisp language better designed than the average Scheme and Racket is just another Scheme going in its own direction. Actually if you read the Racket docs, it is a very complex system.
One also could use the excellent Chez Scheme (which now is open source) or Chicken Scheme.
The ideas of Racket onboarding beginners is also confusing: multiple languages with some integration mechanism with various degrees of different features and semantics. Much of that is not really needed, but a nice experiment in language modularity. Added to that an IDE which favors batch programming for beginners... In a teaching setting it helps reducing side-effects ... each 'Run' is a new program start.
To be clear, I think Common Lisp is a great language and in no small part this is due to the stability that its design by consensus and reference standard over approximately a decade by a group of seriously competent programmers and computer scientists. The price of Common Lisp is the RTFM tradition of onboarding users, TANSTAAFL.
I agree that Racket ecosystem is complex. There is a valley that contains the basic abstractions of Erlang [1] and Algol Mesa is accessible right out of the box and Scribble for writing documentation. Of course, the fact that all that complexity is documented in the standard distribution (and generally very well documented) is [at least for me] a feature not a bug.
Finally, my current take is that 'easy' onboarding of users is a bait and switch for any programming language [2]. Eventually there is an inflection point where the answer is RTFM. It just comes earlier or later in different language communities. With Common Lisp it comes much earlier than is typically expected by programmers today. StackOverflow is more likely to be a first attempt at problem solving than Steele's Common Lisp the Language.
[1]: http://docs.racket-lang.org/guide/parallelism.html#%28part._...
Chicken Scheme is my favorite, but Racket or Guile would work too. Guile is good because Emacs is slowly transitioning to using it, and Racket for its great ecosystem.
Chicken Scheme itself compiles down to C, so it's quite fast, portable, and light-weight. It also has a great ecosystem, library of eggs, and community.
Others have mentioned Elisp, which emacs uses, and that's good too if you are interested in emacs. It would just be a shame to start with it and get the impression that that's the best that a Lisp-like language can offer when it's really rather primitive compared to a modern Scheme, Clojure, or CL. I myself learned Elisp last, after already learning CL and Scheme, and found doing so to be very easy after having learned the others. So I'd really recommend starting with one of the others and learning Elisp last, if you're in to emacs.
Emacs on Guile is nearly a one-man project that has been progressing in fits and starts, and it's not guaranteed that that branch will be adopted as the Emacs mainline. Basically, the Emacs devs are telling the Guile folks that the onus is on them to make something worth integrating into the Emacs core, and so far it's nowhere near that.
But it's important to realize that Emacs on Guile is only about using Guile as the runtime for Emacs Lisp, as multiple languages can compile to Guile bytecode, not just Scheme. Even if Emacs on Guile happened, the user would not program in Scheme, but still in Emacs Lisp.
Well, you could program in eLisp, and most people probably would, but you could also program in Scheme. Most emacs programs would remain in eLisp for a long time, though, as it'll take a while to convert them all over to Guile.
So, yes, this is a long-term project, and most people would continue to program in eLisp for the foreseeable future, but some would program in Scheme and try to convert existing eLisp programs to Scheme.
That's my understanding of the situation, anyway.
For exploring Lisps in general, such 'strange loops' around building tools do not seem quite as obvious obvious or natural. Particularly at small scale programs.
The #1 issue for folks in my experience had been getting an environment set up. Emacs, SLIME, encodings, paredit, ... . It's a big barrier to entry.
That said, for people who want to start with CL now, I'd recommend grabbing https://shinmera.github.io/portacle/. It's a portable Lisp IDE based off a pre-configured Emacs + SLIME + SBCL + Quicklisp + Git combo. I can confirm that it Just Works, out of the box.
Quick lisp solved it mostly, but Roswell is the finishing touch in my opinion.
shell$ sbcl
[... some editing ...]
sbcl> (load "file.lisp")
As for which Lisp. I advise Common Lisp since it's the most practical of the lot. Doesn't force you into a particular paradigm.If you are only interested in getting into the syntax. It almost literally doesn't matter. If you are interested in learning a lot of tricks that you've probably not had a lot of exposure to, CL is almost certainly the more bountiful place to start.
It's self-hosted in JavaScript and Lua. It matches the JS runtime as closely as possible, so if you're comfortable with JS, Lumen is basically a wrapper around it.
Think of it like CoffeeScript on steroids.
There isn't a lot of documentation, but if you have any questions I'm happy to answer them.
Lumen looks interesting and I dug up some HN comments from over the years.
Any example apps or sample code anywhere?
What about host language access? I'd rather not give up using existing JS and Lua libraries.
I can see there's REPL, but is it possible to have dynamic evaluation while running inside web browser?
Have you used this inside Nginx's Lua module and/or OpenResty?
Why not Python as one target host language? Lists and hashmaps (dictionaries) are pretty prevalent there and I believe continuously developed Lisp dialect is still missing.
Thank you for this. I learned new things already.
Here's a version of Lumen you can copy-paste directly into your browser console:
https://gist.github.com/anonymous/c8e26607668dd6240f606fc2d0...
That's not too convenient, but it's easy to create a wrapper around these building blocks.
If you have any other questions at all, please don't hesitate to ask. I love talking about this stuff.
Easy:
$ npm i leftpad
$ LUMEN_HOST=node lumen
> (require 'leftpad)
function
> ((require 'leftpad) "foo" 10)
"0000000foo"
> I can see there's REPL, but is it possible to have dynamic evaluation while running inside web browser?Yes, the entire codebase is only 3k lines. You can use browserify, or simply concatenate all the JS files together. Lumen is unopinionated.
I've done this before, and I'm more than happy to set you up with a copy-pastable solution if you want.
> Have you used this inside Nginx's Lua module and/or OpenResty?
No, but there's no reason it wouldn't work. Here's an example of it working in a WASM Lua implementation: https://news.ycombinator.com/item?id=13900453
> Why not Python as one target host language? Lists and hashmaps (dictionaries) are pretty prevalent there and I believe continuously developed Lisp dialect is still missing.
I've spent time on this! It's a difficult problem. In Lua and JS, you can attach keys and values to arrays. In other words, an array can also be a hashmap. Not so in Python -- or rather, not with the standard Python dict() type. And then you run into problems of interoperability and performance: if it's a non-standard type, other libraries run into problems consuming it. This is less true of Python than other languages, though, so I've been trying to find a happy medium.
There are ways of using solely arrays, but it involves having some sort of Keyword type. A normal lisp has those, and typically they use '(a b :x 42) to create an "array" where the first two elements are "a" and "b" and the key "x" has value 42. You can do something similar for Python, and it's an active area of research for me.
> Any example apps or sample code anywhere?
This is Lumen's strength and weakness. Very few people know about Lumen because of a lack of examples and documentation. However, it's incredibly cool and quite mysterious, and I like that it has a very small following. It makes changing the language much easier.
Here's an extensive example: https://github.com/sctb/motor
Note that it won't run on the latest Lumen, because dot syntax was recently removed. You'll need to revert to commit `c146de`. But you see how easy it is to morph the language into whatever shape you want, and how powerful it can be.