-
Notifications
You must be signed in to change notification settings - Fork 14
[Query] Inspect Higher Order Functions
This document was generated from 'src/documentation/wiki-query.ts' on 2026-07-20, 17:48:26 UTC presenting an overview of flowR's query API (v2.12.3). Please do not edit this file/wiki page directly.
Inspect Higher-Order Functions Query [overview]
Determine whether functions are higher-order functions
This query is requested with the type inspect-higher-order.
Run in the REPL: :query @inspect-higher-order [(<crit>;...)] <code | file://path>
With this query you can identify which functions in the code are higher-order functions, i.e., either take a function as an argument or return a function.
Please note, that functions that are just identities (e.g., function(x) x) are not considered higher-order if they do not take a function as an argument.
Using the example code f <- function() function(x) x; f() the following query returns the information for all identified function definitions whether they are higher-order functions:
[ { "type": "inspect-higher-order" } ](This can be shortened to @inspect-higher-order when used with the REPL command :query).
Results (prettified and summarized):
Query: inspect-higher-order (8ms)
- Function 5 (1.17-29) is not a higher-order function
- Function 7 (1.6-29) is a higher-order function
All queries together required ≈8 ms (1ms accuracy, total 8 ms)
Show Detailed Results as Json
The analysis required 8.4 ms (including parsing and normalization and the query) within the generation environment.
In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.
{
"inspect-higher-order": {
".meta": {
"timing": 8
},
"higherOrder": {
"5": false,
"7": true
}
},
".meta": {
"timing": 8
}
}Original Code
f <- function() function(x) x; f()Dataflow Graph of the R Code
The analysis required 5.5 ms (including parse and normalize, using the r-shell engine) within the generation environment. No signature database is mounted for these generated graphs, so library() calls attach no package exports; base-R names are still qualified via the generated base-package store (e.g. acf as stats::acf).
We encountered no unknown side effects during the analysis.
flowchart LR
7["`*#91;RFunctionDefinition#93;* **function**
*1.6-29* (**id: 7**)`"]
subgraph "flow-7" [function 7]
%% Environment of 5 [level: 1]:
%% Built-in
%% 1----------------------------------------
%% 2----------------------------------------
5["`*#91;RFunctionDefinition#93;* **function**
*1.17-29* (**id: 5**)`"]
subgraph "flow-5" [function 5]
1["`*#91;RSymbol#93;* **x**
*1.26* (**id: 1**, v: )`"]
%% No edges found for 1
3(["`*#91;RSymbol#93;* **x**
*1.29* (**id: 3**)`"])
end
%% No edges found for 5
end
%% No edges found for 7
0["`*#91;RSymbol#93;* **f**
*1.1* (**id: 0**, v: 7)`"]
8[["`*#91;RBinaryOp#93;* base#58;#58;**#60;#45;**
*1.1-29* (**id: 8**)
arg: (0, 7)`"]]
built-in:_-["`Built-In:
#60;#45;`"]
style built-in:_- stroke:gray,fill:gray,stroke-width:2px,opacity:.8;
%% Environment of 10 [level: 0]:
%% Built-in
%% 1----------------------------------------
%% f: {**f** (id: 0, type: Function, def. @8)}
10[["`*#91;RFunctionCall#93;* **f**
*1.32-34* (**id: 10**)`"]]
3 -->|"reads"| 1
5 -.-|function| flow-5
7 -.-|function| flow-7
0 -->|"defined-by"| 7
0 -->|"defined-by"| 8
8 -->|"reads, arg"| 7
8 -->|"returns, arg"| 0
8 -.->|"reads, calls"| built-in:_-
linkStyle 7 stroke:gray;
10 -->|"reads"| 0
10 -->|"returns"| 5
10 -->|"calls"| 7
This query also supports a slicing criterion based query mode that only returns information for functions matching the given criteria:
[
{
"type": "inspect-higher-order",
"filter": [
"1@function"
]
}
](This can be shortened to @inspect-higher-order (1@function) "f <- function() function(x) x; f()" when used with the REPL command :query).
Results (prettified and summarized):
Query: inspect-higher-order (7ms)
- Function 7 (1.6-29) is a higher-order function
All queries together required ≈7 ms (1ms accuracy, total 8 ms)
Show Detailed Results as Json
The analysis required 8.0 ms (including parsing and normalization and the query) within the generation environment.
In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.
{
"inspect-higher-order": {
".meta": {
"timing": 7
},
"higherOrder": {
"7": true
}
},
".meta": {
"timing": 7
}
}Implementation Details
Responsible for the execution of the Inspect Higher-Order Functions Query query is executeHigherOrderQuery in ./src/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.ts.
Currently maintained by Florian Sihler and Oliver Gerstl at Ulm University
Email | GitHub | Penguins | Portfolio
- 🧑💻 Developer Onboarding
- 💻 Setup
- 👓 Overview
- 🪟 Interfacing with flowR
- 🌋 Core
- 🧹 Testing & Linting (Benchmark Page)
⁉️ FAQ- ℹ️ Extra Information