3 ms·
What is the benefit of this? It seems like oftentimes editing ASTs is much more verbose than code that would generate an AST. For example, in python's builtin
by closed 10y ago
What is the benefit of this? It seems like oftentimes editing ASTs is much more verbose than code that would generate an AST.
For example, in python's builtin ast library, writing the variable
> x
in AST is..
> Expr(value=Name(id='x', ctx=Load()))
while assigning the variable
> x = 1
in AST is..
> Assign(targets=[Name(id='x', ctx=Store()),], value=Num(n=1))
There is a lot packed in there! I looked at the site, and a few videos, but the goal and motivation for this project has gone way over my head (probably my fault!).
- TeMPOraL 10y agoThat's because the representation of that AST seems to be defined in terms of Python's objects, so it looks unwieldy. Compare with Lisp: Code: x AST: x Code: (let ((x 5)) (+ x x)) AST: (let ((x 5)) (+ x x)) And as for the very little syntactic sugar most Lisps have: Code: 'x AST: (quote x) :).
- closed 10y agoAh, that helps a lot--thanks for the example! Most ASTs I've have seen look much more gruesome than that. That AST looks straight delightful. (actually now that I think about it, R may do something a bit similar)
- jiyinyiyong 10y agoAnd we can map Cirru AST to a language AST like I did in http://script.cirru.org/ http://script.cirru.org/ ;)