Comments (8)
@jayvdb ternary operator was supported from day 1, it's just the JS syntax, not the Python one. As mentioned in the README and other discussions, the goal of the project was never 100% Python compatibility. The goal was to balance clarity and consistency of Python with JavaScript (and yes, there are cases when JS syntax is actually more consistent/clear than Python). To me, the ternary syntax of JS seemed cleaner than that of Python because it doesn't flip the conditional and if
block. The ng version of the project attempts to stay more pure to the Python syntax (including objects/arrays) at the expense of some performance. You're more than welcome to use that, if it's more suitable to your needs.
from rapydscript.
This is implemented in rapydscript-ng
from rapydscript.
kovidgoyal/rapydscript-ng@9c508b2
from rapydscript.
FYI, still on the fence about this one. In your version, you changed the syntax for ternary conditional, so the choice of ?
makes sense. In my version, like in CoffeeScript, the whitespace before that ?
would completely change its meaning, which I don't like.
from rapydscript.
Yeah, I can see how it is a problem for you. I got rid of the JS variant of the ternary conditional since there was no need for it, and it frees up the ?
operator for this purpose. Given the prevalanece of undefined and null throughout the JS ecosystem, I for one find an existential operator very useful.
from rapydscript.
Agree, I've gotten quite accustomed to using it in Swift.
I think you replaced the ternary with Pythonic conditional (http://stackoverflow.com/questions/394809/does-python-have-a-ternary-conditional-operator) rather than getting rid of it completely, is that not the case? I find myself using the ternary quite often to make the assignment more clear:
a = condition ? then : else
vs
if condition:
a = then
else:
a = else
What I don't like about Python's version of ternary, however, is that it flips then
and condition
.
from rapydscript.
Yes, I replaced it with python's ternary conditional operator. Since I write a lot of python code, python's ternary conditional has become quite natural for me :) Although, I agree, that it seemed awkward when I started using it. And I too use the ternary conditional a lot, in all languages I write.
Also, given that most of RapydScript's syntax is pythonic, it made sense to use the python form.
from rapydscript.
As this discussion is covering the Python ternary operator, I'd like to note that it would be really nice the Python syntax was supported. I was surprised it is still not supported.
To have the same effect without it, and still have valid Python code, one needs to create a function for the branch logic, and because it is an expression that could appear anywhere (print(1 if 1 else 2)
), that function needs to be injected into the scope of the expression, before the expression.
Glad to see that rapydscript-ng supports this; I'll need to use that until if-exp support is added to the original project.
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.