The extract built-in function [^] is very useful, but doesn't provide flexibility that would make it even more so. At present construct X [T*] _ [^ Y] recursively extracts all [T] subtrees at all levels.
More commonly, we'd like the non-recursive version, which extracts all [T] subtrees non-recursively, that is, only the topmost ones, not the [T]s embedded in [T]s. While it's possible to get those using global variables and the paradigm:
export X [T*]
_ % empty
where
Y [getTs]
import X
...
rule getTs
skipping [T]
match $ [T]
NextT [T]
import X [T*]
export X
NextT
X
end rule
This is awkward an inconvenient. It would be better to default [^] to non-recursive, the common case, and add another built-in function for recursive, possibly [^^] or [^*].
However, for back-compatibility reasons, we may be forced to leave [^] as it is, and instead add a new function for non-recursive, for example [^/] or [^|].
The extract built-in function [^] is very useful, but doesn't provide flexibility that would make it even more so. At present
construct X [T*] _ [^ Y]
recursively extracts all [T] subtrees at all levels.More commonly, we'd like the non-recursive version, which extracts all [T] subtrees non-recursively, that is, only the topmost ones, not the [T]s embedded in [T]s. While it's possible to get those using global variables and the paradigm:
This is awkward an inconvenient. It would be better to default [^] to non-recursive, the common case, and add another built-in function for recursive, possibly [^^] or [^*].
However, for back-compatibility reasons, we may be forced to leave [^] as it is, and instead add a new function for non-recursive, for example [^/] or [^|].