Skip to content

Fix misinterpretation of function arguments with parameters (#45)#96

Open
dyrpsf wants to merge 2 commits into
draeger-lab:masterfrom
dyrpsf:fix-function-bvars-parameters
Open

Fix misinterpretation of function arguments with parameters (#45)#96
dyrpsf wants to merge 2 commits into
draeger-lab:masterfrom
dyrpsf:fix-function-bvars-parameters

Conversation

@dyrpsf
Copy link
Copy Markdown
Contributor

@dyrpsf dyrpsf commented Jan 4, 2026

This PR fixes issue #45: when a FunctionDefinition has bvars with the same ids as
global parameters, SBSCL used the parameter values instead of the argument values
inside the function body.

The fix:

  • Populate ASTNodeInterpreter.funcArgs with {bvarName -> argumentValue} before
    evaluating the function body in functionDouble(...) and functionBoolean(...).
  • Restore the previous funcArgs map after evaluation, so nested function calls work.

With this change, identifiers inside a function body correctly refer to the function
arguments, even if parameters with the same ids exist in the model.

Copy link
Copy Markdown
Member

@draeger draeger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good: The only comment I have is that we now have two parts of the code with nearly identical and comparably complex code. If further improvements or corrections are necessary, adjustments will need to be made to the positions. If it were possible to unify both methods by performing the pre- and postprocessing steps in sub-methods, maintenance could be simplified, and duplication errors could be reduced.

@draeger draeger requested a review from funasoul January 5, 2026 14:55
@draeger draeger assigned draeger and dyrpsf and unassigned draeger Jan 5, 2026
@dyrpsf
Copy link
Copy Markdown
Contributor Author

dyrpsf commented Jan 5, 2026

@draeger Thanks for the review and the suggestion!

You’re right, functionDouble and functionBoolean share almost the same pre/post‑processing logic. I’ll extract that into a small private helper so the two methods only differ by how they evaluate the function body. I’ll push an updated commit shortly.

@dyrpsf
Copy link
Copy Markdown
Contributor Author

dyrpsf commented Jan 5, 2026

Hi @draeger,
I’ve pushed a follow-up commit that factors out the common argument-handling logic into a private
pushFunctionArguments(...) helper. Both functionDouble(...) and functionBoolean(...) now use
this helper, so their bodies only differ in how they evaluate the function body, and the duplicated code is removed.

Copy link
Copy Markdown
Member

@draeger draeger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done solution!

@draeger draeger requested a review from tyzerrr January 5, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants