aaronpeikert / StenoGraphs.jl

Write meta graphs quickly
https://aaronpeikert.github.io/StenoGraphs.jl/
MIT License
5 stars 3 forks source link

NaN is parsed as a Symbol #27

Open Maximilian-Stefan-Ernst opened 2 years ago

Maximilian-Stefan-Ernst commented 2 years ago

I would like to allow the Syntax f1 → fixed(1.0, NaN)*x1 to fix the loading in the first group, but not the second. However, this fails unexpectedly:

While typeof(NaN) is Float64, and typeof(fixed(1.0, NaN)) results in Fixed{Tuple{Float64, Float64}}, using it inside the @StenoGraphs macro results in the Modifier Fixed{Tuple{Float64, Symbol}}((1.0, :NaN)).

MWE:

struct Fixed{N} <: EdgeModifier
    value::N
end
fixed(args...) = Fixed(args)

@StenoGraph begin
  f1  → fixed(1.0, NaN)*x1
end
aaronpeikert commented 2 years ago

Not that it helps but it should be missing instead of NaN.

Maximilian-Stefan-Ernst commented 2 years ago

Why? Lavaan uses NA, and writing f1 → fixed(1.0, missing)*x1 seems not so pretty to me. So I decided in favor of NaN. Also, NaN and 1.0 have the same length in monospace fonts, resulting in a much more pleasant look:

graph = @StenoGraph begin
    # measurement model
    visual   → fixed(1.0, NaN)*x1 
    textual  → fixed(1.0, 1.0)*x4
end

graph = @StenoGraph begin
    # measurement model
    visual   → fixed(1.0, missing)*x1 
    textual  → fixed(1.0, 1.0)*x4
end
aaronpeikert commented 2 years ago

NaN exists only to satisfy ISO norm for floating-point calc and has some really weird behaviours. missing is the idiomatic way and the Julia community is very proud of it (rightfully so, I'd say). One important point is that typeof(NaN) is Float64. Therefore the equivalent of fixed(1.0, NaN) for label is label(1.0, missing) anyway. Base often uses _ for ignored arguments, so I could imagine:

const _ = missing

Unfortunately, we settled on _ for unquoting....

I could be a bit surprising and swap NaN with missing.

Not sure what is the best solution...