Skip to content

Commit c94c9de

Browse files
authored
Merge pull request #3 from moonbitlang/logic-not
[ME-0002] logical not operator
2 parents 04bfb78 + f2e8160 commit c94c9de

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Logical not operator
2+
3+
* Proposal: [ME-0002](https://github.com/moonbitlang/moonbit-evolution/blob/0002-orsuccess/proposals/0002-logical-not-operator.mbt.md)
4+
* Author: [Yorkin](https://github.com/Yoorkin)
5+
* Review and discussion: [Github issue](https://github.com/moonbitlang/moonbit-evolution/pull/3)
6+
7+
## Introduction
8+
9+
In MoonBit, the `not` function takes a boolean value and returns its negation,
10+
as implemented in `moonbitlang/core` . We propose the `!expr` syntax to negate a
11+
boolean expression, which aligns with the conventions of other programming languages.
12+
13+
## Motivation
14+
15+
Since `not` is a function, boolean expressions must be wrapped in parentheses
16+
when used. This can be cumbersome and deviates from the conventions of other
17+
programming languages that use a logical operator for negation. Furthermore,
18+
we already have `&&` and `||` for logical operations. This inconsistency may
19+
confuse users from diverse programming backgrounds and lead to misunderstandings
20+
by LLMs during code generation.
21+
22+
## Solution
23+
24+
We propose introducing a logical operator `!` that can be used in expressions
25+
to negate a boolean value:
26+
27+
```moonbit
28+
fn f(x : Bool) -> String {
29+
if !x {
30+
"false"
31+
} else {
32+
"true"
33+
}
34+
}
35+
36+
let false_value = !true
37+
let true_value = !!true // !(!true)
38+
```
39+
40+
The `not` function will still be available for pipeline syntax and use as a
41+
higher-order function.

0 commit comments

Comments
 (0)