Comments (4)
The syntax is up to choice here, we could do something like this, gdscript inspired:
fn max(a, b: int) {
return b if a < b else a
}
(notice the check expression is now in the middle)
from umka-lang.
I like this proposal. As for the syntax, I think that b if a < b else a
is very hard to compile for a single-pass compiler that generates bytecode on-the-fly. The compiler sees b
but does not know whether to insert a jump instruction before it to skip this b
if a < b
yields false
.
from umka-lang.
I would like ternary operators in umka. There are a lot of cases where they would be useful. As for the syntax proposed by @vtereshkov, I think it would imply that switch statement s and maybe even loops support this syntax too. Something to think about?
from umka-lang.
There is an unexpected issue with reference counting that we need to solve before we can implement the ternary operator. Consider the following code:
for i := 0; i < 2; i++ {
// ...
p = i % 2 == 0 ? new(int, 42) : new(int, 43)
// ...
}
Since every reference-counted function result is stored in a temporary local variable to prevent its premature death, the actually executed pseudocode is like this:
for i := 0; i < 2; i++ {
// ...
p = i % 2 == 0 ? {__temp0 = new(int, 42); __temp0} : {__temp1 = new(int, 43); __temp1}
// ...
decref(__temp0)
decref(__temp1)
}
This means that, e.g., __temp0
will get some reference-counted value only once (at iteration 0), but have its reference count decremented twice (at iterations 0 and 1). It may cause a dangling pointer.
Notice that we cannot call decref(__temp0)
immediately in the innermost {}
block, since __temp0
must at least outlive the assignment to p
.
from umka-lang.
Related Issues (20)
- when module isn't imported, it reports the member of the module not being found, not the module itself. HOT 1
- Improve error message for missing field
- Proposal: `new` taking a value as an argument HOT 4
- Functions for generating and checking for `NaN`s in the standard library HOT 1
- `floor`/`ceil` Bulit in calls work when referenced from another module, where `floor`/`ceil` don't exist.
- Can not load relative modules in emscripten HOT 5
- Standard library documentation
- Some proposals regarding `utf8.um`
- `std.rand()` generates alternating odd and even numbers HOT 1
- Optimize string element access HOT 2
- Inconsistent weak pointer semantics HOT 3
- Type inference for composite literals
- Untyped literals not working in multiple assignments
- Segmentation fault after a 'Duplicate identifier' error
- Allow weak pointers pointing to stack or global storage
- Proposal: Get rid of `repr()` in favor of `%v` format specifier in `printf()`
- should the interpreter trigger an error when a function that returns in all possible branches doesn't have an explicit return statement at the end? HOT 1
- Web requests HOT 6
- Remove unnecessary copies of reference-counted function results
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 umka-lang.