Created
September 18, 2011 16:47
-
-
Save krawaller/1225258 to your computer and use it in GitHub Desktop.
This file contains 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
calc = (tool,a1,a2,toolarg)-> | |
if tool is "relation" | |
throw "Only one relation allowed!" if a2.type is "relation" | |
type:"relation",objs:[a1,a2],val:toolarg | |
else if a2.type is "relation" | |
type: "relation",val:a2.val, objs:[calc(tool,a1,a2.objs[0]),a2.objs[1]] | |
else if a2.isblock | |
o tool,[a1,a2] | |
else if tool in ["sum","product"] and tool is a2.type | |
o tool, [a1].concat a2.objs | |
else if not (tool is "sum" and a2.type is "product") and (a2.type in ["sum","product"] or (tool is "power" and a2.type is "fraction")) | |
o a2.type, [calc(tool,a1,a2.objs[0])].concat a2.objs[1..] | |
else | |
o tool,[a1,a2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment