javascriptcommon-lispprimitiveparenscript

How to translate a javascript code snippet using `Array.from` to Parenscript (Common Lisp library)?


I have this code snippet working on the browser using JavaScript:

Array.from(document.querySelectorAll('input'))

Thedocument.querySelectorAll('input') gets a NodeList and Array.from converts it to an array.

I am trying to translate it to Parenscript inside a function as:

(ps:chain  array (from  (ps:chain document (query-selector "input")))))

This is close:

"array.from(document.querySelector('input'));"

There is even a little trick to achieve the capital letter with the hyphenating of -array:

(ps:ps   (ps:chain  -array (from  (ps:chain document (query-selector "input")))))

Which generates:

"Array.from(document.querySelector('input'));"

But it does not work as expected when called. It returns an empty string.

How can I fix it?

Obs.: I am using Common Lisp/SBCL.


Solution

  • Currently, Parenscript only returns primitive values which are:

    1. Undefined;
    2. Boolean;
    3. Number;
    4. String;
    5. BigInit; and,
    6. Symbol.

    The code document.getElementsByTagName('input') is not returning a string, it is returning some objects. That's why it fails to work.

    Source.