Assume we are defining a canvas
abstract data type in METAPOST, where some tasks are gathered. I would like to define a kind of reference to the last added task, but I do not know METAPOST good enough to figure out which macro concept I should use.
Here is a no-op code illustrating the use of such a reference:
def task text TASK =
vardef TASK.init =
enddef;
enddef;
def canvas text CANVAS =
numeric CANVAS._task_n;
task CANVAS._task[];
vardef CANVAS.init =
#@._task_n := 0;
enddef;
vardef CANVAS.current_task =
#@._task[#@._task_n]
enddef;
vardef CANVAS.add_task =
#@._task_n := #@._task_n + 1;
% #@.current_task.init; % ! Yield an isolated expression `init`
#@._task[#@._task_n].init;
enddef;
enddef;
canvas c;
c.init;
c.add_task;
bye;
How can I correctly define the current_task
macro, so that I can modify the add_task
macro to refer to the current_task
instead of #@._task[#@._task_n]
(as suggested in the comment)?
#@._task[#@._task_n]
in a symbolic way, i.e. to be able to write something like#@.current_task.init
instead of#@._task[#@._task_n].init
but my current approach does not work. Thank you to point out the mailing list.