Comments (5)
π
from wren.
This seems a little weird to me from a design standpoint, but it also seems like idiomatic code would Just Work with these rules. Overall, I like it.
I wouldn't mind seeing a further distinction by saying that "top level" names cannot be reassigned. (In other words, they're like Java's final
.) I don't like that class names can be reassigned. It would help people decide when to use what type of name and could be useful in certain compiler optimizations. And finally, it would resolve the naming issue. We'd just call them "constants."
It would also become difficult to have useful mutable top-level variables, which could be both good and bad. You could always work around it by putting static variables in a top-level class or similar.
from wren.
I wouldn't mind seeing a further distinction by saying that "top level" names cannot be reassigned.
I thought about that too. I'm not deeply opposed to doing this, but I figured I'd leave this out at first in the name of minimalism. I'm trying to cut as many non-essential features as I can.
In particular, Wren doesn't have many features that exist purely on philosophical "it's easier to write maintainable code because of this" grounds. It's not that I don't like those kind of features, it's just that they don't increase the number of things a user can do, so I can sacrifice them without loss of expressiveness.
It would help people decide when to use what type of name and could be useful in certain compiler optimizations.
I don't think we'd get much optimization out of it. Before we could take advantage of this, we'd need a much more complex compiler pipeline in general. If we had that pipeline, we could automatically tell which variables never get assigned to, so it wouldn't need to be indicated in the source to begin with.
I think single-assignability is basically just for the end user.
And finally, it would resolve the naming issue. We'd just call them "constants."
There is that! :) I was thinking maybe "local" and "nonlocal" names. What do you think?
It would also become difficult to have useful mutable top-level variables, which could be both good and bad.
You can still declare lowercase names at the top level, and I think doing so will be common. It's definitely useful in the REPL and it's handy for scripts that have some top level code. The only limitation is that those lowercase top level names aren't visible inside classes. They're usable inside other imperative code at the top level.
from wren.
I figured I'd leave this out at first in the name of minimalism.
That's fair.
I don't think we'd get much optimization out of it.
There are some optimizations available even in a single-pass compiler. For example, zero-overhead constants.
var PI = 3.14159
class Circle {
circumference {
// This line can compile exactly like:
// return 2*3.14159*_r
return 2*PI*_r
}
}
This also makes it possible to constant fold the 2*PI
. Although if the class is defined before the constant, none of this can happen easily, so that's a little weird.
Another example is the expression x is Num
. Since the compiler knows that Num
always refers to the built-in Num
class (unless it's been shadowed, which the compiler would know about), it could have a special bytecode just for this type of check. (It might not be worth doing, but it becomes an option.)
from wren.
Yeah, I guess we might be able to do constant folding. I wouldn't rule that out at some point, though I'm not sure if it's worth the effort. We could only constant fold trivial expressions involving known operations primitive types.
In the rare places where that is a bottleneck, it's easy for the user to just do that manually:
var TWO_PI = PI * 2
Not that I'm advocating making the user manually do microoptimizations like this. But if it's a reasonably simple thing that the user can handle at their end, I think it's reasonable to keep the language simpler. :)
from wren.
Related Issues (20)
- List.count returns a negative value for huge lists HOT 2
- [Feature] Pipe Operator for Function Calls HOT 53
- [RFC] Object.responds(_) method HOT 10
- [RFC] Add routines for degrees/radians conversions HOT 21
- [RFC] Adding a `Tuple` with language support HOT 11
- [RFC] Adding `const` versions of `Object`s. HOT 9
- Class reflection for embedding HOT 3
- [RFC] `veery` lang transpiler to `wren` lang HOT 3
- [RFC] Object method message passing syntax HOT 28
- [RFC] Add `static Object.typeOf(_)` (and deprecate `Object.type` ?) HOT 9
- How can i stop wren script running? HOT 3
- Calling wren method handle from inside a bound foreign method body HOT 5
- Whitespace bugs? HOT 4
- Serialize (suspended) fibers or serialize the vm HOT 4
- wren_debug.c should use vm->config.writeFn instead of printf HOT 1
- Should we document this aspect of for loop control variable behavior?
- How do I pass a foreign object to a function call? HOT 3
- is Wren dead? HOT 2
- Where causes code to be called twice HOT 3
- How to return other foreign class obj from a foreign class ? HOT 7
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 wren.