Skip to content

Instantly share code, notes, and snippets.

@weakish
Last active July 23, 2017 11:44
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 weakish/9360b137d6a0ce6fb8b666379ae7e174 to your computer and use it in GitHub Desktop.
Save weakish/9360b137d6a0ce6fb8b666379ae7e174 to your computer and use it in GitHub Desktop.
compare #ruby and #racket

Ruby and Racket

Why Racket? Why Lisp? listed 10 features of Racket, and concluded that:

with Racket I’ve been able to ren­der big­ger ideas into pro­grams more quickly, and with fewer bugs, than any lan­guage I’ve used be­fore (and there have been many— Ba­sic, C, C++, Perl, Java, JavaScript, Python, and oth­ers).

I checked the list against Ruby, and it turned out that, generally speaking, Ruby also fit into the feature list.

Ruby Is a Poor Man's LISP

  1. Everything is an expression.

    In Ruby, almost everything is an expression. For example, result = if a then b else c end.

  2. Every expression is either a single value or a list.

    In Ruby, everything is an object. Thus mostly the Ruby syntax can be reduced to object.method(parameters) For example, (+ 1 1) can be expressed as 1.+(1) in Ruby, where + is a method of 1. (Well it is usually written as 1 + 1, but this is just a syntax sugar.)

  3. Functional programming.

    Ruby supports higher order functions, closures (lambda or define_method) and you can write Ruby code that does not relying on state and without data mutation.

  4. Libraries and documentation

    Ruby has good documentation and a huge number of gems.

  5. Dr­Racket

    RubyMine

  6. X-expression

    a spe­cial na­tive data struc­ture that Lisps use to rep­re­sent HTML and other XML-ish data.

    n/a in Ruby

  7. Scribble

    • docco (written in Node.js, supporting a lot of languages including Ruby)
    • rocco (written in Ruby)
  8. Syn­tax trans­for­ma­tions.

    Ruby has powerful meta programming support. Though nothing can beat Lisp in this area. But if abused, macros / meta-programming will become a big trouble.

  9. New language

    Ruby are famous for creating (internal) DSLs. Though it seems racket is more powerful for implementing new language on it.

  10. Op­por­tu­ni­ties to par­tic­i­pate.

    Ruby are open to contributions. And there are several implementations to contribute: MRI, JRuby, Rubinius, mruby, etc.

This is not a surprise since Matz, the creator of Ruby, said that Emacs Lisp changed his life.

Two Racket Features Absent in Ruby

And there are two features of Racket that are absent in Ruby:

  1. Simple, consistent, and predictable syntax

  2. Typed Racket

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