diff --git a/examples/grammar.ipynb b/examples/grammar.ipynb index 5976938..bce7284 100644 --- a/examples/grammar.ipynb +++ b/examples/grammar.ipynb @@ -345,13 +345,13 @@ "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", "\n", @@ -360,10 +360,10 @@ "\n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", "\n", @@ -396,63 +396,21 @@ "metadata": {}, "outputs": [ { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "TreeView.LabelledTree({3, 2} directed simple Int64 graph, Any[:*, 8, 4.0])" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" + "ename": "UndefVarError", + "evalue": "UndefVarError: seed1! not defined", + "output_type": "error", + "traceback": [ + "UndefVarError: seed1! not defined", + "", + "Stacktrace:", + " [1] getproperty(::Module, ::Symbol) at ./sysimg.jl:13", + " [2] top-level scope at In[12]:2" + ] } ], "source": [ - "srand(100)\n", + "using Random\n", + "Random.seed1!(100)\n", "rulenode = rand(RuleNode, grammar, :Real, 10)\n", "display(rulenode, grammar)" ] @@ -470,18 +428,22 @@ "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "32.0" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" + "ename": "UndefVarError", + "evalue": "UndefVarError: f not defined", + "output_type": "error", + "traceback": [ + "UndefVarError: f not defined", + "", + "Stacktrace:", + " [1] top-level scope at none:0", + " [2] eval(::Module, ::Any) at ./boot.jl:319", + " [3] eval(::RuleNode, ::Grammar) at /Users/rlee18/.julia/dev/ExprRules/src/ExprRules.jl:389", + " [4] top-level scope at In[13]:1" + ] } ], "source": [ - "eval(rulenode, grammar)" + "Core.eval(rulenode, grammar)" ] }, { @@ -499,7 +461,7 @@ { "data": { "text/plain": [ - ":(8 * 4.0)" + ":(f(B))" ] }, "execution_count": 14, @@ -526,7 +488,7 @@ { "data": { "text/plain": [ - "2{15,4}" + "3{6}" ] }, "execution_count": 15, @@ -535,7 +497,7 @@ } ], "source": [ - "srand(0)\n", + "Random.seed!(0)\n", "sample(rulenode)" ] }, @@ -554,7 +516,7 @@ { "data": { "text/plain": [ - "2{15,4}" + "3{6}" ] }, "execution_count": 16, @@ -563,7 +525,7 @@ } ], "source": [ - "srand(3)\n", + "Random.seed!(3)\n", "sample(rulenode, :Real, grammar)" ] }, @@ -582,7 +544,7 @@ { "data": { "text/plain": [ - "ExprRules.NodeLoc(2{15,4}, 1)" + "NodeLoc(3{6}, 1)" ] }, "execution_count": 17, @@ -591,7 +553,7 @@ } ], "source": [ - "srand(1)\n", + "Random.seed!(1)\n", "loc = sample(NodeLoc, rulenode)" ] }, @@ -610,7 +572,7 @@ { "data": { "text/plain": [ - "15," + "6," ] }, "execution_count": 18, @@ -638,77 +600,61 @@ "data": { "image/svg+xml": [ "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", + "\n", + "\n", + "\n", + "\n", "\n", "\n", - "\n", + "\n", "\n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", "\n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", "\n", "\n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - " \n", - "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", + " \n", "\n", "\n", - " \n", - " \n", - " \n", + " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ - "TreeView.LabelledTree({7, 6} directed simple Int64 graph, Any[:*, :*, 9, :*, 3, 6, 4.0])" + "TreeView.LabelledTree({6, 5} directed simple Int64 graph, Any[:f, :*, 9, :*, 4, 9])" ] }, "execution_count": 19, @@ -717,7 +663,7 @@ } ], "source": [ - "srand(28)\n", + "Random.seed!(28)\n", "insert!(rulenode, loc, rand(RuleNode, grammar, :Real, 3))\n", "display(rulenode, grammar)" ] @@ -815,7 +761,7 @@ { "data": { "text/plain": [ - "6-element Array{ExprRules.RuleNode,1}:\n", + "6-element Array{RuleNode,1}:\n", " 1{2,2}\n", " 1{2,3}\n", " 1{3,2}\n", @@ -912,40 +858,23 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - ":(1 + (1 + 2))\n", - "├─ :+\n", - "├─ 1\n", - "└─ :(1 + 2)\n", - " ├─ :+\n", - " ├─ 1\n", - " └─ 2\n" - ] - } - ], - "source": [ - "ex = get_executable(tree, grammar)\n", - "print_tree(ex)" - ] + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Julia 0.6.2", + "display_name": "Julia 0.7.0", "language": "julia", - "name": "julia-0.6" + "name": "julia-0.7" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "0.6.2" + "version": "0.7.0" } }, "nbformat": 4, diff --git a/src/ExprRules.jl b/src/ExprRules.jl index 2b4d9ca..9707d9c 100644 --- a/src/ExprRules.jl +++ b/src/ExprRules.jl @@ -3,7 +3,6 @@ __precompile__() module ExprRules import TreeView: walk_tree -import Random: srand using StatsBase using AbstractTrees using Nullables