eval_term() cannot bind a variable named t: the binding is partially matched to the formal 'term', so every transform result in t is unevaluable

Open Beginner friendly
#356 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r, rust
Domain
backend

Research direction

Read R/session.R around lines 600–606, where eval_term() declares its arguments and checks the bindings. Reproduce the reported failure with eval_term(P("sin(t) + t^2"), t = 1) and compare it with the working x example. Done means bindings named t, te, ter, and term are handled as intended and the error message is accurate; the issue does not name a test file.

Written by the indexing model from the issue text.

Description

area/api-bindings good first issue help wanted kind/contract severity/3-major

eval_term() cannot bind a variable named t (nor te, ter, term) because the binding name is partially matched to the formal argument term, so the most common variable in the calculus area — time — cannot be evaluated at all, and the error message blames the caller for not naming the binding.

library(rssn)
s <- rssn_session(); t <- sym("t", s)
P <- function(txt) parse_term(txt, s)

eval_term(P("sin(t) + t^2"), t = 1)
# Error: eval_term() takes named bindings, such as x = 0.5
eval_term(P("sin(t) + t^2"), te = 1)     # same error
eval_term(P("sin(t) + t^2"), ter = 1)    # same error
eval_term(P("sin(t) + t^2"), term = 1)   # same error
eval_term(P("sin(t) + t^2"), "t" = 1)    # same error
do.call(eval_term, list(P("sin(t) + t^2"), t = 1))   # same error

# every name that is not a prefix of "term" works
eval_term(P("sin(x) + 1"), x = 0)   # 1        (the documented example)
eval_term(P("sin(s)"), s = 1)       # 0.841471
eval_term(P("sin(ti)"), ti = 1)     # 0.841471
eval_term(P("sin(tt)"), tt = 1)     # 0.841471

Why it is wrong: the binding is named correctly; the message "eval_term() takes named bindings, such as x = 0.5" is false. There is no workaround inside the documented API — positional bindings are rejected by the same check, and quoting the name does not help — so a Laplace/Fourier/ODE result in t (the variable every transform in this engine uses: laplace(f, t, s), fourier(f, t, w), dsolve in t) simply cannot be evaluated numerically. Substituting a different symbol name, or re-parsing the printed text with x instead of t, is the only way.

Mechanism: R/session.R:600 declares eval_term <- function(term, ...). R matches a named actual argument to a formal by exact name first, then by partial name, so t = 1 is matched to term (as are te, ter, term); ... is then empty, names(list(...)) is NULL, and the guard at line 606 raises the "takes named bindings" error. Renaming the first formal (.term, x) or collecting the bindings before the call fixes it; the same trap will hit any future wrapper whose first formal is a prefix of a plausible symbol name.

rssn 0.3.0, R 4.6.2 binding, Windows x86_64.

Dominant language
Rust
Stars
36
Forks
3
Avg merge
14h 51m
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Apich-Organization/rssn

All issues in Apich-Organization/rssn

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.