mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
47 lines
739 B
Go
47 lines
739 B
Go
package eval
|
|
|
|
import "github.com/elves/elvish/pkg/eval/vals"
|
|
|
|
// Basic predicate commands.
|
|
|
|
func init() {
|
|
addBuiltinFns(map[string]interface{}{
|
|
"bool": vals.Bool,
|
|
"not": not,
|
|
"is": is,
|
|
"eq": eq,
|
|
"not-eq": notEq,
|
|
})
|
|
}
|
|
|
|
func not(v interface{}) bool {
|
|
return !vals.Bool(v)
|
|
}
|
|
|
|
func is(args ...interface{}) bool {
|
|
for i := 0; i+1 < len(args); i++ {
|
|
if args[i] != args[i+1] {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func eq(args ...interface{}) bool {
|
|
for i := 0; i+1 < len(args); i++ {
|
|
if !vals.Equal(args[i], args[i+1]) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func notEq(args ...interface{}) bool {
|
|
for i := 0; i+1 < len(args); i++ {
|
|
if vals.Equal(args[i], args[i+1]) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|