constInputs: Determine which parameters are not modified in a function

Description Usage Arguments Value Author(s) Examples

Description

This function determines which functions are "constant" in a function, i.e. read-only. These are the formal arguments/parameters that are not changed by code in the body of this function. The purpose of knowing this is that we can, in theory, avoid copying the value of the argument before calling this function, but still know that the content will not change. This is useful when compiling code.

This currently does not work recursively for calls to other functions. This will be added later.

Usage

1

Arguments

f

the function object whose parameters and body we process

Value

A character vector giving the names of the parameters that are not modified in the body of the function. THis might be empty.

Author(s)

Duncan Temple Lang

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
f =
function(x)
{
  y = numeric(length(n))
  for(i in seq(along = x))
    y[i] = x[i]*2
}

constInputs(f)  # "x"

g =
function(x)
{
  for(i in seq(along = x))
    x[i] = x[i]*2
}

constInputs(g)

duncantl/CodeAnalysis documentation built on Aug. 11, 2019, 12:35 a.m.