Skip to content

make all maketerm arguments mandatory #35

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

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/TermInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function metadata end


"""
maketerm(T, head, children, type=nothing, metadata=nothing)
maketerm(T, head, children, type, metadata)

Constructs an expression. `T` is a constructor type, `head` and `children` are
the head and tail of the S-expression, `type` is the `type` of the S-expression.
Expand All @@ -125,8 +125,7 @@ the sub-expression. `T` will be the type of the outer expression.

Packages providing expression types _must_ implement this method for each expression type.

If your types do not support type information or metadata, you still need to accept
these arguments and may choose to not use them.
Giving `nothing` for `type` or `metadata` results in a default being selected.
"""

function maketerm end
Expand Down
2 changes: 1 addition & 1 deletion src/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ children(e::Expr) = e.args
operation(e::Expr) = iscall(e) ? first(children(e)) : error("operation called on a non-function call expression")
arguments(e::Expr) = iscall(e) ? @view(e.args[2:end]) : error("arguments called on a non-function call expression")

function maketerm(::Type{Expr}, head, args, type=nothing, metadata=nothing)
function maketerm(::Type{Expr}, head, args, type, metadata)
Expr(head, args...)
end
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using Test
@test arguments(ex) == [:a, :b]
@test isexpr(ex)
@test iscall(ex)
@test ex == maketerm(Expr, :call, [:f, :a, :b])
@test ex == maketerm(Expr, :call, [:f, :a, :b], nothing, nothing)


ex = :(arr[i, j])
Expand All @@ -18,5 +18,5 @@ using Test
@test_throws ErrorException arguments(ex)
@test isexpr(ex)
@test !iscall(ex)
@test ex == maketerm(Expr, :ref, [:arr, :i, :j])
@test ex == maketerm(Expr, :ref, [:arr, :i, :j], nothing, nothing)
end
Loading