5 ms·
Disclaimer: not a big Lisp user. Interesting how Lisp code is NOT littered with " if something != null, ...", unlike your average Java project (or even python,
by dgan 4y ago
Disclaimer: not a big Lisp user.
Interesting how Lisp code is NOT littered with " if something != null, ...", unlike your average Java project (or even python, but it's less visible), and just works.
My understanding is that busines-as-usual handling of nil (empty lists) implicitely confers to Lisp code monadic style which help to avoid tedious checks
- fredrikholm 4y agoIt's littered, just hidden. Eg: if, if-let, when, when-let, unless etc. This makes it appear that the data is passed down in a monadic style, but it often isn't; *nil* is not an actionable value.
- crapaud23 4y agoThis is the way Clojure works too. Nil is treated as an identity/neutral element. This goes beyond lists: in contrast to Common Lisp who equates nil to the empty list, Clojure maintains a distinction and you're supposed to handle nils by correctly implementing functions. This is as easy as using clojure's core functions, they all have been tailored to handle nil as the neutral element. As a consequence, in Clojure, nil's neutrality extends to other datastructures, for instance (hash)maps. (assoc nil :some :value) => {:some :value}.
- dgan 4y agoI like the idea, but JVM is a show stopper for me :/
- smcl 4y agoMay I ask why? I've no dog in this fight (I don't work with Java) but I've seen plenty of people against Java the language who were very happy to use Scala or Clojure. I haven't encountered anyone who has specifically said they were against the JVM, so I'm interested whether it's something technical (maybe you do more real-time or work with resource-constrained systems) or if it's something more personal. There are no bad answers, I'm not looking for an argument just genuinely curious :)
- dgan 4y agoCopy pasted: Why => because JVM is poor no fit for CLI, and is a poor fit for games. Those two fields in which I see myself using common-lisp. Unsure what's so wierd about it, everyone (most) knows about slow cold startup times, and inability to control memory layout in JVM. Also, horrible C bindings
- smcl 4y agoI didn't say it was weird :( Just was curious if it was one of the commonly encountered things (which you listed) or if there were some other limitations I wasn't aware of.
- rchtwlm 4y agoWhy? I have no particular feelings for or against the JVM. It always surprises me when people get so passionate about runtimes - how much do you interact with them? They're just in the background doing their thing. I can see reasons for not wanting to use the JVM in specific cases. For example, it may not have the performance you want for the application you're developing. I'm just confounded by general statements such as "JVM = no go", "I want to use C# but I'm more of a JVM guy than dotnet" (or vice versa). Is this some bizarre nu-console war that's going on in the programming community that I have missed?
- dgan 4y agoWhy => because JVM is poor no fit for CLI, and is a poor fit for games. Those two fields in which I see myself using common-lisp. Unsure what's so wierd about it, everyone (most) knows about slow cold startup times, and inability to control memory layout in JVM. Also, horrible C bindings
- crapaud23 4y agoFor me it's microcontrollers, however I've heard in spite of the unmaintained status, clojure-scheme[1] is very usable. It uses gambit to produce C-code you can compile anywhere. https://github.com/takeoutweight/clojure-scheme https://github.com/takeoutweight/clojure-scheme
- yoyohello13 4y agoI'm with you on stock JVM. The slow startup time is often a deal breaker for me. But there are projects that address this. Like https://github.com/babashka/babashka https://github.com/babashka/babashka for Clojure. Or GraalVM for general JVM use.
- richard_todd 4y agoHow do you control memory layout in Common Lisp?
- iainctduncan 4y agoyou might be interested in embedded Schemes. I use s7, which shares a lot of features with both CL and Clojure (for a Scheme) and is very easy to embed in C or C++ apps. I use it for music coding, but others (e.g. Naughty Dog) have done it for games. It's a super fun way to develop. My high level code is mostly Scheme, interfacing with low level C.
- hayley-patton 4y agoI don't usually find myself needing a null element in Lisp, so there's no need to handle any. (Ditto Java, but I don't write much Java to be fair.)
- pfdietz 4y agoCommon Lisp code does have checks for NIL. When they are missing you get bugs like this one: https://bugs.launchpad.net/sbcl/+bug/2002244 https://bugs.launchpad.net/sbcl/+bug/2002244 https://sourceforge.net/p/sbcl/sbcl/ci/06f1639e53e99365f48a119b030202d2dbfef0f5/ https://sourceforge.net/p/sbcl/sbcl/ci/06f1639e53e99365f48a1... If you are calling a generic function you can sometimes avoid such checks by introducing methods specialized on the type NULL (which contains only NIL).
- sph 4y agoAgreed. After 16 years of programming experience, I've somehow settled into a world where error handling is no big deal in my software: - Let-it-crash philosophy of Erlang/Elixir - Monadic errors of Rust - Conditions/restarts/REPL model of Common Lisp Using Go (or C or Python or anything with exceptions) feels like going back to the 1970s.