mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
eval: Add builtin lt and gt.
This commit is contained in:
parent
6ee16abba0
commit
4b05661c44
|
@ -79,6 +79,8 @@ func init() {
|
|||
&BuiltinFn{"-", wrapFn(minus)},
|
||||
&BuiltinFn{"mul", wrapFn(times)},
|
||||
&BuiltinFn{"div", wrapFn(divide)},
|
||||
&BuiltinFn{"lt", wrapFn(lt)},
|
||||
&BuiltinFn{"gt", wrapFn(gt)},
|
||||
|
||||
&BuiltinFn{"=", eq},
|
||||
&BuiltinFn{"deepeq", deepeq},
|
||||
|
@ -482,6 +484,24 @@ func divide(ec *EvalCtx, prod float64, nums ...float64) {
|
|||
out <- String(fmt.Sprintf("%g", prod))
|
||||
}
|
||||
|
||||
var ErrFalse = errors.New("false")
|
||||
|
||||
func lt(ec *EvalCtx, nums ...float64) {
|
||||
for i := 0; i < len(nums)-1; i++ {
|
||||
if !(nums[i] < nums[i+1]) {
|
||||
throw(ErrFalse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func gt(ec *EvalCtx, nums ...float64) {
|
||||
for i := 0; i < len(nums)-1; i++ {
|
||||
if !(nums[i] > nums[i+1]) {
|
||||
throw(ErrFalse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var ErrNotEqual = errors.New("not equal")
|
||||
|
||||
func eq(ec *EvalCtx, args []Value) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user