diff --git a/evaldo/builtins.go b/evaldo/builtins.go index cd1d3096..ba834a5d 100644 --- a/evaldo/builtins.go +++ b/evaldo/builtins.go @@ -7399,7 +7399,11 @@ var builtins = map[string]*env.Builtin{ Argsn: 1, Doc: "", Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object { - return *env.NewString(strings.Join(os.Args[2:], " ")) + if len(os.Args) > 1 { + return *env.NewString(strings.Join(os.Args[2:], " ")) + } else { + return *env.NewString("") + } // block, _ := loader.LoadString(os.Args[0], false) // return block }, diff --git a/evaldo/builtins_math.go b/evaldo/builtins_math.go index 36878ca1..cdcedc2b 100644 --- a/evaldo/builtins_math.go +++ b/evaldo/builtins_math.go @@ -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.", diff --git a/main.go b/main.go index 811bdda1..20db9b93 100644 --- a/main.go +++ b/main.go @@ -98,9 +98,19 @@ func main() { evaldo.ShowResults = !*silent + var code string + if *do != "" { + code = *do + } + // Check for --help flag if flag.NFlag() == 0 && flag.NArg() == 0 { - main_rye_repl(os.Stdin, os.Stdout, true, false) + if Option_Do_Main { + ryeFile := dotsToMainRye(".") + main_rye_file(ryeFile, false, true, *console, code) + } else { + main_rye_repl(os.Stdin, os.Stdout, true, false) + } } else { // Check for --help flag if *help { @@ -108,11 +118,6 @@ func main() { os.Exit(0) } - var code string - if *do != "" { - code = *do - } - args := flag.Args() // Check for subcommands (cont) and handle them if len(args) > 0 { diff --git a/planing.md b/planing.md index 65635171..8b14f945 100644 --- a/planing.md +++ b/planing.md @@ -1,5 +1,5 @@ # Planning - +--- ## For 0.0.16 [+] ### Subc flag default [++] @@ -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 [++] @@ -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 [++] @@ -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. @@ -117,11 +125,25 @@ 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. + +Pratik is adding standard math functions from https://pkg.go.dev/math to the context. + +### 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 @@ -129,10 +151,6 @@ Let math dialect call rye functions also, not just builtins. It would be good if 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. -### 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. - ### 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 @@ -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)~~ diff --git a/serve_wasm.rye b/serve_wasm.rye index 5ca9a913..b155cf41 100644 --- a/serve_wasm.rye +++ b/serve_wasm.rye @@ -5,7 +5,7 @@ rye .needs { http } -new-server ":8085" +http-server ":8085" |handle "/" new-static-handler %wasm |serve diff --git a/tests/misc.rye b/tests/misc.rye index a7336348..5be3f7d2 100644 --- a/tests/misc.rye +++ b/tests/misc.rye @@ -382,10 +382,32 @@ section "Math functions" equal { do\in math { atan 1 } } 0.7853981633974483 } +<<<<<<< HEAD +======= +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 + } + + +>>>>>>> 5236b5f75f0221676742cd7157b7d35167348d33 ; TODO add sin and cos ... need PI constant } +<<<<<<< HEAD end +======= +end +>>>>>>> 5236b5f75f0221676742cd7157b7d35167348d33 diff --git a/util/microliner.go b/util/microliner.go index 714fc867..fa7877c5 100644 --- a/util/microliner.go +++ b/util/microliner.go @@ -464,6 +464,9 @@ startOfHere: line = line[:pos] s.needRefresh = true } + case "l": + s.eraseScreen() + s.needRefresh = true } } else if next.Alt { switch strings.ToLower(next.Key) { diff --git a/wasm/ryeshell/index.html b/wasm/ryeshell/index.html index 0bdf9861..fdfca722 100644 --- a/wasm/ryeshell/index.html +++ b/wasm/ryeshell/index.html @@ -261,7 +261,7 @@