Live data from Hacker News

Cirru – An editor for AST

cirru.org

31–40 of 53 posts

Re: Cirru – An editor for AST

#31
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!).

Re: Cirru – An editor for AST

#32
post #10
post #2

Some context : https://medium.com/cirru-project/stack-editor-programming-by...

So the units in Stack editor is not “files”, it’s “functions”(or “definitions”). And we navigate by functions, edit by functions, and finally program by functions. It’s more like the program is running and we got a call stack here. We edit the code that’s collected for a specific purpose without constantly switching the context. It can be faster. This is a very neat idea.

getting OT now but check out http://witheve.com

Re: Cirru – An editor for AST

#34
post #31

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…

That'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)

:).

Re: Cirru – An editor for AST

#35
post #33

Paredit[1] is (almost) from the gods as an AST editor. The only issue I have is that it doesn't automatically reformat your code so it is not only always syntactically correct, but also properly formatted at the same time. [1] https://www.emacswiki.org/emacs/ParEdit

Paredit does try and keep the subtree you're editing correctly indented. Moreover, it has a paredit-reindent-defun command (bound to M-q), which reindents the whole tree you're editing. Bind it to whatever auto-reindent facility Emacs has (Electric keys? I don't know - I never had a need to configure it for myself.), and there you go. Personally, I'm fine with manual M-q on code if I see the identation got messed up.

Re: Cirru – An editor for AST

#36
post #9

What I want is for the editor to be aware of the semantics of the language and offer me language-unique tools to edit code, also to generate and work on macros, in the language it's editing , or at least one that is close enough to it I don't have to switch gears in order to get a tough task done. Otherwise it really doesn't improve on a text editor. All of these things would require a ton of work, so I stick with Su…

> I've yet to see one that could effectively work with dynamic languages That is a hard nut to crack, a dynamic language will frustrate static analysis.

Lisp languages cheat on that by pulling relevant metadata from the image after you loaded the code in. So if you just open a project as text, SLIME won't help you find e.g. a list of places that call a particular function - but after you load it into your Lisp image, cross-referencing features become available.

Re: Cirru – An editor for AST

#37
post #29

Earlier quoted context omitted.

Have you tried VSCODE, their open language server protocol means that most popular languages have code completion, refactoring, code lens and debugging support. It's totally free and open source. I was a hard core JetBrains user but vscode has been amazing. They even got minimap like sublime in last release. Every month they move at an amazing velocity working on features devs ask for. I feel it's the modern democrat…

No. But I have a friend who writes in C# and he showed me quite some tips on VS Code. I know it's very smart and IDE understands code in semantics, that can be a lot better than Stack Editor that only recognize the structure. I will keep an eye on that.

Language Server, which parent mentioned, is kinda independent from VSCode and provides the groundwork for most of the fancy language level stuff. You could look into integrating langserv into your editor to get the best of both worlds.

Re: Cirru – An editor for AST

#39
post #33

Paredit[1] is (almost) from the gods as an AST editor. The only issue I have is that it doesn't automatically reformat your code so it is not only always syntactically correct, but also properly formatted at the same time. [1] https://www.emacswiki.org/emacs/ParEdit

Paredit does try and keep the subtree you're editing correctly indented. Moreover, it has a paredit-reindent-defun command (bound to M-q), which reindents the whole tree you're editing. Bind it to whatever auto-reindent facility Emacs has (Electric keys? I don't know - I never had a need to configure it for myself.), and there you go. Personally, I'm fine with manual M-q on code if I see the identation got messed up.

M-q is useful, but something more useful IMO would be the same feature but one that removes unneeded white space within the sexpr between expressions and keep everything indented. A contrived example:

   (defun   x ()   
   (+ x   x)) => (defun x () 
                     (+ x x))

Re: Cirru – An editor for AST

#40
post #31

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…

That'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) :).

Ah, 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)

Post reply on HN