1 страниц (4 вхождений)
Inconsistent function behavior - Changing constants in a function messes up if finction is defined twice - Сообщения
#1 Опубликовано: 12.04.2024 20:56:05
smath function bug.sm (5 КиБ) скачан 23 раз(а).
I ran into this issue on a really long calc and took me a while to realize what went wrong. When I have a function with constants in it, I can redefine the constants later and call the function and it works great. But if I redefine the function, this functionality stops working. I also tried renaming the second function definition and/or adding another term to the function signature and this didn't give me the expected behavior. Not sure if this is already known or what's going on, but thought I'd make an account and post it. Thanks everyone. Love Smath.
I ran into this issue on a really long calc and took me a while to realize what went wrong. When I have a function with constants in it, I can redefine the constants later and call the function and it works great. But if I redefine the function, this functionality stops working. I also tried renaming the second function definition and/or adding another term to the function signature and this didn't give me the expected behavior. Not sure if this is already known or what's going on, but thought I'd make an account and post it. Thanks everyone. Love Smath.
#2 Опубликовано: 12.04.2024 21:13:08
Whoops I didn't have the file right to demonstrate the bug. Now it shows the issue as intended.
#3 Опубликовано: 12.04.2024 21:25:24
I don't believe this is a bug. When you first define the function. c.1 and c.2 are undefined. So you can define c.1/c.2 outside of the function at will and it will calculate fine. However, when you redefine the function, values for c.1/c.2 are already defined so these get evaluated and assigned in the function. There are couple ways to deal with this.
1. Add c.1, c.2 to the input variables. So f(i,j) becomes f(i,j,c.1,c.2)
2. Clear c.1, c.2 before re-defining the function.
That being said, I don't quite understand the use case for redefining functions within a sheet or changing values of constants. If you're changing the value of a constant, it isn't a constant and should become a function variable.
smath function (not a) bug -alyles.sm (6 КиБ) скачан 22 раз(а).
1. Add c.1, c.2 to the input variables. So f(i,j) becomes f(i,j,c.1,c.2)
2. Clear c.1, c.2 before re-defining the function.
That being said, I don't quite understand the use case for redefining functions within a sheet or changing values of constants. If you're changing the value of a constant, it isn't a constant and should become a function variable.
smath function (not a) bug -alyles.sm (6 КиБ) скачан 22 раз(а).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#4 Опубликовано: 12.04.2024 22:30:44
Ah thank you alyles. I know I could work around this by adding these non-constants to the function signature. It was what I viewed as inconsistent behavior that bothered me.
However, I see from your explanation that the behavior changes not based on whether the function is redefined, but whether the "constant" in the function is defined before or after the function. Ie, if in my sample file you define c1 at the top of the page, the function doesn't update it's value based on c1 changed till you repaste the function. I'm content that that is consistent program behavior, if a smidge confusing. Thank you!
However, I see from your explanation that the behavior changes not based on whether the function is redefined, but whether the "constant" in the function is defined before or after the function. Ie, if in my sample file you define c1 at the top of the page, the function doesn't update it's value based on c1 changed till you repaste the function. I'm content that that is consistent program behavior, if a smidge confusing. Thank you!
1 страниц (4 вхождений)
-
Новые сообщения
-
Нет новых сообщений