Comments (11)
My favorite syntax in Enso is
fib n-1 n-2
- I don't think it has any bad impact on mathematical precedence. It is natural to read it as:fib (n - 1) (n - 2)
. Do we foresee a solution where meaning offib n-1 n-2
remains unchanged?
I don't think that will change. We are considering either grouping adjacent mathematical operations or ignoring whitespace when comparing precedence of mathematical operators, and neither would affect that.
from enso.
mathematical operators
Another question which is not clear to me is: how do we differentiate between operators and mathematical operators? Aren't all operators the same in Enso?
I think the distinction we would want could be described as value-level (math, logic, comparison) vs functional operators (lambda operator, application operators including space, dot operator). User-defined operators could be handled based on their precedence character, with the addition of recognizing <-
and ->
subsequences as indicating non-mathematical operations (as we already ascribe properties based on the presence of these sequences).
from enso.
My idea would be to introduce another precedence level in parser. I don't think this involves any part of engine beside parser (please correct me if I'm wrong). Now, we hierarchical precedence discovery - first level is "spaced" and "non-spaced". Then in these groups we apply precedences of operators. We could add another group to the top level, so we will have "spaced", "non-spaced", "math" and then just resolve precedences in these groups. Just my idea, might not be the best one, but I shared it because maybe it will be useful to someone :)
from enso.
Expression | Interpretation (current) | Interpretation (Solution 1) | Interpretation (Solution 2) |
---|---|---|---|
|
|
| |
|
|
| |
|
|
| |
|
|
|
unchanged |
|
|
|
unchanged |
|
|
unchanged | |
|
|
unchanged |
Footnotes
from enso.
Solution 0: Math-consistent spacing
Maintain the uniform application of space-precedence rules, but warn if the result is inconsistent with mathematical precedence.
Solution 1: High precedence math
Place math operators in a precedence level between unspaced non-math and spaced non-math.
Current logic:
- Reduce each sequence of terms that contains no spaces.
- Reduce the remainder.
New logic:
- Reduce each sequence of terms that contains no spaces or symmetrically-unspaced binary mathematical operators (but if a binary math operator has an unspaced term on exactly one side, reduce it to an operator section).
- Reduce each sequence consisting of
X (F X)+
(regex notation), whereX
is a non-operator term andF
is a binary mathematical operator. - Reduce the remainder.
Solution 2: Space-invariant math precedence
Redefine the effect of spacing in terms of precedence-modification.
Current logic (after refactoring):
- When an operator is unspaced, its precedence is modified to be higher than any spaced operator.
New logic:
- When an operator is unspaced, its precedence is modified to be higher than any spaced operator, but when comparing precedence of mathematical operators unmodified precedence is used.
Discussion
Complexity for language users:
- Solution 0 allows the simplest language rules, but users unfamiliar with space-precedence may be surprised by a warning if they use spacing inconsistent with mathematical precedence.
- Solution 1 can be explained in terms of a precedence hierarchy, but it would no longer be possible for any operators (or function application) to have a higher precedence than mathematical operators.
- Solution 2 achieves space-invariant precedence within mathematical subexpressions without losing the high precedence of function application, though it requires a "modified precedence" concept that may be less intuitive than the precedence hierarchy concept of Solution 1.
Implementation
Parsing changes
- Solution 1: 3 points
- Solution 2: 5 points
Warnings
- Parser: Each solution would require different logic for detecting unexpected spacing. The parser has no mechanism for emitting warnings; this would need this to be added to the JNI and JS bindings.
- Solution 0/1: 2 points
- Solution 2: 1 point
- Compiler (? points): The compiler would receive a span->warnings map from the parser. I don't know whether it can make use of this data structure directly, or each warning needs to be attached to the IR with the corresponding span--the latter may take some work. The IDE doesn't need to receive these warnings from the compiler, since the IDE parses too; but the compiler should print them when run standalone, and maybe have a mode to treat parser warnings as errors when running tests etc.
Library changes
parse_all_enso_files.sh
can be used to detect expressions whose interpretation have been changed. If there are few they could be updated by hand; if there are many, I could add refactoring suggestions to the warnings, and create a tool that can apply them (2 points).
Total (excluding compiler changes to print warnings)
- Solution 0: 2 points
- Solution 1: 7 points, assuming automated refactoring is needed
- Solution 2: 6-8 points, depending on whether automated refactoring turns out to be needed
from enso.
My favorite syntax in Enso is fib n-1 n-2
- I don't think it has any bad impact on mathematical precedence. It is natural to read it as: fib (n - 1) (n - 2)
. Do we foresee a solution where meaning of fib n-1 n-2
remains unchanged?
from enso.
mathematical operators
Another question which is not clear to me is: how do we differentiate between operators and mathematical operators? Aren't all operators the same in Enso?
from enso.
The main ones, which I felt we should keep the space precedence on, were .
and ->
.
But I would guess we would also want <|
and |>
.
from enso.
Refinement notes:
- Let's add tests where we check if applying warnings' suggestions creates the same AST without warnings.
- As we assume to auto-fix node edits with warnings, let the warnings be called "(auto) formatting"
- But actually applying (or displaying) them in GUI is not in scope of this task.
from enso.
Keziah Wesley reports a new STANDUP for today (2024-07-16):
Progress: Implemented new precedence rules, reviewed changed parses. It should be finished by 2024-07-18.
Next Day: Next day I will be working on the #10366 task. Work on warnings.
from enso.
Keziah Wesley reports a new STANDUP for yesterday (2024-07-17):
Progress: Finished implementation; updated libraries; added new linter to run
tool and CI. It should be finished by 2024-07-18.
Next Day: Next day I will be working on the #10473 task. Start on context errors
from enso.
Related Issues (20)
- Support for reading and writing Tableau Hyper files
- Add support for drilldown in XML
- Stopping a project from dashboard immediately starts a new Language Server HOT 4
- Lack of `namespace` field in project's `package.yaml` makes PM classify it as a plain directory HOT 3
- Drop-down widget for possible `Any.to` conversion targets.
- Long opening of a file in backend leads to ydoc failures HOT 2
- Reconnecting to binary websocket seems to not working
- 'Additional Options (how to get to zoom, etc) has stopped working.
- Add context sensitive help to right side panel HOT 1
- Local Project Manager is not showing any existing projects HOT 1
- Move Component browser help HOT 1
- When Reopening a Project, no dynamic widgets available.
- New Component Browser
- Component Browser Modes
- Update Component Browser List filtering. HOT 1
- Suspended application of default arguments playing badly with warnings and causing weird behaviour HOT 1
- Add retries to Ydoc requests
- Implement transactional Table Upload / Update / Delete Rows for Snowflake backend HOT 1
- Unexpected comparator warning in `Vector_Spec`
- Fix `Count_Distinct` on a Boolean column in Snowflake
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enso.