3 ms·
To expand a little on this, the article shows the parsed AST: { type: 'function', value: 'defn', children: [ { type: 'function_name',
by junke 11y ago
To expand a little on this, the article shows the parsed AST:
{
type: 'function',
value: 'defn',
children: [
{ type: 'function_name', value: 'average' },
{ type: 'arguments', children: [
{ value: 'x' },
{ value: 'y'}
]
},
{ type: 'function', value: '/', children: [...] }
]
}
The parenthesis-based surface syntax is directly translated into the above, which is IMO more verbose and contains no additional information. On the other hand, it is valid Javascript data.
So it looks like it is equivalent to manipulate the above form. Now, suppose you want to define a function which returns a form which performs a function call. We won't use macros, but simply a function that builds an AST. We can't write Javascript directly with this parser, so let's say there are primitive Lispy functions to build equivalent javascript trees:
(defn my-funcall ()
(js%hash (js%kv "type" "function")
(js%kv "value" "my-fn")
(js%kv "children"
(js%vector
(js%hash
(js%kv "value" 3))))))
... whereas, a lisp-based approach would be:
(defn my-function (list 'my-fun 3))