Last active
March 16, 2018 09:49
-
-
Save WillNess/baa358b72cff8a2ce869c1ec2ec3c32f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apply f args = eval [f, ...[[QUOTE, a] | a <- args]...] [] % McCarthy-original-LISP-paper | |
| eval e a | atom e = head [v | [n, v] <- a, n == e] | |
| | otherwise = | |
| case e of | |
| [QUOTE, x] -> x | |
| [FUNCTION, x] -> [FUNARG, x, a] | |
| [EQ, x, y] -> eval x a == eval y a | |
| [CONS, x, y] -> [eval x a, ...eval y a...] | |
| [CAR, x] -> head ( eval x a ) | |
| [CDR, x] -> tail ( eval x a ) | |
| [ATOM, x] -> atom ( eval x a ) | |
| [COND, ...xs...] -> head [eval c a | [t, c] <- xs, eval t a] | |
| [[LAMBDA, b, c], ...xs...] -> eval c [...[[n, eval x a] | n <- b | x <- xs]..., ...a...] | |
| [[LABEL, n, x], ...xs...] -> eval [x, ...xs...] [[n, [LABEL, n, x]], ...a...] | |
| [[FUNARG, f, d], ...xs...] -> eval [f, ...[[QUOTE, eval x a] | x <- xs]...] d | |
| [x, ...xs...] -> eval [eval x a, ...xs...] a % was: bug: | |
| %% ...[eval x a | x <- xs]...] a % args twice eval'd | |
| %% eval e = \a -> case e of [QUOTE, x] -> x | |
| %% compile e = case e of [QUOTE, x] -> \a -> x |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hypothetical alternative syntax for parallel comprehensions / zipN :
it is much easier to have guards this way, too.
it'd work by having an imaginary
uncurry zipNstuck in there automatically.example use: a code golf's TIO
another example: primes:
here too it's cumbersome to add guards with the current PLC syntax:
so we end up using the explicit zip - which apparently is less optimizable...