
Cirru – An editor for AST - pcmonk
http://cirru.org/
======
chadrs
Reminds me of

[http://www.lamdu.org/](http://www.lamdu.org/)

while trying to remember the name I discovered:

[https://www.facebook.com/notes/kent-beck/prune-a-code-
editor...](https://www.facebook.com/notes/kent-beck/prune-a-code-editor-that-
is-not-a-text-editor/1012061842160013/)

[http://jetbrains.com/mps](http://jetbrains.com/mps)

[https://github.com/cxxtree/cxxtree](https://github.com/cxxtree/cxxtree)

[http://www.greenfoot.org/frames/](http://www.greenfoot.org/frames/)

[http://unisonweb.org/](http://unisonweb.org/)

[https://github.com/chrisdone/structured-haskell-
mode](https://github.com/chrisdone/structured-haskell-mode)

[https://www.emacswiki.org/emacs/ParEdit](https://www.emacswiki.org/emacs/ParEdit)

[https://github.com/projectured/projectured](https://github.com/projectured/projectured)

~~~
sedachv
Note that some of these (like ParEdit) are just macros for text-oriented
editors, and not real structured editors.

The earliest structure editor was Interlisp's original structure editor for
teletypes, which worked on Lisp lists directly. Editing on teletypes is not
anything like editing on video terminals - you are basically forced to edit
one line at a time instead of viewing the whole file. That's how _ed_ works.
Structured editing made a lot of sense for teletypes because you did not have
to worry about putting delimiters in the wrong place, which is very hard to
spot when you are doing things one line at a time.

There was an Interlisp structured editor (maybe more than one? I'm not sure)
written for video terminals in the 1970s. On video terminals structured
editing loses a lot of its advantages over text editing and structured editors
fell out of style in the 1990s.

------
vinceguidry
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 Sublime for now. Text isn't that
bad.

IDEs are kinda close, but I've yet to see one that could effectively work with
dynamic languages. RubyMine is interesting-looking, but seems to want to
impose a lot of its opinions on your workflow. I don't really see how RubyMine
would really be that much better than Sublime and a terminal.

~~~
jiyinyiyong
Author here. Your are right. Graphical editor is just a favor of myself and
happened to make implementing this features easier. If you are skilled enough
to parser code in text and build a tree underneath, it's definitely the same
result that you got smart IDE that helps write code faster.

BTW, I don't know much about building IDEs, so I won't analyze code by myself
and let the editor recognize the code. Could be very tough work.

~~~
nojvek
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 democratic IDE

~~~
jiyinyiyong
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.

~~~
zokier
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.

------
maelito
Some context : [https://medium.com/cirru-project/stack-editor-programming-
by...](https://medium.com/cirru-project/stack-editor-programming-by-
functions-a961f1d9555c)

~~~
rafiei
_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.

~~~
catshirt
getting OT now but check out [http://witheve.com](http://witheve.com)

------
didibus
The benefits of AST editors is that the source can be stored and revisioned
controlled much better. And the AST can be projected to different
visualizations or text representation.

------
RubyPinch
I find myself wanting to edit the textual version of the AST itself, as the
tree interface seems too cryptic

edit: I'm guessing its probably a bug that is confusing me the most, as I'm
getting both a inline tree and a indented tree at the same time for a node

~~~
jiyinyiyong
Author here. Try [http://text.cirru.org](http://text.cirru.org) see if it fits
your mind. I guess people always hate news things that breaking others. Me
too....

~~~
RubyPinch
That does feel a lot clearer

I guess my main thing is I don't know if I should trust my understanding of
the tree display or not

Perhaps, as a sort-of training assistant, have the resulting "code" optionally
appear beside the editor?

e.g. [https://i.imgur.com/92stVmi.png](https://i.imgur.com/92stVmi.png)

(I also noticed that you are looking for TCO for python, In some cases Coconut
can do TCO, and can compile to python, but its somewhat of an unweildly tool
to use

[http://coconut.readthedocs.io/en/v1.2.2/DOCS.html#function-d...](http://coconut.readthedocs.io/en/v1.2.2/DOCS.html#function-
definition) )

~~~
jiyinyiyong
I agree. I'm just too lazy to add that. Actually on
[http://cirru.org/](http://cirru.org/) there's a button named "Show me data".
By clicking at the button you get the data in vectors, which is almost the
thing you shown in the png. Personally I'm already familiar enough to read AST
from the UI with nothing like assistant.

I think reading by a JavaScript programmer, TCO is "Tail Call Optimization".

------
ungzd
May be good idea for mobile devices, where editing text is hard but it's
possible to make usable tree editing UI.

~~~
TeMPOraL
One idea for a side project I have (that I lack time for) is an app (or maybe
a keyboard, I don't know how far one can push Android's keyboards, but from
what I saw it could be quite far) for editing Lisp code. Could be useful with
e.g. ECL app, but personally, I'd use that to do quick fixes / small bursts of
development while away from home / office.

------
closed
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
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)

:).

~~~
closed
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)

~~~
jiyinyiyong
And we can map Cirru AST to a language AST like I did in
[http://script.cirru.org/](http://script.cirru.org/) ;)

------
kruhft
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](https://www.emacswiki.org/emacs/ParEdit)

~~~
TeMPOraL
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.

~~~
kruhft
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))

~~~
sedachv
You can write an interactive function that runs _fill-paragraph_ (or whatever
_M-q_ is bound to in the mode you are using), then deletes multiple spaces
(something like [http://stackoverflow.com/questions/8674912/how-to-
collapse-w...](http://stackoverflow.com/questions/8674912/how-to-collapse-
whitespaces-in-a-region)).

That would not be a good default because some people, like me, like to align
their code in columns (for example, things like _let_ clauses).

What I would like to see come as an Emacs default is _just-one-space_ working
on regions with the behavior you describe.

~~~
kruhft
What I've noticed after using paredit is that I'm doing a lot less paren
matching (well none) and a lot more white space clean up, so I think such a
function would be very useful to run as a hook on insert char. Since the
program is always syntactically correct, it might almost work...

And @sedachv, thanks for Parenscript. It makes Javascript almost...well, now I
can work it it :) Much appreciated.

------
jiyinyiyong
Author here. Added another quick video on Youtube, check this out
[https://news.ycombinator.com/item?id=13774829](https://news.ycombinator.com/item?id=13774829)

Guess I need help from someone because English is not my mother language, and
I even got cough these days.

------
wyldfire
But ... which language(s)' AST? Clojure? It feels like we could all use more
context here.

~~~
jiyinyiyong
Author here. Theoretically it can any language that has a simple way to
generate code from a simple AST. But in my case it's Clojure because in Lisp I
can generate code from data easily with
[https://github.com/brandonbloom/fipp/](https://github.com/brandonbloom/fipp/)
. I wrote several posts before I guess it's can not be explained with only two
pages.

~~~
wyldfire
Ok, great. If nothing else, the title of this submission could clarify the
context.

~~~
jiyinyiyong
I uploaded a new video, hope it explains my ideas better.
[https://youtu.be/zsiYPppEDp0](https://youtu.be/zsiYPppEDp0)

------
steego
I love seeing prototypes like this. Excellent job!

One suggestion: I would implore you to add undo sooner rather than later.

~~~
jiyinyiyong
That would be a huge feature. I got some ideas but have no time to finish it.
It's can be something like something like Redux devtoos, because it's not just
files...

------
amenghra
reminds me
[http://tratt.net/laurie/blog/entries/an_editor_for_composed_...](http://tratt.net/laurie/blog/entries/an_editor_for_composed_programs.html)

------
iamcreasy
Can someone explain what is the use of an AST editor?

------
microcolonel
I don't want to be a downer, but the visual presentation is awful, I could not
work with the nesting direction changing all the time.

If there were a good language-specific pretty printer, and it looked like
regular text in the language, I could probably stomach it.

~~~
jiyinyiyong
I've used it to write web pages for nearly a year, so I believe we can. The
problem is, like people may hate using indentations, they just hate. There's
also a text version of Cirru [http://text.cirru.org](http://text.cirru.org) ,
but withouth benefits of structural editing.

~~~
microcolonel
I'll give it a try instead of just criticizing it. :- )

I've used Paredit, which is similar in concept; I think it's really cool if it
can be generalized well to languages which aren't LISP.

~~~
jiyinyiyong
Maybe Prettier? It's for JavaScript:

[https://github.com/jlongster/prettier](https://github.com/jlongster/prettier)
[https://twitter.com/search?q=atom%20prettier&src=typd](https://twitter.com/search?q=atom%20prettier&src=typd)

