common-lispparenscript

Is there a way to insert raw javascript in parenscript code?


The following code inserts third-party generated javascript as a string which will need to be eval'ed.

(ps (let ((x (lisp (json:encode-json-alist-to-string
                 '((:a . 1) (:b . 2))))))))

"(function () {
   var x = '{\"a\":1,\"b\":2}';
    return null; })();"

Is there a way to tell parenscript to insert a string unquoted?


Solution

  • Added this to parenscript's non-cl.lisp file:

    (define-expression-operator lisp-raw (lisp-form)
      `(ps-js:escape
        ,lisp-form))
    
    (defun lisp-raw (x) x)
    

    Result:

    (ps (let ((x (ps::lisp-raw (json:encode-json-alist-to-string
                     '((:a . 1) (:b . 2))))))))
    "(function () {
        var x = {\"a\":1,\"b\":2};
        return null;
    })();"