Skip to content

Commit

Permalink
add core map,apply
Browse files Browse the repository at this point in the history
  • Loading branch information
fabjan authored and kanaka committed May 2, 2021
1 parent ce49400 commit bfaeb3b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions impls/sml/core.sml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ val coreException = [
| _ => raise NotApplicable "'throw' requires one argument")
]

fun splatArgs [LIST l] = l
| splatArgs [VECTOR v] = v
| splatArgs (x::xs) = x::(splatArgs xs)

val coreFn = [
SYMBOL "map",
FN (fn [FN f, LIST l] => LIST (List.map (fn x => f [x]) l)
| [FN f, VECTOR v] => LIST (List.map (fn x => f [x]) v)
| x => raise NotApplicable "map requires a function and a list or vector"),

SYMBOL "apply",
FN (fn (FN f::args) => f (splatArgs args)
| x => raise NotApplicable "apply requires a function and a list or vector")
]

val coreNs = List.concat [
coreList,
coreIo,
Expand All @@ -168,5 +183,6 @@ val coreNs = List.concat [
coreString,
coreAtom,
coreException,
coreFn,
coreMath
]

0 comments on commit bfaeb3b

Please sign in to comment.