feat: implement ! operator for all core types with proper truthiness semantics
Add native `!` methods to Null, Object, Num, String, and List classes so that `!` works reliably on any value. Null returns `true`, all other types return `false` since they are considered truthy. Update documentation to describe the operator as returning the logical complement and add comprehensive tests for each type. Also fix the `all` method test to use a truthy string instead of expecting a runtime error.
This commit is contained in:
@@ -29,7 +29,7 @@ Boolean values. There are two instances, `true` and `false`.
|
||||
|
||||
### **!** operator
|
||||
|
||||
Negates the value.
|
||||
Returns the logical complement of the value.
|
||||
|
||||
> !true
|
||||
false
|
||||
@@ -150,6 +150,15 @@ It is a runtime error if `block` is not a function.
|
||||
|
||||
**TODO**
|
||||
|
||||
## Null Class
|
||||
|
||||
### **!** operator
|
||||
|
||||
Returns `true`, since `null` is considered [false](control-flow.html#truth).
|
||||
|
||||
> !null
|
||||
true
|
||||
|
||||
## Num Class
|
||||
|
||||
**TODO**
|
||||
@@ -242,6 +251,12 @@ It is a runtime error if `other` is not a number.
|
||||
|
||||
**TODO**
|
||||
|
||||
## Object Class
|
||||
|
||||
### **!** operator
|
||||
|
||||
Returns `false`, since most objects are considered [true](control-flow.html#truth).
|
||||
|
||||
## String Class
|
||||
|
||||
A string of Unicode code points stored in UTF-8.
|
||||
|
||||
Reference in New Issue
Block a user