functions with an embedded [history] seem to have inconsistant behavior depending on how they are called

Cptnfantasy's icon

When a function that relies on a [history] is referenced by another function's branch it will behave differently based on whether it is declared locally (to a codebox) or included in a .genxpr that is named by the 'require' operator.

When everything is declared locally, each function call seems to have a unique [history], but if is referenced in a .genexpr it seems like the [histories] (lol) don't have separate aliases and share the same memory space or something.

Making a uniquely name branching function for each call needed seems to remedy the issue.

I realize this probably makes no sense so I illustrated the behavior in a patch.

my question: is this a bug? Is nesting if/else branches in functions bad form? What is the 'best practices' for this situation?

the attached patcher replicates what I'm talking about with a simple function that behaves like rand~ based on the one in the gen~ examples folder.

historyExample.zip
application/x-zip-compressed 3.42 KB

C Hausch's icon

i stumbled under this exact problem just yesterday, 2 years after your post.

i can't imagine this is supposed to be that way. dear c74 team, please give a little love to gen.

i noticed the problem in a patch where i generate 3 lfo ramps in a function that i smoothed out using a rampsmooth implementation that i put into an extra genexpr file for sake of clarity of code and maintainability. when the 3 ramps got weirdly synchronized i looked through my code for hours. after reading this post here i took the rampsmooth function and put it in the main codebox. now everything works.

please let me repeat: please dear c74 coders don't forget about gen – it is the part of max that i want most to improve (code optimization anyone?)!