constInputs: Determine which parameters are not modified in a function

constInputsR Documentation

Determine which parameters are not modified in a function

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

constInputs(f)

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

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 Feb. 21, 2024, 10:49 p.m.