Tag decorators are run bottom-to-top.
- x Is new feature
Description of suggestion or shortcoming:
Right now, it looks like the bottom decorators, closest to the variable in question are run first. I would have expected them to run last.
See lines 14-18:
In this new code, showAs winds up getting the tag of the underlying variable, to get the format. This only works if @showAs is on top of @format.
z = 34 -> Tag.format(".1f")
toLogScale = {
|e|
Plot.dist(
e,
{ xScale: Scale.log({ tickFormat: e -> inspect -> Tag.getFormat }) }
)
}
toSymScale = {|e| Plot.dist(e, { xScale: Scale.symlog() })}
showLog(dist) = Tag.showAs(dist, toLogScale)
showSym(dist) = Tag.showAs(dist, {|e| Plot.dist(e, { xScale: Scale.symlog() })})
@showAs(toLogScale)
@name("My favorite Dist")
@description("This is a long description")
@format("$.2")
x = (5 to 10)
y = x -> Tag.all
I agree that top-to-bottom order would be better in your example, and "@name first, then @showAs" reads better, but bottom-to-top order is used both in Python and in JS, so I'm not sure what's more important here. Some other users familiar with decorators in other languages might get confused.
There's a slight difference from other languages that Squiggle decorators work the same as r-values in pipe operator; @foo(arg1, arg2) gets called as @foo(value, arg1, arg2). Python and JS decorators that take arguments are factories that produce the decorator lambda first, and then those functions get called with a single parameter. Decorator factories are called top-to-bottom, and decorators themselves are called bottom-to-top. But even if we had decorator factories, it won't change the outcome, I believe.
Good points! I'm not sure what the best approach is now, will continue to consider. Doesn't seem super urgent now, especially given the considerations you mentioned.