- From: Henri Lesourd <address@hidden>
- To: address@hidden
- Subject: Re: [TeXmacs] How to get value of the environment variable from scheme?
- Date: Thu, 18 Sep 2008 21:52:18 +0200
Takama M. wrote:
>
Hi,
>
>
I feel pleasure of using TeXmacs recently.
>
Now I want to know the method to get value of the variable
>
stored in the TeXmacs environment from scheme side.
>
>
I try to find those ...
>
and found such procedures "get-env" and "get-env-tree".
>
>
Though the help pages of the TeXmacs are very well and
>
useful, those procedures are not documented in detail.
>
>
The lines below are my poor efforts.
>
Am i on the right path?
>
>
Yes, it's OK.
>
Or are there other better methods?
>
>
>
There is another way, which is to directly
traverse the document tree to find the <assign|...>
or <with|...> constructs, then read the data. But
this way is slower and more syntactic, although
the other one is sometimes buggy due to problems
in the C++. Inside the file graphics-utils.scm,
see the implementation of:
(tm-find-prop p var)
(get-upwards-tree-property p var)
etc.
(read on older messages on the mailing list,
there are some which document how to traverse
TeXmacs documents as tree).
>
<assign|xx|7>
>
scheme] (get-env "xx")
>
=> "7"
>
OK!
>
>
<assign|tpl|<tuple|H|e|l|lo>>
>
scheme] (get-env "tpl")
>
=> ""
>
???
>
>
>
It's because the output of (get-env) is supposed
to be a string, thus when the value is a non
atomic tree, it spits you out BS.
>
scheme] (get-env-tree "tpl")
>
=> <tuple|H|e|l|l|o>
>
Hummm...
>
>
>
In fact, using (get-env-tree) all the time
is simpler, then you convert the trees to
s-expressions by means of (tree->stree),
and you always deal with Scheme objects.
(isn't very optimal if the values are
big, though...).
>
scheme] (tm-car (get-env-tree "tpl"))
>
=> tuple
>
>
This one is cool.
>
scheme] (tm-cdr (get-env-tree "tpl"))
>
=> (<tree H> <tree e> <tree l> <tree l> <tree o>)
>
>
>
That one is shitty, for you can't avoid
rewriting the tree, then.
Much better to use:
(tree-label $TREE) -> Symbol
(tree-arity $TREE) -> Integer
(tree-ref $TREE $INDEX) -> Tree
to read/traverse the tree.
>
scheme] (define (tmcadr t) (tm-car (tm-cdr t)))
>
scheme] (tmcadr (get-env-tree "tpl"))
>
=> H
>
>
>
tree-ref $TREE 0 = tmcadr, but constant-time,
without the consings.
Archive powered by MHonArc 2.6.19.