Permalink
Browse files

add `and` function, make `cdr` and `list?` more resilient

  • Loading branch information...
1 parent 647abd9 commit 515523ff9417665609c3b373c8144ebc1d613262 @defunkt committed May 29, 2009
Showing with 17 additions and 2 deletions.
  1. +17 −2 jasper.js
View
@@ -127,7 +127,10 @@ var Jasper = (function(global) {
}
this['cdr'] = function(sexp) {
- return sexp.slice(1, sexp.length)
+ if (sexp && sexp.slice)
+ return sexp.slice(1, sexp.length)
+ else
+ return sexp
}
// essentials
@@ -136,14 +139,26 @@ var Jasper = (function(global) {
}
this['if'].special = true
+ this['and'] = function() {
+ var ret, i
+
+ for (i = 0; i < arguments.length; i++) {
+ if (ret === false) return false
+ ret = jeval(this, arguments[i])
+ }
+
+ return ret
+ }
+ this['and'].special = true
+
this['empty?'] = function(sexp) {
return !sexp || sexp.length == 0
}
// alias
var emptyp = this['empty?']
this['list?'] = function(sexp) {
- return sexp.constructor == Array
+ return sexp && sexp.constructor == Array
}
var listp = this['list?']

0 comments on commit 515523f

Please sign in to comment.