Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed Apr 23, 2024
2 parents d6b447d + a57e412 commit b34ab14
Show file tree
Hide file tree
Showing 10 changed files with 753 additions and 31 deletions.
16 changes: 16 additions & 0 deletions _sandbox/reading_material.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Reading material

## Rebol

## Error / failire handling

https://middlemost.com/failure-is-your-domain/

https://joeduffyblog.com/2016/02/07/the-error-model/
https://www.tritondatacenter.com/node-js/production/design/errors
https://youtu.be/Xhx970_JKX4
https://ericlippert.com/2008/09/10/vexing-exceptions/

## Concurrency

https://medium.com/techhappily/go-concurrency-2-2-patterns-and-idioms-error-handling-c18e4e083a74
6 changes: 6 additions & 0 deletions evaldo/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func MakeArgError(env1 *env.ProgramState, N int, typ []env.Type, fn string) *env
return env.NewError("Function " + fn + " requires argument " + strconv.Itoa(N) + " to be of : " + types + ".")
}

func MakeNativeArgError(env1 *env.ProgramState, N int, knd []string, fn string) *env.Error {
env1.FailureFlag = true
kinds := strings.Join(knd, ", ")
return env.NewError("Function " + fn + " requires native argument " + strconv.Itoa(N) + " to be of kind : " + kinds + ".")
}

func MakeRyeError(env1 *env.ProgramState, val env.Object, er *env.Error) *env.Error {
switch val := val.(type) {
case env.String: // todo .. make Error type .. make error construction micro dialect, return the error wrapping error that caused it
Expand Down
28 changes: 28 additions & 0 deletions evaldo/builtins_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,34 @@ var Builtins_math = map[string]*env.Builtin{
}
},
},
"ceil": {
Argsn: 1,
Doc: "Returns the least integer value greater than or equal to x.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch val := arg0.(type) {
case env.Integer:
return *env.NewDecimal(float64(val.Value))
case env.Decimal:
return *env.NewDecimal(math.Ceil(val.Value))
default:
return MakeArgError(ps, 1, []env.Type{env.IntegerType, env.DecimalType}, "ceil")
}
},
},
"cbrt": {
Argsn: 1,
Doc: "Returns returns the cube root of x.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch val := arg0.(type) {
case env.Integer:
return *env.NewDecimal(math.Cbrt(float64(val.Value)))
case env.Decimal:
return *env.NewDecimal(math.Cbrt(val.Value))
default:
return MakeArgError(ps, 1, []env.Type{env.IntegerType, env.DecimalType}, "cbrt")
}
},
},
"pi": {
Argsn: 0,
Doc: "Return Pi constant.",
Expand Down
Loading

0 comments on commit b34ab14

Please sign in to comment.