File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ target
Original file line number Diff line number Diff line change
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.
You can’t perform that action at this time.
0 commit comments