Skip to content

Revamp macros definitions#368

Draft
mforets wants to merge 1 commit intomasterfrom
marcefo/mlstyle
Draft

Revamp macros definitions#368
mforets wants to merge 1 commit intomasterfrom
marcefo/mlstyle

Conversation

@mforets
Copy link
Copy Markdown
Member

@mforets mforets commented Mar 31, 2026

No description provided.

Copy link
Copy Markdown
Member

@schillic schillic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! I know this is marked as a draft, but I already had a look. Currently, this PR is a perfect refactoring (with one exception, see my comment below).

Comment on lines -67 to +74
if length(args) > 1 && @capture(args[2], x ∈ X_)
return Expr(:call, ConstrainedIdentityMap, esc(:($(dimension))), esc(:($(X))))
else
return Expr(:call, IdentityMap, esc(:($(dimension))))
if length(args) > 1
X = @match args[2] begin
:($_ ∈ $X) => X
_ => nothing
end
if X !== nothing
return Expr(:call, ConstrainedIdentityMap, esc(:($(dimension))), esc(:($(X))))
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different from the old code, which required that the constrained variable is called x. I think some cases are better now. Other cases should have been throwing an error. But this would require a more fundamental change. So I am fine with that new behavior.

julia> X = 5;

# master: ignores `y` as variable in constraint
julia> @map(y -> y, dim=2, y  X)
IdentityMap(2)

julia> @map(x -> x, dim=2, y  X)
IdentityMap(2)


# this branch
julia> @map(y -> y, dim=2, y  X)  # accepts `y` as variable
ConstrainedIdentityMap{Int64}(2, 5)

julia> @map(x -> x, dim=2, y  X)  # misses non-matching variable name
ConstrainedIdentityMap{Int64}(2, 5)

Comment on lines +164 to +165
# like `:($lhs = $rhs)` match both `dim = 3` (parenthesized macro call, parsed
# as :kw) and `dim = 3` (unparenthesized, parsed as :(=)).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two occurrences of dim = 3 are identical. Did you mean something else?

else
@match ex begin
:($x(0) ∈ $X0) => begin # COV_EXCL_LINE
# TODO? handle equality
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO? handle equality
# TODO handle equality (x(0) = x0)?

@capture(expr[2], x_(0) ∈ x0_) || throw(ArgumentError("malformed epxpression")) # TODO handle equality
x0 = @match expr[2] begin
:($x(0) ∈ $X0) => X0
_ => throw(ArgumentError("malformed epxpression")) # TODO handle equality
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ => throw(ArgumentError("malformed epxpression")) # TODO handle equality
_ => throw(ArgumentError("malformed epxpression")) # TODO handle equality (x(0) = x0)?

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.

2 participants