Skip to content

Commit

Permalink
Merge branch 'main' into devops1
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor authored Apr 15, 2024
2 parents 2b4c3c1 + 5236b5f commit e03bc3b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 15 deletions.
42 changes: 42 additions & 0 deletions evaldo/builtins_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,48 @@ var Builtins_math = map[string]*env.Builtin{
}
},
},
"atan2": {
Argsn: 2,
Doc: "Returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.",
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:
switch val2 := arg1.(type) {
case env.Integer:
return *env.NewDecimal(math.Atan2(float64(val.Value), float64(val2.Value)))
case env.Decimal:
return *env.NewDecimal(math.Atan2(float64(val.Value), val2.Value))
default:
return MakeArgError(ps, 2, []env.Type{env.IntegerType, env.DecimalType}, "atan2")
}
case env.Decimal:
switch val2 := arg1.(type) {
case env.Integer:
return *env.NewDecimal(math.Atan2(val.Value, float64(val2.Value)))
case env.Decimal:
return *env.NewDecimal(math.Atan2(val.Value, val2.Value))
default:
return MakeArgError(ps, 2, []env.Type{env.IntegerType, env.DecimalType}, "atan2")
}
default:
return MakeArgError(ps, 1, []env.Type{env.IntegerType, env.DecimalType}, "atan2")
}
},
},
"atanh": {
Argsn: 1,
Doc: "Returns the inverse hyperbolic tangent.",
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.Atanh(float64(val.Value)))
case env.Decimal:
return *env.NewDecimal(math.Atanh(val.Value))
default:
return MakeArgError(ps, 1, []env.Type{env.IntegerType, env.DecimalType}, "atanh")
}
},
},
"pi": {
Argsn: 0,
Doc: "Return Pi constant.",
Expand Down
44 changes: 32 additions & 12 deletions planing.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Planning

---
## For 0.0.16 [+]

### Subc flag default [++]
Expand Down Expand Up @@ -39,6 +39,8 @@ is approachable than shell, which is contrary to what I thought.
We shell needs to support multiline, for some examples in docs to work. It can work the same as Regular shell, where if the last character is space it goes into multiline mode. In this case the space character should be made visible, via
something like middot or a newline like character. Or / and it could look for open parenthesis and go into multiple lines until it's closed.

---

## For 0.0.17 [+]

### Command line arguments improvement [++]
Expand Down Expand Up @@ -76,6 +78,8 @@ users .left-join groups 'group_id 'id
* function arguments are defines inside parenthesis, like math syntax usually is
* added math subcontext that includes typical math functions and math dialect, added first few

---

## For 0.0.18

### Rye force console, silent, do, help, dot behaviour [++]
Expand All @@ -93,19 +97,23 @@ Let state saves be encrypted with password and console_.....rye.enc ask for same
+ walk - useful for dialects, recursive algos, ...
+ xword, exword improvements, xword accepts args, equality - matching still works

### Import function , current path / script [--]
### Import function , current path / script [++]

Import function like "do load %file" but only looks for files local to the main script file or current script file basically.
Try to make import always relative to current script, so interpreter should have a concept of "current script" at loplevel. Maybe a specific "do" variant that is invoked in improt and is script location aware.

This would also be needed for loader errors in case of multiple files, so you know what file the loader failed.

### Improve errors with current path / script [--]
---

## For 0.0.19

### Improve errors with current path / script [+-]

At least loader errors should be able to display filename next to location. Toplevel code at least should also be aware of script filename, or should we look in direction of a stacktrace. Would we need to manually manage the stack of callees'
maybe only in debug flag since it would impact performance. Maybe functionname => number of calls so recursion doesn't push out the stack info.

### Liner with standard ansi colors, some improvements [--]
### Liner with standard ansi colors, some improvements [+-]

Test using standard colors, we will see if they work in Emacs ansi-term then, we will see if maybe general terminal theming works on them, also xterm.js probably has theming, test it, make build flag if possible, update refaktor/liner for it.

Expand All @@ -117,22 +125,32 @@ We could also try to add some low hanging fruit improvements of syntax highlighe
- More key combinations (ctrl-d, ...)
- Sole keys (pageup, pagedown)

## LATER

### Math dialect fwd

Let math dialect call rye functions also, not just builtins. It would be good if we could just use function "math" ... not context math and in it function math or math/do ... but still preserve the usable context too. Hmmmm ....
Let math dialect call rye functions also, not just builtins. It would be good if we could just use function "math" ... not context math and in it function math or math/do ... but still preserve the usable context too.

### Mod-words - experiment
Pratik is adding standard math functions from https://pkg.go.dev/math to the context.

`word:: ::word` would be mod-words and would allow changing existing values to words. So set-words would only create and fail if word already is set in current context. Mod-words would only change and fail if word
is not yet defined. We rarely modify at all ... to much modifying is a smell that code could be written better. word:: visually is not horrible, or that noticable, but jsut noticable enough I think. So let's do this and
we will see what practice shows. For starters just add it to loader but it could behave the same as set-word so we woule volontarily use it and see hot it looks and feels at all. If it seems ok, we change the interpreter.
### Devops context fwd [+-]

- Integrate relevant function from https://github.com/shirou/gopsutil [++]
- Create standard commands / utils like cd / ls / mkdir / cp / mv [+-]
- Integrate awesome script library for many standard piping commands https://github.com/bitfield/script [--]

### do_main build flag and Android test

if build flag do_main is used make the dot behaviour work even without the dot. Usefull for distributing binary and main.rye , also to test to produce a mobil APK with Fyne.

---

## LATER

### Mod-words - experiment

`word:: ::word` would be mod-words and would allow changing existing values to words. So set-words would only create and fail if word already is set in current context. Mod-words would only change and fail if word
is not yet defined. We rarely modify at all ... to much modifying is a smell that code could be written better. word:: visually is not horrible, or that noticable, but jsut noticable enough I think. So let's do this and
we will see what practice shows. For starters just add it to loader but it could behave the same as set-word so we woule volontarily use it and see hot it looks and feels at all. If it seems ok, we change the interpreter.

### MakeArgError improve output

We could try to display more information at MakeArgError. We know what type the value was. We don't but if we knew the names of arguments it would be even better. But builtins in Rye currently don't have named
Expand All @@ -158,7 +176,9 @@ rye . --do 'init' # TODO runs main.rye and function init
rye --do 'print 123 + 123' --quit # TODO
```

## Random ideas
---

## RANDOM

### ~~Smart history v01 (just ideas)~~

Expand Down
16 changes: 13 additions & 3 deletions tests/misc.rye
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,20 @@ section "Math functions"
equal { do\in math { atan 1 } } 0.7853981633974483
}


; TODO add sin and cos ... need PI constant
group "atan2"
mold\nowrap ""
{ { string } }
{
equal { do\in math { atan2 3 4 } } 0.6435011087932844
}

group "atanh"
mold\nowrap ""
{ { string } }
{
equal { do\in math { atanh 0.5 } } 0.5493061443340548
}

}


end

0 comments on commit e03bc3b

Please sign in to comment.