Comments (7)
Note that in my fork, one can do
list(n)
which is equivalent to new Array(n)
Personally, I dont know why one would ever do [None]*n in RS, since presumably the reason to do so in python is to pre-allocate a list -- in RS that is better done with new Array(n).
from rapydscript.
Well, it preallocates a list to a certain value. For example, say I want a list of 1000 1
s: [1]*1000
. While it has overhead over the case of new Array(n)
, the user is guaranteed an initial state rather than an array of undefined
s. And good thing it's not C, where the user would get an array of god-knows-what.
from rapydscript.
Sure, but IMO the better way for that is to use
x = [None for i in range(n)]
or
x = list(None for i in range(n))
or
x = list(repeat(None, n)) (this of course require someone to write an itertools module for RS, but that is pretty easy to do.
And if you are worried about performance, this kind of expression can be detected and optimised by the compiler, just as it currently optimises for i in range(n):
loops.
from rapydscript.
Oh and just to be clear, my objection to this proposal is that this kind of ad hoc syntax addition leads to lots of inconsistency -- and that is something I dislike in programming languages. For instance, if this were to be implemented
a = [None] * 2
b = [None]
c = b * 2
a != c
from rapydscript.
Agreed, once again bitten by JavaScript's operator limitations. My original idea was to limit this syntax to [...]*n, similar to another inconsistency I already allow:
a[-1] # compiles to a[a.length-1] as a convenience feature
b = -1
a[b] # meaningless/undefined
from rapydscript.
Yeah, JS sucks :)
I think we should limit this kind of inconsistency to cases where no good alternative exists. In this case, using comprehensions is a good alternative.
from rapydscript.
Taking Kovid's advice on this.
from rapydscript.
Related Issues (20)
- append method does not compile to js push method HOT 1
- VSCode extension for syntax highlighting HOT 4
- cannot compare string HOT 3
- Typescript has problem compile RS --es6 output at class attributes HOT 2
- Why not support in-browser compiler? HOT 2
- enhancement: check for already reserved words like: enum HOT 18
- Cannot resolve python imports HOT 8
- Is that possible to parse python code to js AST? HOT 1
- fstring support. HOT 1
- How to keep all comments HOT 8
- Can't find python module that is installed and available? HOT 1
- Cannot catch ImportError HOT 2
- Cannot import from custom module in different directory HOT 5
- How to use RapydScript with JavaScript MutationObserver HOT 1
- Question about feasibility: option to use JS function syntax for nested functions, especially inside dicts/object-literals HOT 7
- How to run code snippets from tutorials on old Android? HOT 1
- Computed and negative slices
- parenthesized syntax HOT 2
- TypeError: undefined is not a function HOT 1
- Compiler issues 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 rapydscript.