Skip to content

Instantly share code, notes, and snippets.

@Sam-Serpoosh
Created November 20, 2012 04:54
Show Gist options
  • Save Sam-Serpoosh/4116136 to your computer and use it in GitHub Desktop.
Save Sam-Serpoosh/4116136 to your computer and use it in GitHub Desktop.
Just a very simple program from SICP book both in Lisp and Ruby to show how much more elegant the code will be when the philosophy of "Code as Data" exist in a language!
(define make-pair (a, b)
(lambda (pick)
(cond (= pick 1) a)
(cond (= pick 2) b)))
(define car (x) (x 1))
(define cdr (x) (x 2))
def make_pair(a, b)
lambda do |pick|
case pick
when 1
return a
when 2
return b
end
end
end
def car(picker)
picker.call(1)
end
def cdr(picker)
picker.call(2)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment