Makie.jl: Error in @lift macro expression in case of struct

Created on 8 Jun 2020  路  6Comments  路  Source: JuliaPlots/Makie.jl

MWE

a = Node(rand(3, 3, 3));
b = Node(1);
i = 1;
@macroexpand @lift($a[:,i,$b])
:(AbstractPlotting.lift(((a, b)->a[:, i, b]), a, b)) #this does what it should
#now enclose Nodes into a Struct:
struct C
    a
    b
end;
c = C(a, b);  
@macroexpand @lift($c.a[:, i, $c.b])
:(AbstractPlotting.lift(((c,)->c.a[:, i, c.b]), c))  #wrong expression

the expression is wrong, because it treats c as the observable, but instead it should treat c.a and c.b as independent observables.

Most helpful comment

Hm thinking about this further, it could be a bit difficult to correctly determine how far up the expression tree we should go to replace the expression with the late $.

a.$c  ->  lift(a.c)
a.b.$c  ->  lift(a.b.c)
a(x)[3].$y  ->  lift(a(x)[3].y)

The alternative with the parentheses:

$(a.c)  ->  lift(a.c)
$(a.b.c)  ->  lift(a.b.c)
$(a(x)[3].y)  ->  lift(a(x)[3].y)

is much easier to do

All 6 comments

yeah that annoyed me as well wenn I wrote the macro, but I didn't have time to deal with this case then. The problem is that for $x.y sometimes x is the observable, and sometimes it's y. Maybe I should enable the syntax

@lift(c.$a[:, i, c.$b])

which currently doesn't work but at least parses, so that should be possible.
Another option would be to enable $(some_observable_as * the_result + of_an_expression)

I like the first option

Hm thinking about this further, it could be a bit difficult to correctly determine how far up the expression tree we should go to replace the expression with the late $.

a.$c  ->  lift(a.c)
a.b.$c  ->  lift(a.b.c)
a(x)[3].$y  ->  lift(a(x)[3].y)

The alternative with the parentheses:

$(a.c)  ->  lift(a.c)
$(a.b.c)  ->  lift(a.b.c)
$(a(x)[3].y)  ->  lift(a(x)[3].y)

is much easier to do

Yes for parenthesis, that was actually my first guess - that also fails in current version. If parenthesis worked, I wouldn't fill the issue.
And it's meaning in code is completely clear.

ok I'll look into the implementation

Was this page helpful?
0 / 5 - 0 ratings