apfl/src/globals.apfl

170 lines
4 KiB
Text
Raw Normal View History

{builtins ->
if := builtins.if
== := builtins.==
> := builtins.>
< := builtins.<
>= := builtins.>=
<= := builtins.<=
+ := builtins.+
- := builtins.-
* := builtins.*
/ := builtins./
join := builtins.join
print := builtins.print
dump := builtins.dump
disasm := builtins.disasm
tostring := builtins.tostring
not := builtins.not
len := builtins.len
type := builtins.type
2023-03-07 20:37:37 +00:00
loop := builtins.loop
gc := builtins.gc
backtrace := builtins.backtrace
fopen := builtins.fopen
fread := builtins.fread
fwrite := builtins.fwrite
fclose := builtins.fclose
loadfile := builtins.loadfile
loadstring := builtins.loadstring
-serialize-bytecode := builtins.-serialize-bytecode
-unserialize-bytecode := builtins.-unserialize-bytecode
-named := { name f ->
builtins.set-func-name f name
}
2023-03-07 20:37:37 +00:00
while := { cond body ->
res := nil
loop {
if (cond) {
res = (body)
true
} {
false
}
}
res
}
for := {
end body ->
for 0 end body
start end body ->
if (> start end) {
for start -1 end body
} {
for start 1 end body
}
start step end body ->
end-not-reached := if (> step 0) {{ < start end }} {{ > start end }}
out := nil
while end-not-reached {
out = body start
start = + start step
}
out
}
& := { ~strings ->
join "" strings
}
partial := { f ~a1 ->
{ ~a2 ->
f ~a1 ~a2
}
}
compose := {
f -> f
f ~fs ->
fs-composed := compose ~fs
{ ~args ->
f (fs-composed ~args)
}
}
!= := -named '!= (compose not ==)
!> := -named '!> (compose not >)
!< := -named '!< (compose not <)
!>= := -named '!>= (compose not >=)
!<= := -named '!<= (compose not <=)
2023-03-07 20:37:37 +00:00
has := {
pred cmp y ->
{ x ->
cmp (pred x) y
}
pred y ->
has pred == y
}
keach := {
d?(has type 'dict) body ->
out := nil
builtins.iterate-dict d { k v ->
out = body k v
true
}
out
l?(has type 'list) body ->
out := nil
for (len l) { i ->
out = body i l@i
}
out
}
each := { container body ->
keach container { _ v ->
body v
}
}
# Dictionary of exported functions
[
'if -> if
'== -> ==
'> -> >
'< -> <
'>= -> >=
'<= -> <=
'+ -> +
'- -> -
'* -> *
'/ -> /
'join -> join
'print -> print
'dump -> dump
'disasm -> disasm
'tostring -> tostring
'not -> not
'len -> len
'type -> type
2023-03-07 20:37:37 +00:00
'loop -> loop
'while -> while
2023-03-07 20:37:37 +00:00
'for -> for
'gc -> gc
'backtrace -> backtrace
'fopen -> fopen
'fread -> fread
'fwrite -> fwrite
'fclose -> fclose
'loadfile -> loadfile
'loadstring -> loadstring
'-serialize-bytecode -> -serialize-bytecode
'-unserialize-bytecode -> -unserialize-bytecode
'& -> &
'partial -> partial
'compose -> compose
2023-03-07 20:37:37 +00:00
'has -> has
'!= -> !=
'!> -> !>
'!< -> !<
'!>= -> !>=
'!<= -> !<=
2023-03-07 20:37:37 +00:00
'keach -> keach
'each -> each
]
}