6 ms·
Common lisp is surprising not functional. It embraces that all things can be first class things. But mutable code is very very easy in common lisp.
by taeric 5y ago
Common lisp is surprising not functional. It embraces that all things can be first class things. But mutable code is very very easy in common lisp.
- pjmlp 5y agoUntil everyone and their dog decided to turn functional as a synonym for as Haskell does it, Lisp was quite functional.
- bradrn 5y agoMy understanding is that Scheme is quite functional. So were the very first versions of Lisp. Common Lisp, on the other hand, strikes me as not very functional at all (from what limited experience I have of the language). It does have first-class functions, and functions like ‘map’ and ‘reduce’, but that isn’t enough to make it truly functional — it seems to lack the characteristic approach of building functions from smaller functions that is so common in functional languages. (Also, functionality is more of a continuum than a binary category. CL certainly is more functional than Python, but less functional than Scheme or SML. It all depends on where you draw the dividing line, though I’d argue that classifying CL as ‘non-functional’ makes for more meaningful categories.)
- lispm 5y agoThe very first versions of Lisp were less functional than Common Lisp: imperative, mutable data, mostly only dynamic scoping for variables, no lexical scope, first class data type of functions unclear, ... Common Lisp at least has lexical scope and first class functions.
- bradrn 5y ago> The very first versions of Lisp were less functional than Common Lisp: imperative, mutable data, mostly only dynamic scoping for variables, no lexical scope, first class data type of functions unclear, ... Hmm, perhaps I’m misremembering — I know very little about the history of Lisp. I was thinking specifically about the very beginning of the language, where it could be used to define ‘eval’ and nothing much else.
- lispm 5y agoThis is the manual of Lisp I, the first actual implementation of Lisp, from 1960: http://bitsavers.org/pdf/mit/rle_lisp/LISP_I_Programmers_Manual_Mar60.pdf http://bitsavers.org/pdf/mit/rle_lisp/LISP_I_Programmers_Man...
- hajile 5y agoCommon Lisp has lexical AND dynamic scoping. This is very nice with constants. A function can make a hard dependency on standard out for example. If I change that value locally then call the function, it will operate as expected while everything else using that variable name will continue using their own expected values too. Lexical scoping would instead require passing that value in every time it is used.
- dreamcompiler 5y agoScheme directly supports call-with-current-continuation (which CL doesn't) and it requires tail call elimination (which CL doesn't require but most CL implementations do it anyway). Scheme also has slightly easier syntax for dealing with functions in function position, at the cost of potential namespace clashes. Some schemes (e.g. Racket) provide immutable data structures. So I guess Scheme is slightly more functional than CL but with the exception of call/cc the differences are so minor that it doesn't matter.
- agentultra 5y agoIf functional means "higher order functions", sure Lisp is quite functional. It's not ergonomic to compose functions in the way that Haskell is due to Lisp's forms essentially making every function able to accept a variable number of arguments. You end up with something like arnesi which provides these functions but it gets slow and verbose to write all those `funcall`'s everywhere. Or you have macros. Whereas in Haskell, partial application and composition are first-class in the design of the language. I really enjoyed programming in CL but I would say that it's one of those languages that let's you try functional programming but it's not the sweet spot for it.
- reikonomusha 5y agoCoalton is in Common Lisp and lets you write all that convenient syntax without much fuss.
- nudpiedo 5y agoI always understood functional in the matematical sense of: inmutable/no side effects. At some point someone decided typed lambda calculus was a superset of lambda calculus and the next thing was the haskell alike thing.
- dreamcompiler 5y agoI assume you mean mutable data, and yes, mutable data is easy in CL. But at the same time immutable data is not hard; it's just not the automatic default.
- taeric 5y agoYeah, I confess I should have said "lisp is surprisingly friendly to non-functional idioms." In large, this can mean mutable data, sure.
- Blackthorn 5y agoI wish it made more things first class. There are surprisingly many restrictions. Example: the call stack isn't first class. You can only interact with it through the condition system, which is very limited. Example: CLOS has a meta object protocol, which is great! But there's no equivalent to the MOP for, say, the language rules themselves (first element in a list in the reader is treated as a function namespace reference, for example).
- lukego 5y agoI was lamenting this the other day, thinking of Smalltalk being able to snapshot the stack and store it in a variable for debugging later. Then it occurred that one should be able to write a Lisp function that creates a data structure containing a snapshot of the whole stack and then inspect that later. So maybe no new Lisp primitives are needed?
- Blackthorn 5y agoHow would you write such a function? The ways to interact with the call stack in Common Lisp are very, very limited.
- lispm 5y agoThe debugger of a Lisp system is also not exclusively written in the language (operators, ...) described in the Lisp standard. The standard language is largely independent from a runtime. It says nothing about the implementation technology. The Lisp system could be running on a virtual machine (like many Smalltalk systems), it could be a whole-program compiler to C, ... For example in LispWorks it's possible to look at a snapshot of a stack in a Debugger, later.
- taeric 5y agoIn your last point, isn't that the evaluator, not the reader? That said, I'm all for more first class things. I really just meant that common lisp was ahead of the game on number of first class things.