Comments (2)
This is a general question I guess for what the REPL should do for top-level statements that can be expressionized. Currently we do not expressionize, but perhaps we should in the REPL? Compare these examples:
🐱> i .= 5
... while i < 10
... i++
...
9
🐱> do
... i .= 5
... while i < 10
... i++
...
9
🐱> function f
... i .= 5
... while i < 10
... i++
... f()
...
[ 5, 6, 7, 8, 9 ]
Those 9
return values kind of magical. I guess it's somehow what eval
(or the Node equivalents that we use) defines as the last expression, which is different how Civet defines it.
So I think it'd be nice to wrap the top level in an IIFE at the Civet level so the last Civet expression gets returned to the REPL. Kind of an extension of the code I added recently to handle top-level await
in this way. Amusingly, I think the easy way to wrap in an IIFE is async do
, because do
is "too smart" and only uses braces if the block is top-level so won't be returned. So it'd be async do
in all cases, and await
the result, even if there aren't any top-level await
s (but just like we currently do if there were).
from civet.
Actually, I think this might be an issue worth extending beyond the REPL. There are settings where we write scripts where the last expression is meaningful. eval
is one example. My SVG Tiler software is another; though export
s are encouraged, mapping files can also be the last expression of the file.
To support these use cases, I propose a "civet iife"
or similar directive that wraps the whole thing in an IIFE, so that the last Civet expression gets returned; effectively, nothing is at the top level anymore, so a final do
or comptime
or whatever will get implicitly returned. IIFEs have other uses cases (isolation of variables in nonstrict mode), which is why CoffeeScript does them by default too. So it could have other applications too. But in particular the REPL could use this, I think. (Not totally sure about top-level await. Maybe that could be part of it too? Like it could be an async
IIFE wrapper in that case, for environments that don't support top-level await too, and you can await the resulting promise.) Thoughts?
from civet.
Related Issues (20)
- Deep `....`rest operator HOT 2
- `::#` doesn't work in type position HOT 3
- Eliminating `return` after `loop` in some cases HOT 3
- `yield x; loop` has strange behavior
- Trailing pipe or property access should expressionize statement HOT 1
- ASI fails before symbol-typed property
- Pipeline unwrapping should add refs
- `&` does not work in indented operator application
- `&` doesn't always work in `if` statement HOT 1
- if type errors
- `comptime` object literal with ES6 method generates invalid JS HOT 1
- `for own` doesn't work inside `comptime` HOT 1
- Comptime generator functions
- Cannot optional-chain prototype
- Empty array matching still broken
- `--inline-map` suppresses comptime serialization errors
- `guard`-`else` HOT 4
- Stray semicolon in class body causes ParseError
- `&` is not compiled to `$ => $` in specific contexts HOT 1
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 civet.