Created
February 2, 2012 10:49
-
-
Save ympbyc/1722859 to your computer and use it in GitHub Desktop.
jslisp oop
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 forrange (lambda (i to fn) | |
(if (>= (+ i 1) to) | |
(fn i) | |
(begin (fn i) | |
((. arguments callee) (+ i 1) to fn))))) | |
(= (. Object prototype get) | |
(lambda (attr) (get this attr))) | |
(= (. Number prototype foreach) | |
(lambda (fn) (forrange 0 this (lambda (i) (fn i)))))) | |
(= (. Array prototype foreach) | |
(lambda (fn dummy) | |
(begin (= dummy this) | |
((. (. this length) foreach) (lambda (i) (fn ((. dummy get) i))))))) | |
((. (vector "hoge" 1 "お湯") foreach) (lambda (item) (alert item))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
consider including forrange to the list of builtin functions.
consider supporting the special form let to get users being able to create local variables.