jqconsole.RegisterMatching('(', ')', 'parents');
lisp.write = function(str){
- jqconsole.Write(str, 'jqconsole-output', false);
+ jqconsole.Write(xstring(str), 'jqconsole-output', false);
return str;
}
var startPrompt = function () {
// Start the prompt with history enabled.
- jqconsole.Write(lisp.evalString(pv, 1, make_lisp_string('(CL:PACKAGE-NAME CL:*PACKAGE*)')) + '> ', 'jqconsole-prompt');
+ jqconsole.Write(xstring(lisp.evalString(pv, 1, make_lisp_string('(CL:PACKAGE-NAME CL:*PACKAGE*)'))) + '> ', 'jqconsole-prompt');
jqconsole.Prompt(true, function (input) {
// Output input with the class jqconsole-return.
if (input[0] != ','){
try {
var vs = lisp.evalInput(mv, 1, make_lisp_string(input));
for (var i=0; i<vs.length; i++){
- jqconsole.Write(lisp.print(pv, 1, vs[i]) + '\n', 'jqconsole-return');
+ jqconsole.Write(xstring(lisp.print(pv, 1, vs[i])) + '\n', 'jqconsole-return');
}
} catch(error) {
jqconsole.Write('ERROR: ' + (error.message || error) + '\n', 'jqconsole-error');
}
} else {
- jqconsole.Write(lisp.compileString(pv, 1, make_lisp_string(input.slice(1))) + '\n', 'jqconsole-return');
+ jqconsole.Write(xstring(lisp.compileString(pv, 1, make_lisp_string(input.slice(1)))) + '\n', 'jqconsole-return');
}
// Restart the prompt.
startPrompt();
(defun atom (x)
(not (consp x)))
-(defun find (item list &key key (test #'eql))
+(defun find (item list &key (key #'identity) (test #'eql))
(dolist (x list)
(when (funcall test (funcall key x) item)
(return x))))
"return typeof(x) == 'object' && 'length' in x && x.type == 'character';")))
(define-builtin string-upcase (x)
- (code "make_lisp_string(" x ".join('').toUppercase())"))
+ (code "make_lisp_string(xstring(" x ").toUpperCase())"))
(define-builtin string-length (x)
(code x ".length"))
(define-builtin js-eval (string)
(if *multiple-value-p*
(js!selfcall
- "var v = globalEval(" string ".join(''));" *newline*
+ "var v = globalEval(xstring(" string "));" *newline*
"return values.apply(this, forcemv(v));" *newline*)
- (code "globalEval(" string ".join(''))")))
+ (code "globalEval(xstring(" string ")")))
(define-builtin %throw (string)
(js!selfcall "throw " string ";" *newline*))
(define-builtin oget (object key)
(js!selfcall
- "var tmp = " "(" object ")[" key "];" *newline*
+ "var tmp = " "(" object ")[xstring(" key ")];" *newline*
"return tmp == undefined? " (ls-compile nil) ": tmp ;" *newline*))
(define-builtin oset (object key value)
- (code "((" object ")[" key "] = " value ")"))
+ (code "((" object ")[xstring(" key ")] = " value ")"))
(define-builtin in (key object)
- (js!bool (code "((" key ") in (" object "))")))
+ (js!bool (code "(xstring(" key ") in (" object ")")))
(define-builtin functionp (x)
(js!bool (code "(typeof " x " == 'function')")))
(define-builtin write-string (x)
- (code "lisp.write(" x ".join(''))"))
+ (code "lisp.write(xstring(" x "))"))
(define-builtin make-array (n)
(js!selfcall
return array;
}
+function xstring(x){ return x.join(''); }
(ls-compile
`(progn
,@(mapcar (lambda (s) `(%intern-symbol (%js-vref ,(cdr s))))
- *literal-table*)
+ (remove-if-not #'symbolp *literal-table* :key #'car))
(setq *literal-table* ',*literal-table*)
(setq *variable-counter* ,*variable-counter*)
(setq *gensym-counter* ,*gensym-counter*)))))
-(print "testing")
-(print (eval '(+ 1 3)))
+(print "<<<")
+(print (find 'a '((b) (c) (a)) :key #'car))
+(print ">>>")
+
(test (= (eval '(+ 1 2)) 3))