Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created February 11, 2017 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/6c4c4456964844da366e78ddef488530 to your computer and use it in GitHub Desktop.
Save deque-blog/6c4c4456964844da366e78ddef488530 to your computer and use it in GitHub Desktop.
let e = add [ cst(1)
, cst(2)
, mul [cst(0), var("x"), var("y")]
, mul [cst(1), var("y"), cst(2)]
, add [cst(0), var("x") ]
]
-- Pretty printing an expression
prn e
> "(+ 1 2 (* 0 x y) (* 1 y 2) (+ 0 x))"
-- Optimization of an expression
prn (optimize e)
> "(+ 3 (* 2 y) x)"
-- Partial evaluation of an expression
prn $ partial (Map.fromList [("y", 0)]) e
> "(+ 3 x)"
-- Getting the list of variable names in an expression
dependencies e
> fromList ["x","y"]
-- Full evaluation of an expression
eval (Map.fromList [("x", 1), ("y", 0)]) e
> 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment