(ecase (%read-char stream)
(#\'
(list 'function (ls-read stream)))
+ (#\( (list-to-vector (%read-list stream)))
(#\\
(let ((cname
(concat (string (%read-char stream))
"return typeof x === 'object' && 'length' in x;")))
(define-builtin aref (array n)
- (concat "(" array ")[" n "]"))
+ (js!selfcall
+ "var x = " "(" array ")[" n "];" *newline*
+ "if (x === undefined) throw 'Out of range';" *newline*
+ "return x;" *newline*))
(define-builtin aset (array n value)
- (concat "(" array ")[" n "] = " value))
+ (js!selfcall
+ "var x = " array ";" *newline*
+ "var i = " n ";" *newline*
+ "if (i < 0 || i >= x.length) throw 'Out of range';" *newline*
+ "return x[i] = " value ";" *newline*))
(defun macro (x)