I think you need to use
<extern|(lambda () p-value)>
extern
only takes functions, so you need to put it in a lambda
.
I think you need to use
<extern|(lambda () p-value)>
extern
only takes functions, so you need to put it in a lambda
.
I think I had not gotten the meaning of @tmbb 's question.
Now that I (maybe) do, I propose a refinement
(tm-define (p-value) "0.032")
(p-value
is defined as a function with no arguments)
with
<extern|p-value>
I thought we can also conveniently wrap it in another macro which adds the tag tag
, maybe
<assign|t-ext|<macro|body|<tag|<arg|body>|<extern|<arg|body>>>>>
but it does not work, when I apply this, the argument gets prepended with a line break, and the error
<unnamed port>: In expression (#<eof>):
<unnamed port>: Wrong type to apply: #<eof>
is displayed in the terminal.
But writing by hand
<tag|ratio|<extern|ratio>>
seems to work.
I think you have to use quasi and unquote to construct this properly.
Small variation on the approach of @pireddag : one could just have a table maybe defined in scheme and then lookup the various values with \extern, instead of having a tm-define for every new parameter. The table is read from scheme with an extern in the preamble, or with some command which can be run with a key-binding, so that one can refresh the values.
Do you mean
<assign|t-ext-t|<macro|body|<quasiquote|<tag|<arg|body>|<unquote|<extern|<arg|body>>>>>>>
??
It works better than my first attempt, but tag
has not effect on the output. I do not understand the logic of what I am writing.
Not quite, maybe I would try
<assign|t-ext-t|<macro|body|<tag|<arg|body>|<quasiquote|<extern|<unquote|<arg|body>>>>>>>
Or maybe
<assign|t-ext-t|<macro|body|<quasiquote|<tag|<arg|body>|<extern|<unquote|<arg|body>>>>>>>
That would be
<assign|show-var|<macro|var|<extern|(lambda (var) (stree-\<gtr\>tree
(assoc-ref var-list (tree-\<gtr\>stree var))))|<arg|var>>>>
that works with a list of variables written
(tm-define var-list '(("a" . 2) ("b" . 3)))
and loaded with another command (the list of variables must have the same name that appears inside the extern
).
Maybe this is a good solution, that does not fill (pollute )the environment with variables. It would be nice to make it work inside a tag too; I tried your suggestions and the output of extern is still typeset without a flag.
Do you want a flag? Then maybe one has to add it explicitly no? For me the following works
(tm-define var-list '(("a" . 2) ("b" . 3)))
(tm-define (my-lookup var) (stree->tree (assoc-ref var-list (tree->stree var))))
and in the document
<assign|my-lookup|<macro|var|<flag|<arg|var>|#aaf><extern|my-lookup|<arg|var>>>>
or (maybe just the first form suffice)
<assign|my-lookup-2|<macro|var|<flag|<arg|var>|#aaf><quasi|<extern|my-lookup|<unquote|<arg|var>>>>>>
@tmbb wrote that he was using tag
to get the flag (message), then I got taken by tag
and did not think about looking for another way to show the flag.
So: @tmbb, here is a good way of keeping a document synchronized with the output of a program. You can put the definition of my-lookup
in a module, var-list
gets composed by Python and the corresponding file either loaded with an extern macro in your preamble or loaded with a command assigned to a key combination (it is also possible to add the update command to the menu and I expect it is possible to redefine “Update all” to include the re-loading of the file).
var-list
has to be a list of pairs, hence the dot.