From 595cc08deacae272928fc8de9471be9f2dde15d0 Mon Sep 17 00:00:00 2001 From: David Llewellyn-Jones Date: Fri, 18 Oct 2024 15:37:05 +0100 Subject: [PATCH 1/3] Add comment about running from project In the Getting Started guide the way to execute will depend on whether the Herb.jl pakcages were installed globally or as part of a project. This commit adds some text to highlight this distinction. --- docs/src/get_started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/get_started.md b/docs/src/get_started.md index 3dabafd..1af223d 100644 --- a/docs/src/get_started.md +++ b/docs/src/get_started.md @@ -1,6 +1,6 @@ # Getting Started -You can either paste this code into the Julia REPL or into a seperate file, e.g. `get_started.jl` followed by `julia get_started.jl`. +You can either paste this code into the Julia REPL or into a seperate file, e.g. `get_started.jl`. If using a separate file you can execute using `julia get_started.jl` or `julia --project=. get_started.jl` depending on whether you installed Herb.jl globally or in a project. To begin, we need to import all needed packages using From 7a7596813ef7708939648dcae1a4e23546ceb123 Mon Sep 17 00:00:00 2001 From: David Llewellyn-Jones Date: Fri, 18 Oct 2024 15:39:17 +0100 Subject: [PATCH 2/3] Fix example code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One of the variables used in the Getting Started section uses both g and g₁ for the same grammar structure. This change switches them all to use g. --- docs/src/get_started.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/get_started.md b/docs/src/get_started.md index 1af223d..86e7127 100644 --- a/docs/src/get_started.md +++ b/docs/src/get_started.md @@ -33,7 +33,7 @@ problem = Problem([IOExample(Dict(:x => x), 2x+1) for x ∈ 1:5]) The problem is given now, let us search for a solution with `HerbSearch`. For now we will just use the default parameters searching for a satisfying program over the grammar, given the problem and a starting symbol using ```julia -iterator = BFSIterator(g₁, :Number, max_depth=5) +iterator = BFSIterator(g, :Number, max_depth=5) solution, flag = synth(problem, iterator) println(solution) ``` @@ -70,7 +70,7 @@ g = @csgrammar begin end problem = Problem([IOExample(Dict(:x => x), 2x+1) for x ∈ 1:5]) -iterator = BFSIterator(g₁, :Number, max_depth=5) +iterator = BFSIterator(g, :Number, max_depth=5) solution, flag = synth(problem, iterator) program = rulenode2expr(solution, g) # should yield 2*6 +1 From a39216a071e30f9761673d7ebff4a4e0136cb3f4 Mon Sep 17 00:00:00 2001 From: David Llewellyn-Jones Date: Fri, 18 Oct 2024 15:41:10 +0100 Subject: [PATCH 3/3] Output program in Getting Started example The example in the Getting Started guide outputs the syntax tree and the final output, but not the generated Julia code. This code is quite instructive, so this change outputs the generated code as well. --- docs/src/get_started.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/src/get_started.md b/docs/src/get_started.md index 86e7127..de9e03c 100644 --- a/docs/src/get_started.md +++ b/docs/src/get_started.md @@ -44,11 +44,14 @@ Eventually, we want to test our solution on some other inputs using `HerbInterpr ```julia program = rulenode2expr(solution, g) # should yield 2*6+1 +println(program) output = execute_on_input(SymbolTable(g), program, Dict(:x => 6)) println(output) ``` +If you run the completed code it will output both the generated Julia expression and the result from assigning value. + Just like that we tackled (almost) all modules of Herb.jl. ## Where to go from here? @@ -74,6 +77,7 @@ iterator = BFSIterator(g, :Number, max_depth=5) solution, flag = synth(problem, iterator) program = rulenode2expr(solution, g) # should yield 2*6 +1 +println(program) output = execute_on_input(SymbolTable(g), program, Dict(:x => 6)) println(output)