Skip to content

Instantly share code, notes, and snippets.

@ympbyc
Created February 2, 2012 10:49
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 ympbyc/1722859 to your computer and use it in GitHub Desktop.
Save ympbyc/1722859 to your computer and use it in GitHub Desktop.
jslisp oop
(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)))
@ympbyc
Copy link
Author

ympbyc commented Feb 2, 2012

consider including forrange to the list of builtin functions.
consider supporting the special form let to get users being able to create local variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment