Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation syntaxtree tutorial #68

Merged
merged 10 commits into from
Jul 9, 2024

Conversation

pwochner
Copy link
Contributor

@pwochner pwochner commented May 1, 2024

Adding a tutorial on ASTs, how they are represented in Herb and how they can be modified.

@pwochner pwochner changed the base branch from master to documentation May 1, 2024 14:22
@IssaHanou
Copy link
Member

Looks nice! I think these are good examples.

Few minor typos:

  • Line 18: represent as an abstract
  • Line 29: grammer → grammar
  • Line 31: in the context of program synthesis ,

it might be nice to also show the evaluation of the AST (using eval) if you store a value in input1 then you can check if the rule node program is correct

@pwochner
Copy link
Contributor Author

pwochner commented May 8, 2024

I added evaluating the ASTs on some input examples using execute_on_input.

@sebdumancic
Copy link
Member

Could we change this

function fizzbuzz(x)
    if x % 5 == 0 && x % 3 == 0
        return Dict(:output1 => "FizzBuzz")
    else
        if x % 3 == 0
            return Dict(:output1 => "Fizz")
        else
            if x % 5 == 0
                return Dict(:output1 => "Buzz")
            else
                return Dict(:output1 => string(x))
            end
        end
    end
end

into

function fizzbuzz(x)
    if x % 5 == 0 && x % 3 == 0
        return "FizzBuzz"
    else
        if x % 3 == 0
            return  "Fizz"
        else
            if x % 5 == 0
                return "Buzz"
            else
                return string(x)
            end
        end
    end
end

?

Simply because it looks nicer and less weird. Returning the dict is a convention we made if we would do synthesis, but otherwise is a bit weird.

@pwochner
Copy link
Contributor Author

pwochner commented Jul 4, 2024

Updated fizz_buzz() and grammar to return String instead of Dict.

@pwochner pwochner merged commit 8daed41 into documentation Jul 9, 2024
4 checks passed
@pwochner pwochner deleted the documentation-syntaxtree-tutorial branch July 9, 2024 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants