Live data from Hacker News

Lisp's Influence on Ruby

blog.tacoda.dev

41–50 of 91 posts

Re: Lisp's Influence on Ruby

#41
post #15

For folks that want all of this plus macros (and a lot of other great things), check out Elixir.

100% Elixir is much more a Lisp than Ruby is.

Agree that Elixir is closer to a Lisp than Ruby.

Heck at least in my brain MLs are closer to a Lisp than Ruby...

Re: Lisp's Influence on Ruby

#43
post #23

One way I find traditional Lisp style more painful for functional code than Ruby is that fully functional-style Lisp pushes me to read and write code the opposite way from how I think about it. In the author's example: orders .select { |o| o.placed_at > 1.week.ago } .group_by(&:customer_id) .transform_values { |group| group.sum(&:total) } the equivalent Lisp code would either be written in imperative style as multipl…

Threading macros are nice, though, right? https://docs.racket-lang.org/threading/introduction.html

Love those.

Re: Lisp's Influence on Ruby

#44
post #19
post #9

Earlier quoted context omitted.

Funny enough Lisp was originally meant to be written in a higher level syntax (with infix operators and everything). But yeah, macros and S-expressions make it easier to write your own DSLs.

With decades later, Dylan and Julia becoming the only ones that kind of managed to get some adoption doing it. For better or worse, parenthesis aren't that bad with the proper IDE tooling.

> For better or worse, parenthesis aren't that bad with the proper IDE tooling.

Hell, even without [0], you can at least count the parenthesis by hand in a pinch. I remember seeing lots of crazy-awesome stuff done in AutoLisp by 'non-programmers', versus 'structure as spacing' in Python which really sucks if the Editor was designed to use the system default (probably non-monospaced, cause other products in the industry had dialogs that broke if you switched to a monospaced) font. [1]

[0] - but real talk parenthesis matching in an editor is a lifesaver

[1] - oooooold version of a very popular GIS product.

Re: Lisp's Influence on Ruby

#45
post #23

Earlier quoted context omitted.

Threading macros are nice, though, right? https://docs.racket-lang.org/threading/introduction.html

They're nice, but they're not the same thing. The threading macros are (as I understand it) pure sugar. Turning (-> (gather my-list) uppercase-list sort) into (sort (uppercase-list (gather my-list))). In contrast to, say, Java (I can't speak to the code above): List things = thingIds.stream() .map(model::findThing) .filter(Objects::nonNull) .toList(); These are streamed. This is pretty much a pipe structure, whereas…

Clojure has two options:

The version with a threading macro, will create a lazy-sequence for each step in the pipeline. It will not instantiate the entire list, so it's O(1) memory overhead in terms of peak memory, but it churns O(N) extra garbage.

    (->> things
         (map model/find-thing)
         (filter some?))
And the version with transducers, which will not create any intermediate sequences:

    (sequence (comp (map model/find-thing)
                    (filter some?))
              things)
It looks like there's a Common Lisp transducers library, but I have no idea how widely it's used.

https://github.com/fosskers/transducers

Re: Lisp's Influence on Ruby

#47
post #2

That is actually Lisp influence on Smalltalk, and Perl, that eventually influenced Ruby.

Matz directly credits Lisp (through Emacs Lisp) as influence in the design of Ruby and its runtime, with Smalltalk influence on the language itself, and IIRC Perl as "what was popular and we tried to replace"

Re: Lisp's Influence on Ruby

#48

I love Ruby, use it for most of my projects that don't require performance. Nothing I would love more than a Ruby with a Common-Lisp like compiler and runtime. Unboxed types, native compilation, partial compilation, live image (Ruby has this but "faster Rubies" like Crystal don't), etc...

I have a (self-hosted, but buggy and wildly incomplete; don't try to use - jRuby or TruffleRuby are better - and far faster - options) Ruby compiler that was partly born out of wanting to figure out what this would take, and the answer is it is massively painful because Ruby has failed to take some basic steps that makes delineating read-time and run-time very hard (e.g. you have fun patterns like overriding "require", and iterating over directories to decide what to require) even though most Ruby programs do have clearly separate load and run phases. It's just hard to programmatically separate it.

I still believe you could do pretty well there with a few basic "tricks" that could still also remain real/valid Ruby, by recognising the most common patterns, documenting them, and providing a way of marking exceptions. Combine that with freezing system classes after startup as an enabler for various optimization, and a compiler could do a pretty good job. But it's a massive piece of work to get it right for Ruby.

Re: Lisp's Influence on Ruby

#49
post #21

Earlier quoted context omitted.

Which Lisp, out of interest?

Does it really matter? There's a point in every Lisper's life, a threshold after which the question becomes immaterial - you'd stop thinking about intricacies of whatever Lisp and focus on the platform specifics instead. Any given day I might program in three-four different Lisp dialects, e.g. Clojure/Clourescript, Fennel, Elisp, Janet, etc. and it practically feels like I'm using the same PL. While switching between…

> Does it really matter?

not philosophically, but certainly practically. To double down, if all lisps are roughly equivalent from a language POV, then you'd want to pick the one or two that will give you the most practical advantage (libraries, documentation, dev environment, etc.)

Re: Lisp's Influence on Ruby

#50
post #11

> He’s described Ruby’s design as starting from a simple Lisp, stripping out macros and s-expressions Put the macros back! It would be so cool!

Macros depend on homoiconicity which Ruby sacrificed in order to have familiar syntax.

Homoiconicity makes macros slightly more syntactically elegant, but is not at all necessary. Rust has macros and isn't homoiconic at all.
Post reply on HN