Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix world age warnings from accessing binding before definiton #108

Merged
merged 2 commits into from
Jan 31, 2025
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FixedPointDecimals"
uuid = "fb4d412d-6eee-574d-9565-ede6634db7b0"
authors = ["Fengyang Wang <fengyang.wang.0@gmail.com>", "Curtis Vogt <curtis.vogt@gmail.com>"]
version = "0.6.0"
version = "0.6.1"

[deps]
BitIntegers = "c3b6d118-76ef-56ca-8cc7-ebb389d030a1"
Expand Down
3 changes: 2 additions & 1 deletion src/FixedPointDecimals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ const FMAFloat = Union{Float16, Float32, Float64, BigFloat}

for fn in [:trunc, :floor, :ceil]
fnname = Symbol(fn, "mul")
fnname_str = String(fnname)
opp_fn = fn == :floor ? :ceil : :floor

@eval begin
@doc """
$($fnname)(I, x, y) :: I
$($fnname_str)(I, x, y) :: I
Comment on lines -54 to +55
Copy link
Member

Choose a reason for hiding this comment

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

Ah, nice, thanks! Good find! It took me a minute of staring, but i think i've got an explanation:
It's easy to forget, but interpolating a symbol into an expression creates an identifier, not a symbol.
So this was generating the following string code:

"  $(trunc_mul)(I, x, y) :: I "

and as you point out, the trunc_mul function doesn't exist yet, so this should fail.

What we meant to be putting in there was the name of the function, as you've done, so your change looks great. 👍
The other thing we could have done is to generate what this code meant to be generating, which is this:

julia> "$(:foo)(I, x, y) :: I"
"foo(I, x, y) :: I"

That is, putting the symbol itself into the code, rather than using the symbol to put an identifier in the code.

The syntax to do that is to wrap the value in a QuoteNode, whose sole purpose it to allow putting symbols or expressions as values into generated code:

            $($(Meta.quot(fnname)))(I, x, y) :: I
            $($(QuoteNode(fnname)))(I, x, y) :: I

(either of those options are identical)

Copy link
Member

Choose a reason for hiding this comment

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

but anyway, i like what you've done - it's very straightforward.

Copy link
Member

Choose a reason for hiding this comment

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

in particular, the quote suggestion raises the question "how does a symbol stringify in interpolation? Does it print as foo or :foo?" so converting to a string is more clear 👍


Compute `$($fn)(I, x * y)`, returning the result as type `I`. For
floating point values, this function can be more accurate than
Expand Down
Loading