GaloisInc / saw-script

The SAW scripting language.
BSD 3-Clause "New" or "Revised" License
442 stars 63 forks source link

Define a `map` function (like `for`, but non-monadic) #2083

Open RyanGlScott opened 3 months ago

RyanGlScott commented 3 months ago

Currently, SAWScript offers a for function for iterating over a list in a monadic fashion:

for : {m, a, b} [a] -> (a -> m b) -> m [b]

For many use cases, however, it would be more convenient to iterate over a list without needing a monad m. For these scenarios, we should offer a map function:

map : {a, b} (a -> b) -> [a] -> [b]

SAWScript does not currently offer this, but it could easily be added.

sauclovian-g commented 3 months ago

FWIW, you can find here a bunch of other list ops needed on another project that are (AFAIK) not and maybe should be in the standard library.