Function variable not being treated as a vector? #641
-
|
Hi, @Proektsoftbg! I got another question for you... Why the macro approach in #640 works and the following one doesn't?
|
Beta Was this translation helpful? Give feedback.
Answered by
Proektsoftbg
Sep 16, 2025
Replies: 1 comment 4 replies
-
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
javila
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



Hi! The problem is that for historical reasons dots are allowed in variables, so
p.kcan be a variable with this name. You can actually definep.k = 1. When the function is created, it is compiled for performance andp.kis expected to be a variable later. At this moment, the program does not know if you will pass a variable or vector to p. We cannot change this behavior now because old worksheets may stop working. So, to explicitly specify thatpwill be a vector, definep=[0]before creating the function. Thenp.kwill be compiled as thek-th index of vectorp.However, the best and most efficient way is not to use indexing at all, and entirely by vectorized operators functions:
Please…