Macros are not real objects
(1) By Ryan (RyanSmith) on 2022-07-29 10:58:45 [source]
When you define a macro, the definition can be used by name like any other object (line, circle, etc.) but it is not treated fully like an object, i.e. you cannot refer to its "last" instance, nor can you refer to its anchors (.s, .sw, .end, etc.) and most surprisingly, nor can you label it.
Given this example:
define emo { C1: circle radius 1; arc left 1 from C1; move right 0.45; circle radius 0.1 arc right 1 from C1; move up 0.2 from C1.s; circle radius 0.15 fill black; } E1: [emo]; move from E1.e right 1.5; [emo] at last move.end;→ /pikchrshow
I cannot simply say:
E1: emo;
I seem to have to "cast" it as a group:
E1: [emo];
Nor can I tell it where to draw the next, such as:
emo at last move.end;
or refer to it by relative position:
line from last emo;
but again can use the work-around of setting it into a group such that:
[emo] at last move.end;
works.
Is this by design? If not, might I suggest improving it to treat macros as 1st-class citizens too? I'm hoping something so easily fixed by two square-brackets would be as easy to fix in the codebase too, maybe even by the same method, unless it is expensive token-wise.
The work-around is easy enough, so no great urge to change it, or do so fast - just another nice-to-have on the roadmap.
Thanks!
(2.1) By sam atman (mnemnion) on 2024-04-14 15:08:49 edited from 2.0 in reply to 1 [link] [source]
I worked out something more flexible, although the syntax is different from using ordinary objects: the label is passed in as an argument to the macro.
It's legible enough, I would say, and since every macro-call is a labeled group, one can do the same basic things as a labeled group allows.
define emo { $1: [C1: circle radius 1; arc left 1 from C1; move right 0.45; circle radius 0.1 arc right 1 from C1; move up 0.2 from C1.s; circle radius 0.15 fill black]\ } emo(E1) move from E1.e right 1.5; emo(E2) at last move.end;→ /pikchrshow
(3) By Andreas Kupries (akupries) on 2024-04-18 13:20:12 in reply to 2.1 [link] [source]
Is it possible to leave out the $1:
part of the macro, i.e. have just the body grouped ? And then writing
E1: emo
also works ? As well as all the other issues, i.e. last
, anchors, etc. ?
Trying ...
define emo { \ [ C1: circle radius 1; arc left 1 from C1; move right 0.45; circle radius 0.1 arc right 1 from C1; move up 0.2 from C1.s; circle radius 0.15 fill black] \ } E1: emo move from E1.e right 1.5; E2: emo at last move.end;→ /pikchrshow
Signs point to yes.