Created
September 7, 2011 11:03
-
-
Save dahlia/1200298 to your computer and use it in GitHub Desktop.
Lisp Tests
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
11 | |
4 | |
hello, world | |
hello, world | |
<!DOCTYPE html> |
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
11 | |
4 | |
hello, world | |
3 | |
<!DOCTYPE html> |
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
--- Apply and Function as Value | |
Hello | |
Hello | |
--- Lexical Scope (let) | |
1 | |
7 | |
12 | |
7 | |
1 | |
--- Lambda | |
3 | |
--- Higher-Order Function | |
36 | |
9 | |
--- Lexical Scope (lambda) | |
3 | |
10 | |
5 | |
20 | |
10 |
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
(display (. "hello world" Length)) | |
(display (. (quote (1 2 3 4)) Count)) | |
(display (String.Join ", " (quote ("hello" "world")))) | |
(display ((. String Join) ", " (quote ("hello" "world")))) | |
(using System) | |
(using System.Net) | |
(using System.IO) | |
(let ((client (new WebClient))) | |
(let ((data (client.OpenRead "http://dahlia.kr/"))) | |
(let ((reader (new StreamReader data))) | |
(display ((. (reader.ReadLine) Trim))) | |
(reader.Close)) | |
(data.Close))) |
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
(display (len "hello world")) | |
(display (len (quote (1 2 3 4)))) | |
(display ((. ", " join) (quote ("hello" "world")))) | |
(display ((. "abcdabcda" count) "a")) | |
(import urllib2) | |
(let ((u (urllib2.urlopen "http://dahlia.kr/"))) | |
(display ((. (u.readline) strip)) | |
(u.close)) |
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
(display "--- Apply and Function as Value") | |
(define display2 display) | |
(apply display2 (quote ("Hello"))) | |
(display2 "Hello") | |
(display "--- Lexical Scope (let)") | |
(let ((+ -) (- +)) | |
(display (+ 4 3)) | |
(display (- 4 3)) | |
(setf! - *) | |
(display (- 4 3))) | |
(display (+ 4 3)) | |
(display (- 4 3)) | |
(display "--- Lambda") | |
(display ((lambda (a b) (+ a b)) 1 2)) | |
(display "--- Higher-Order Function") | |
(display ((lambda (op a b) (op a (op a b))) * 3 4)) | |
(display (((lambda () (lambda (a) (* a a)))) 3)) | |
(display "--- Lexical Scope (lambda)") | |
(display (((lambda (a) (lambda (b) (/ a b))) 9) 3)) | |
(define account | |
(lambda (balance) | |
(lambda (incr) | |
(setf! balance (+ balance incr)) | |
balance))) | |
(define hong (account 10)) | |
(define choi (account 5)) | |
(display (hong 0)) | |
(display (choi 0)) | |
(display (hong 10)) | |
(display (choi 5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment