Skip to content

Instantly share code, notes, and snippets.

@vindarel
Last active March 30, 2022 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vindarel/59db5d57391f35e86288f2c6bf7dcd59 to your computer and use it in GitHub Desktop.
Save vindarel/59db5d57391f35e86288f2c6bf7dcd59 to your computer and use it in GitHub Desktop.
Elixir VS Common Lisp - preliminary remarks

I am still only lurking into Elixir. My friends love it. I want to evaluate the developer experience and compare it with Common Lisp.

Alchemist mode for Emacs doesn't seem to have much of the interactive capabilities of Slime (and that would be understandable, given it's the most one can do).

often alchemist has to boot an Erlang VM to evaluate a single expression. Running tests boots a VM, looking up a function’s source doc boots a VM, each prefix autocompletion boots a VM. This is slow, and if you want the VM to load the code you’re actively developing you better not have any compile-time errors.

http://jtmoulia.pocketknife.io/blog/2015/03/11/elixir-and-distel/

We will want to try Distel, even if it doesn't look much maintained (at all).

Someone also said

I use slime in neovim for an in-editor iex repl.

Below is an overview of Alchemist.

Setting up Elixir

Alchemist mode (Emacs)

Mix tasks

Similar to comma commands in Slime (,ql with completion to install Quicklisp packages, etc).

Compile and execute

It's about compiling files with elixirc and running them with elixir. We are not running inside a live image.

Project

Find a test file (easily done with Projectile), run tests. Nothing too special, it seems.

Documentation lookup

OK

Definition lookup

  • no go-to source in source is Erlang or Elixir. You have to set a variable. It's working out of the box with Slime, AFAIK.

    (setq alchemist-goto-erlang-source-dir "/path/to/erlang/source/")

By the way, Elixir is not (totally) built in Elixir, unlike many CL implementations like SBCL.

Completion

  • no fuzzy completion? Alchemist uses company-mode. Slime has fuzzy completion by default.

  • no function signature in the minibuffer?

  • Alchemist has a test mode: allows to run a test at point. There is no default test runner on CL/Slime. We must call it from the REPL (with proper fuzzy completion) or, with FiveAM, run the last-run test with `run!.

REPL connection

Alchemist allows to connect to a IEX REPL.

  • to run it in the context of a project (iex -S mix) you have to ask so.
  • you can send to the REPL: the line, the region, the current buffer, the module. Not the function? Not the previous expression?
  • you can evaluate code and insert the result in the buffer in comments. Fun. Useful? A bit like slime-scratch with C-j or slime-pprint-eval-last-expression which sends the result in another special window.

Macroexpand

Both languages have macro and the macroexpand utility.

More Slime features?

  • many REPLs?
  • find who calls, who sets etc
  • click on an object to inspect it (if it's a hash-table, see it, sort its keys and values, change them).
  • trace utility?
  • toggle profiling of a function, of all functions in a package, of functions containing a substring.
  • disassembly commands
  • both can connect to a running REPL?

Common Lisp parts

editor tools: no class browser for Elixir… because no class?^^ No interactive debugger? No stepper?

type checking on compiling a function

Testimonies

Question: What would you say to my two friends who like Elixir and are afraid of CL? (despite one of them having contributing a feature to a lisp project very easily). I don't have enough serious Elixir experience.

Answer: I don't have enough experience with either either, but I'm torn between the two ecosystems. If all they're doing is web server work I think BEAM languages with Phoenix and LiveView are hard to beat and there is probably more paying jobs if they're not entrepreneurs. If they do more than web server stuff, then Common Lisp is the clear choice because it does everything well.

I really like the warmth and pace of the Elixir community. They're good with documentation, very open, and incredibly active. The downside is that there is a ton of churn so you're always updating stuff. It's nowhere near the level of Javascript that way, but if you're searching for stability, Elixir isn't it. Also, the community is focused mostly boring business apps. The functional style of programming is liberating if you're used to imperative or Java/C++ style object orientation. But not every problem is a fit for functional programming and you can program yourself into a corner that way. I started with Logo as a kid so when I found functional programming I was giddy. It works how my mind works.

The Common Lisp community is smaller but really damn deep. People work on all kinds of apps from hobby projects, to serious science stuff, number crunching, data visualization, web stuff, graphics stuff, games... basically the whole gamut. Libraries that work will still work in ten years. It's nice to be able to rub elbows with luminaries in their fields and read their code. CLers tend to be highly idiosyncratic loners who are scratching their own itches and rolling their own systems rather than relying on prebuilt solutions or opinionated frameworks. That means that you have to know what you want to do and how to do it, as there isn't anyone that's going to hand you a blueprint on a plate. You will however get to talk to people who know architecture deeply and if you survive the learning curve you will know one language that can rule them all. I really like talking to smart people who want to change the world so the CL community is a fit for me. Others find CLers to be brusque, smug, and self-absorbed, but they're like New Yorkers that way and don't suffer idiots well. Documentation in CL is a weakness, but improving, and the code is so damn readable and generally well commented that you get used to figuring stuff out. CL code is often gorgeous, intellectually satisfying, and literary. They say if you want to be a great programmer, read a lot of good code. If that's the case CL libraries and apps are the Library of Alexandria.

Elixir has a REPL and macros, but they're just not in the same league as those of CL. Developing in Emacs with Sly or Slime makes it so easy to play and try things. Apps are built from the ground up a bit at a time and the amount of control and insight into the system that you have has to be experienced in order to understand what you're missing with other languages, even other Lisps. CL can be used as a toolbox to build a language that's specific to the problem you're trying to solve. People complain about the parentheses and readability, but I find Lisp to be way more readable than languages imitating Algol syntax which I personally hate with a white hot passion so much so that it's kept me away from programming until now. I'm 53. At this point, I don't have time to learn all the languages to see what I like, so I want CL because it's one language that will see me through the rest of my life. I also like that CL is multi-paradigm, not just functional. So it's a match for basically any programming style. That does however mean that you have to know how to program functionally if that's what you want because CL will let you mutate whatever you want and you have to know not to. CL is always happy to help you blow your legs off if that's what you ask for.

I hope that's helpful to your friends. I can relate to the intimidation factor with CL, but it's easy enough to dip your toe in the water without committing your life to it. I'm sure others will have more to say.

https://www.reddit.com/r/lisp/comments/tna6zo/moving_from_the_beam_to_common_lisp_what_are_my/i23yr5a/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment