add fast.spl, improving repl

This commit is contained in:
Daniella / Tove 2024-10-23 15:52:47 +02:00
parent a8a2616a41
commit 5c8875eb55
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
3 changed files with 92 additions and 1 deletions

87
spl/fast.spl Normal file
View file

@ -0,0 +1,87 @@
"#stream.spl" import
"#http.spl" import
func ls { files | "." list-files }
func ls@ { files | list-files }
func cd { | chdir }
func cat { | read-file }
func output { | with thing ;
thing gettype "array" eq
thing gettype:ends-with<^Iter> or
dup if {
thing:foreach<&println>
}
not if {
thing _str println
}
}
func *m { | swap :ends-with }
func m* { | swap :starts-with }
func # { | swap :filter }
func ? { | swap :map }
func times { | :iter }
func \ { | pop }
func ~@ { | env:get<"HOME"> "/" concat swap concat }
func ~ { | env:get<"HOME"> }
func $ { v | env:get }
func . { | output }
func ex { | with s ; [ ^sh ^-c s ] command-wait; }
func ex% { | command-wait; }
func into { | with input file ;
input gettype any<[ / "array" eq \ / "bytearray" eq \ ]> not if { input _str:to-bytes =input }
file 1 StreamTypes:file:create
dup :write-exact;<input>
:close;
}
func tcp { stream |
StreamTypes:tcp:create
}
func curl { s | bcurl:to-str }
func bcurl { bytes | with url ;
1 if {
url:readf<"{}:{}/{}"> dup if {
=url
url:0 url:1 _int "GET" "/" url:2 concat net:http:Request:new
2 stop
} pop
url:readf<"{}:{}"> dup if {
=url
url:0 url:1 _int "GET" "/" net:http:Request:new
2 stop
} pop
url:readf<"{}/{}"> dup if {
=url
url:0 80 "GET" "/" url:1 concat net:http:Request:new
2 stop
} pop
url:readf<"{}"> dup if {
=url
url:0 80 "GET" "/" net:http:Request:new
2 stop
} pop
"invalid url" panic
} :send:body
}
construct _shell_array_ext {
idx
;
next { any | with this ;
this:idx 0 or dup ++ this:=idx this:sget
}
}
include _shell_array_ext in array
include _Iter in array
func any { bool | with o checks ;
0 checks:foreach<{ | o swap call if { pop 1 } }>
}

View file

@ -1,7 +1,9 @@
"fast.spl" import
func main { mega | with args ;
"Welcome to the SPL REPL!" println
"Enter any code after the cursor to execute it.\n" println
"Enter any code after the cursor to execute it.\nfast.spl (for shell-like functions) is included.\n" println
"REPL" =program-name
while { 1 } {

View file

@ -10,6 +10,7 @@ pub const MESSAGING: &str = include_str!("../spl/messaging.spl");
pub const ASSEMBLE: &str = include_str!("../spl/assemble.spl");
pub const ISBPL: &str = include_str!("../spl/isbpl.spl");
pub const REPL: &str = include_str!("../spl/repl.spl");
pub const FAST: &str = include_str!("../spl/fast.spl");
pub const PURE: &str = include_str!("../spl/pure.spl");
pub const TIME: &str = include_str!("../spl/time.spl");
pub const SERVER: &str = include_str!("../spl/server.spl");
@ -30,6 +31,7 @@ pub fn register(runtime: &mut Runtime) {
insert("assemble.spl", ASSEMBLE);
insert("isbpl.spl", ISBPL);
insert("repl.spl", REPL);
insert("fast.spl", FAST);
insert("pure.spl", PURE);
insert("time.spl", TIME);
insert("server.spl", SERVER);