To clarify my point, and I hope this does clarify things:
To achieve the idealized human-readable form when we are writing and reading lisp code, it is assumed that it's extremely complicated to take conventional lisp code, such as
Code: Select all
(sqrt (+ (* (- (/ (+ 1 2) (+ 2 3)) 10) 2) 1))
and allow a user to read it and write it as
(not just for this case, but for any valid lisp code)
All of this needs to be possible while still saving code in the conventional lisp style in the background.
The reason it's so complicated to implement is because a user could easily type ( and ) characters, or add more operators, and the software that needs to turn that into valid lisp code would be too easily confused without an intermediate step.
The solution I'm suggesting is an intermediate step of turning the conventional lisp code into a full abstract syntax tree which has 0 parentheses in the tree, and only one operator per branch.
Code: Select all
<list> ┬ sqrt
└ <list> ┬ +
├ 1
└ <list> ┬ *
├ 2
└ <list> ┬ -
├ 10
└ <list> ┬ /
├ <list> ┬ +
│ ├ 1
│ └ 2
└ <list> ┬ +
├ 2
â”” 3
this tree is then reformatted into the readable code, such as
to the end user.
the end user may then write more operators, like instead of 1 + 1, they type 1 + 2 * 3, and a new branch is created in the tree, in the background, because a new operator was introduced (and only one operator can be on one branch). There would be unique rules for mathematical operators, such as identical operators can be repeated on the same branch (1 + 2 + 3 + 4 + 5 would just turn into + 1 2 3 4 5 on the same branch).
Parentheses could be typed by the end user, and turned into another branch, or leaf, on the abstract syntax tree in the background.
In summary, by converting lisp into a tree, then the tree into human readable syntactic sugar, you don't actually impose any character-typing limitations on the user, and you don't actually change the syntax of lisp, you merely format it differently, kind of like displaying data to a user in the form of a table, rather than a comma separated list. Different formatting can help readability. It's primarily useful for representing data structures. In lisp, code is data. That's why I feel this solution is unique to lisp.