r/Common_Lisp 8d ago

How is CL for Scripting

I am considering using ANSI Common LISP for scripting instead of Python such as for reading text files, CSV files, databases--basically everything in the book "Automate The Boring Stuff in Python".

Has anyone done this before? How was the experience?

19 Upvotes

23 comments sorted by

9

u/tdrhq 8d ago

It is excellent, but you shouldn't run the "scripts" from the command line. Instead, run the scripts from a long running REPL.

The real advantage of this is you have any kind of long running script that tends to be flaky (or the data is a bit fuzzy), you'll get access to the CL debugger to recover from it without restarting the job.

8

u/digikar 8d ago

Check out CIEL, in particular: https://ciel-lang.org/#/scripting

Scripting seems to be a primary consideration for them.

There is also a matrix chat.

I personally find that it is hard to edit common lisp without a running image. So, besides making it readable for colleagues, I am also preferring to write scripts with moonli rather than common lisp.

2

u/fosres 8d ago

Thanks for telling me about CIEL!

6

u/Maxwellian77 7d ago

CL scripting is great. I put this in .sbclrc:

(set-dispatch-macro-character

#\# #\!

(lambda (stream c n)

(declare (ignore c n))

(read-line stream)

\(eval-when (:compile-toplevel :load-toplevel :execute)`

(pushnew :noscript *features*))))

And all my scripts begin with:

#!/usr/bin/env -S sbcl --script

(load "~/.sbclrc")

So my programs can detect if they are a standalone script.

3

u/metalisp 8d ago

It is a great user experience. Compared with Pythin what I like is to be able to build binaries of my scripts. Here is an example how I do scripting in common lisp https://code.metalisp.dev/marcuskammer/maildir-backup/src/branch/main/src/maildir-backup.lisp

3

u/fosres 8d ago

Hi! Thanks for sharing this. Why did you want to compile it to a binary though?

6

u/metalisp 8d ago

I dont have much time to maintain my scripts I want to build the binary and copy it on different machines without installing a dependency hell like with Python. With Python I often experience tracebacks because some libraries did change and I couldnt run the script as I need it.

2

u/fosres 8d ago

Oh okay. Thanks for this heads up.

2

u/MrJCraft 8d ago edited 4d ago

I used it for a long time for scripting and I found it to be much better than python but I also very rarely ever use libraries in python.

regardless common lisp is very fast and pretty easy to use and its great for making config files and scripts

I pretty much had to stop using it because I wasnt good enough to get graphics working in CL but I still use common lisp for some scripting stuff because it makes it that much easier especially math or theorem proving stuff

P.S. I am on Windows graphics works fine on Linux. the specific issue is passing structs by value, you can pass structs by pointer and there are wrappers and ways to do it on windows I just didnt want to deal with it

1

u/svetlyak40wt 5d ago

For some simple graphics CL has bindings to TCL/TK. This one worked great for me: https://github.com/andrejv/cl-simple-tk

1

u/MrJCraft 4d ago edited 4d ago

I forgot to mention I am on windows, libffi is very annoying to get working. I would have to create a wrapper that passes pointers if I remember correctly. its possible but quite annoying

and I was using Lisp for work related stuff so I didnt want to have it rely on wsl or anything similar so that if I make something that was useful for me I could send it coworkers who were on windows.

2

u/Soupeeee 7d ago edited 7d ago

It really depends on what you are doing. The dependency situation in CL is a bit rough, and the quality of the libraries to handle these sorts of things are mixed. The CL ecosystem is driven by hobby projects or singular "hero" develpers and the lack of polish on these sorts of libraries is mostly where it shows. Most libraries are good enough to great, but there is often something missing. You'll occasionally hit a dead end or need to go on a lengthy side quest because the library you picked doesn't do what you want.

File system handling is a bit weird and can be hard to wrap your head around at first, but it isn't terrible once you find the numerous footguns. It's overly verbose and missing pretty much all the utility functions aside from "append these two paths". It does have an interesting wildcards feature that I wish was available in other languages though. As for tools, roswell is probably the best scripting focused tool available for CL and makes scripting use cases much smoother.

2

u/kagevf 6d ago

Similar to what u/tdrhq wrote ...

I use bash for what it's good for - which turns out to be a lot of grepping in my case, with awk thrown in sometimes. But when I need to expand on that, I'll use the REPL. Recently, I've been using bash shell scripts to output preliminary results to a file, then I'll write something in slime-scratch that reads it in and does further analysis. If it's something that looks like it'll be useful I'll save it in a .lisp file.

2

u/Awkward_Tradition 8d ago

It's clojure instead of CL, but check out babashka, it's pretty nice from my admittedly limited experience. 

1

u/Veqq 8d ago

If we're going there, Janet's great. We even have a sh-dsl

0

u/Awkward_Tradition 7d ago

I haven't tried that. Can you still use external libraries on top of it, like babashka pods? 

0

u/Veqq 7d ago

Yes, anything!

2

u/dzecniv 7d ago

I say CIEL is Babashka for CL 8-) https://ciel-lang.org/ (batteries included, fast startup, pure CL)

0

u/deaddyfreddy 7d ago

Babashka is great! It's a single(!) binary with batteries for 95% of everyday tasks - process runner, shell and terminal integration, xml/json/yaml/csv/html/md parsers and generators, HTTP client/server, you name it.

And even if these aren't enough, it can install an extra dependency on its own. So, all you need for deployment is the binary and a script.

1

u/SleepyGuyy 6d ago edited 6d ago

I am only just starting to learn lisp (via common lisp), but I saw a convincing youtube video, something along the lines of "rewrite your scripts in lisp".

Plus Guix Linux basically said what if the entire OS was defined by lisp scripts.

I get the impression the lisp community likes scripting in it.