Comments (5)
Minor nitpick: We might want to call them prefixNeg
and prefixNot
...
from effekt.
-(x + y)
is perfectly valid and very commonly used mathematically expression. I have never seen someone write 0 - (x + y)
instead. Do you have an example where this appears as a code smell?
For example, the normal distribution is defined as N(x; mu, sigma) ~ e^(-((mu - sigma)^2 / (2 * sigma^2))
. I have never seen it given as N(x; mu, sigma) ~ e^(0 - ((mu - sigma)^2 / (2 * sigma^2))
instead. If someone wanted to implement this in Effekt, I would imagine the normal user would like to stick as close as possible to common mathematical notations and not having to think about how to desugar it.
Edit: A perhaps easier example: negative fractions. It is more convenient and more common to write - (1 / 2)
instead of 0 - (1 / 2)
.
from effekt.
Yes, right. That's a typo... edited
from effekt.
Why would we want to write -(1+2)
? For prefixNot
I can understand it, but -(1+2)
is a smell in my opinion. Is there a usecase where you think this is better than 0 - (1 + 2)
?
Another prefix operator that could be useful is bitwise negation ~x
where typically we wouldn't desugar it into "subtraction".
from effekt.
Ok, here are two points to address
-
spaces: a lot of Effekt code is written by students (in theses, etc.). Since we do not have a nice formatter, they end up using the most creative way to use whitespaces. I would be very happy if
1-x
would just fail and force them to write1 - x
. Ideally, also1- x
should fail. -
-
as unary operator. This is mostly personal taste. I have a dislike for prefix and postfix operators. I almost always writex = x + 1
instead ofx++
. I am also happy to write0 - x
instead ofx
, like here:
effekt/libraries/common/effekt.effekt
Lines 386 to 387 in a4d5f58
Actually, I typically write -1 * ...
instead of 0 - ...
and I think it works pretty well in your example as well.
The normal distribution is a bit of a red hering, since you use other operators that typically also don't exist in PLs (like ^
for exponentiation).
from effekt.
Related Issues (20)
- Tests for `exception` stdlib. HOT 1
- [To be discussed] Allow match guards as boolean expressions
- Rename constructors of collections HOT 1
- Wrong primitive names in LLVM I/O HOT 2
- String-related problems on the LLVM backend HOT 5
- Top-level constants in the LLVM backend
- `equals` does not work properly in chez Backends
- Convention for error reporting and aborting HOT 1
- Store string literals in their unescaped form HOT 6
- Functions outside of the event loop segfault on LLVM
- Overeager JS inliner forgets to parenthesize HOT 1
- Consistently name generated ML binary
- `array::copy(from, start, to, offset, length)` copies one element more
- References escape their region when using `var` HOT 1
- More descriptive comments when generating LLVM from Machine
- Unexpected end of input on opening brace after newline HOT 1
- Existentially quantified types are defined in outer scope HOT 2
- Investigate using memory use markers in the generated LLVM
- Renamer stack-overflows on large test suites 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 effekt.