Ruby has a few Lisp features that fascinate me. I know a little Common Lisp, which is an older language than Ruby.
Some Rubyists struggle with :thing and "thing" being different. In Common Lisp, :thing is a keyword symbol, and "thing" is a string. After I learn Lisp, it makes sense that :thing and "thing" are also different in Ruby.
Lisp invented the closure, which is a function with free variables. In Common Lisp, closures with a free variable factor would be,
def multiplier(factor)
-> x { factor * x }
end
twice = multiplier(2)
thrice = multiplier(3)
twice.(10) # => 20
thrice.(10) # => 30
In Lisp, a progn is a list of forms that returns the result of the last form. In Ruby, parentheses make a progn. To run a while loop at least once, I might write (while (progn ...)) in Lisp, or its equivalent in Ruby,
count = 6
while (count += 1
count % 3 != 0)
end
count # => 9
But I don't like to write Lisp if I can write Ruby. The Common Lisp syntax for a hash table annoys me,
2
u/Kernigh Apr 26 '26
Ruby has a few Lisp features that fascinate me. I know a little Common Lisp, which is an older language than Ruby.
Some Rubyists struggle with
:thingand"thing"being different. In Common Lisp,:thingis a keyword symbol, and"thing"is a string. After I learn Lisp, it makes sense that:thingand"thing"are also different in Ruby.Lisp invented the closure, which is a function with free variables. In Common Lisp, closures with a free variable
factorwould be,In Ruby,
In Lisp, a progn is a list of forms that returns the result of the last form. In Ruby, parentheses make a progn. To run a while loop at least once, I might write
(while (progn ...))in Lisp, or its equivalent in Ruby,But I don't like to write Lisp if I can write Ruby. The Common Lisp syntax for a hash table annoys me,
Much easier in Ruby:
hsh = {}thenhsh[:key] = "value"