Skip to content

Instantly share code, notes, and snippets.

@madis
Last active October 12, 2022 06:27
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 madis/67433993c28d77586ae707c06e6ace7e to your computer and use it in GitHub Desktop.
Save madis/67433993c28d77586ae707c06e6ace7e to your computer and use it in GitHub Desktop.
Clojure vs Ruby

Clojure vs Ruby

Simplest way to try these, without having to install anything:

  1. Clojure(Script) http://clojurescript.net/
  2. Ruby https://replit.com/languages/ruby

Or to try these on your machine

  1. Clojure via Babashka https://babashka.org/
  • download the latest release
  • put bb command on your $PATH e.g. export PATH=/where/babashka/executable/bb`
  • start REPL rlwrap bb --repl and paste in the lines
  1. Ruby via https://www.ruby-lang.org/es/documentation/installation/
  • once you have the ruby executable you should also have irb (interactive Ruby) which is a Ruby REPL
  • run irb and paste in the code

Good materials for Clojure:

; LISP (Clojure)
(def friend "Jean")
(defn greet [name]
(println (str "Hello " name)))
(greet friend)
(map greet ["Jean" "Madis" "Nayib"])
(defn welcome [name level]
(if (< level 5)
(str "Hello " name)
(str "Hello " name ", nice to see you. How are you")))
(defn welcome [name level]
(str "Hello " name (cond (> level 5) "nice to see you. How are you")))
(welcome "Jean" 1)
(welcome "Jean" 10)
# Ruby
friend = "Jean"
def greet(name)
print "Hello #{name}\n"
end
greet(friend)
["Jean", "Madis", "Nayib"].map { |name| greet(name) }
class Politeness
def initialize(name)
@name = name
end
def welcome
greeting = "Hello #{@name}"
if @level > 5
greeting += ", nice to see you. How are you?"
end
greeting
end
def level=(new_level)
@level = new_level
end
end
politeness = Politeness.new("Jean")
politeness.level = 1
politeness.welcome
politeness.level = 10
politeness.welcome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment