Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline OchkovVF  
#1 Posted : 13 September 2024 17:57:22(UTC)
OchkovVF


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 06/04/2023(UTC)
Posts: 425
Man
Russian Federation

Was thanked: 42 time(s) in 39 post(s)
Factorial-2.sm (8kb) downloaded 1 time(s).
Factorial-Err.png

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Davide Carpi  
#2 Posted : 13 September 2024 20:14:18(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,710
Man
Italy
Location: Italy

Was thanked: 1378 time(s) in 902 post(s)
You can guess by the error message (function is not defined).
The key is that you are using a recursive pattern, and in the first case the internal Factorial() can't be calculated because the context in which the function runs is the "top level" (the canvas), where Factorial(1) doesn't yet exists (it will exists for the next region on the closest canvas pixel on the right side).
The line() on the RHS of a define operator (colon) creates a sub-level that inherit everything from the higher level(s) including the function whom the line() belongs, and that's why the second function works as you expect.
The bottom examples are unrelated because are not recursive.

Hope it helps.

Edited by user 13 September 2024 20:17:15(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.