Inspired by the book Write Yourself a Scheme in 48 Hours.
I decide to write myself a simple interpreter of Wolfram Language to learn more about Haskell as well as
achieve a deeper understanding about Mathematica, which is the desktop IDE for Wolfram Language.
Prebulid binary files are available on the release page
Features
This interpreter is intended to mimic every exact detail of Wolfram Language, including but not limited to its syntax, semantic,
expression structure, evaluation details, etc. (All the scripts below were executed in the REPL session of the mmaclone program)
The program support nearly all Wolfram Language's syntax sugar, infix operators as well as their precedence. E.g., inequality expression chain is parsed to the same AST with Wolfram Language.
Pattern test facility is of the same semantic with `Wolfram Language`'s.
In[15]:= {{1,1},{0,0},{0,2}}/.{x_,x_}/;x+x==2 -> a
Out[15]= {a,{0,0},{0,2}}
In[16]:= {a, b, c, d, a, b, b, b} /. a | b -> x
Out[16]= {x,x,c,d,x,x,x,x}
In[17]:= g[a_*b__]:=g[a]+g[Times[b]]
In[18]:= g[x y z k l]
Out[18]= g[k]+g[l]+g[x]+g[y]+g[z]
In[19]:= q[i_,j_]:=q[i,j]=q[i-1,j]+q[i,j-1];q[i_,j_]/;i<0||j<0=0;q[0,0]=1;Null
In[20]:= q[5,5]
Out[20]= 252
For more information please refer to the project wiki (still under construction).
Features that are likely to be added in future versions:
(Some serious design errors are exposed during development, which I consider are inhibiting
the project from scaling up. So currently my primary focus would be on refactor
rather than adding new features/functions)
More mathematical functions (Sin, Cos, Mod etc...)
Arbitrary precision floating arithmetic using GMP(GNU Multiple Precision Arithmetic Library), currently arbitrary integer, double and rational number are supported.
More built-in functions (Level, Import, Derivativeetc...)
More sophisticated pattern matching
head specification (of the form Blank[Head], currently it only support list type)(Implemented)
Pattern Test(Implemented)
BlankSequence, BlankNullSequence(Implemented)
Other pattern matching expression, like Verbatim, Longest
RecursionLimit(Implemented)
Negative index e.g. in Part
Negative level specification
Curried function e.g. f[a][b] (currently it will throw an error if one is trying to attach value to
the curried form through Set or SetDelayed)
Use iPython as front end
Replace String implementation with more efficient Text(Implemented)
请发表评论