Skip to Content.
Sympa Menu

texmacs-users - Re: list of relative tree paths of matched trees

Subject: mailing-list for TeXmacs Users

List archive

Re: list of relative tree paths of matched trees


Chronological Thread 
  • From: Giovanni Piredda <address@hidden>
  • To: address@hidden
  • Subject: Re: list of relative tree paths of matched trees
  • Date: Mon, 1 Feb 2021 01:50:03 +0100

Let us see if this is closer.

(map tree->path (tree-search (buffer-tree) (lambda(s) (equal? (tree-name s) "proposition"))))

gets you the paths of each tree you find, but they are (as far as I can see) absolute paths (i.e. with respect to the root tree).

If you want the paths relative to buffer-tree (your search tree) then the relative-path function I wrote, applied to (map tree->path (tree-search (buffer-tree) (lambda(s) (equal? (tree-name s) "proposition")))),  should be able to give you that.

Ple. let me know if this makes sense.

G.

On 01.02.21 01:12, Murali Agastya wrote:
Thanks Giovanni for the quick response.
That is however not what I was looking for.   A concrete example may clarify,  (tree-search (buffer-tree) (lambda(s) (equal? (tree-name s) "proposition")))  will give be a list of all the "proposition" trees.  How do I get the  path of each of those "proposition" trees in the above list?
best,
Murali


On Mon, Feb 1, 2021 at 10:42 AM Giovanni Piredda <address@hidden <mailto:address@hidden>> wrote:


Am 01.02.2021 um 00:00 schrieb Murali Agastya:
Hello all,

I am able to get a list of all the subtrees of a given *name* in
a given tree *T * using the  function
(tree-search T  (lambda(s) (equal? (tree-name s) name)) )

Can someone help me with an analogous script that returns the
list of relative paths of those trees instead of the trees
themselves?

Thank you and kind regards,
Murali


It is possible that I am misunderstanding your question, said this.

Get the list of paths of the subtrees mapping tree->path on the
results of your expression

Get the path of the parent tree with (tree->path T)

Use the following to map onto the list of paths (assumes parent is
a parent of child!):

(define (relative-path parent child)
  (cond ((null? parent) child)
        (else (relative-path (cdr parent) (cdr child)))))

With results:

(relative-path '(1 2 3) '(1 2 3))

; ()

(relative-path '(1 2 3) '(1 2 3 4))

(4)




Archive powered by MHonArc 2.6.19.

Top of Page