3 ms·
I'm super interested - I'm always on the lookout for a replacement for Ruby as my primary scripting lang. LISPs seem super cool for scripting because of the exp
by d3nj4l 5y ago
I'm super interested - I'm always on the lookout for a replacement for Ruby as my primary scripting lang. LISPs seem super cool for scripting because of the exploratory nature of the REPL - writing a script, at least for me, is a process where I have to run it dozens of times, tweaking it every time, and then finally running it regularly without monitoring, and the REPL would save so much time in the first part of this process.
But while I'm interested, I can't find any docs for what's included. For scripting, I think I would at least need the following in the standard library, no package management required:
1. A good API for filesystem ops, such as reading and writing files. Ex: reading the lines of a file into a list, writing a list to a file as lines etc.
2. Making network requests easily, with persistent connections if you need it. (see Net::HTTP in Ruby, which has become extremely usable for all but the most advanced use cases)
3. Parsing JSON at the very least, with YAML and CSV being good to haves.
4. An easy way to run shell commands for stuff that's just better handled there. (like `` in Ruby)
In addition, if the stdout natively supports colouring text that would be super sweet, but that's not a hard requirement.
I can see 1) to some extent in the examples, but without a docs site I'm not sure about the rest. Does anybody here know for sure? Otherwise, is there some other lisp that would meet these requirements?
- phyrex 5y agoGive babashka a try. It’s a (very batteries-included) clojure dialect that has the specific goal of replacing shell scripts like that: https://babashka.org/ https://babashka.org/
- JHonaker 5y agoIf you're interested in a lisp for scripting, you should give Racket a try. This is just a Racket DSL (created I believe as a make-like system for the actual Racket project). Regular racket has all of the things, and if easy interaction with the shell is what you desire, you might try RASH, the Racket Shell DSL.
- klibertp 5y agoDoes it have to be a Lisp? I was searching for a language to replace Python for quick scripting, and eventually settled for Raku. If you use RakudoStar distribution, you'll get all the functionality you list (and if you use bare rakudo, you can install it with zef). Why: Python can be verbose, and when I want to write a one-off script to rename some thumbnails in a directory somewhere, that verbosity doesn't help. The strong typing, while good for correctness, also doesn't help much in this use case. What I tried: V, Nim, Clojure, Scala 2, Scala 3, GNU Smalltalk, Rust, Zig, Clojure, Racket, Emacs Lisp, Raku, Ruby, OCaml, and LiveScript. Why Raku[1]: expressive power is insane. My test case of writing a script to merge requirement versions coming from two differently formatted files needed ~30 lines of code on average, while Raku needed just 10. The next best was LiveScript with 23 lines, then Elisp with 25 (counting imports; I have all the libraries already imported in an Emacs session, so I could go down to 19 lines, but thought that would be cheating). The language being "write-only" is not important to my use case, but I also don't feel like Raku is write-only. Yes, reading something like this: my @toml = "script.toml".IO.lines.grep(none "" | /^'#'/).map:{S/'='.*$//.trim}; can take some getting used to, but it's not really much worse than BASH. [1] https://docs.raku.org/language/faq#Why_should_I_learn_Raku?_What's_so_great_about_it https://docs.raku.org/language/faq#Why_should_I_learn_Raku?_...?
- d3nj4l 5y agoThanks for the rec. It doesn't have to be a lisp, but if I'm switching from Ruby I wanted to get something much more major in return, and the REPL features fit the bill. The reason is that when scripting, I often need to debug and explore the problem while the script is running, and most languages don't make that easy. Ruby's debugger (and formerly, pry) is pretty useful, but a full fat REPL would make the experience far more joyful. As for that line, maybe it's my Ruby heritage, but I didn't find it particularly unreadable! Chaining messages is pretty tight and very useful for one liners.
- klibertp 5y agoI don't think you'll find a Lisp that would be anywhere near things like IPython (which I'd consider an example of "far REPL", with context-sensitive completions, inline documentation, rich history with searching and filtering, magic commands (eg. %timeit), ability to call shell commands, ability to mix code and shell (eg. for x in range(10): !echo $x - for lack of better example), ability to load and reload modules, ability to place breakpoints & integrated debugger, etc.). Racket with xrepl enabled is nice and offers some of the features, but far from all of them. You might want to take a look at rash[1], but the project is still experimental and some parts of it are not finalized. Common Lisp implementations coupled with SLIME are nice, and with some utility libraries you can go a long way, but then you're basically tied to Emacs. I'm not sure about Clojure - I didn't investigate that much due to startup time making it not very well suited for my use case (that's also a reason why I ruled out Elixir, even though it's also a very nice language). Other Lisps all have REPLs, but they tend to be really bare-bones compared to more advanced implementations. I used Chicken Scheme for scripting, making use of its ability to compile to native executables, and it's quite nice with a lot of eggs (packages) available, but the REPL is also pretty standard, with just the default readline functionality. > maybe it's my Ruby heritage Definitely :-) My Python-only colleagues screamed in horror after seeing that line... [1] https://rash-lang.org/ https://rash-lang.org/ - I have a similar project running on GNU Smalltalk, but didn't get to work on it in half a year :(