Created
November 20, 2012 04:54
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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