News for hackers. Stuff that matters.
Re:Making a Mini-Lisp: Introduction to Transpilers in JavaSc... by junke on Friday December 25, 2015 @03:55AM (#10790760)
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))

There are no comments on this comment yet.