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

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline Alex M.  
#1 Posted : 14 November 2016 02:49:07(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
This example should be self explanatory. I expected same output in both cases. Is this a feature or a bug? Caused disaster in my formula logic.

Thanks!

FunctionBug.png
FunctionBug.sm (8kb) downloaded 15 time(s).

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

Offline Davide Carpi  
#2 Posted : 14 November 2016 03:43:06(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1340 time(s) in 879 post(s)
Feature Good

You are using pass-by-reference, that assign a value to an input argument when it is the target of an assignment inside the procedure (see here f.e.)

2016-11-14 01_50_19-Feature or a bug_ Cannot force numeric evaluation within a function.png

the last assignment is missing; to assign the same value both to the result and to the input variable you have to define ID#:eval(ID#+1) even after the loop.

2016-11-14 01_53_10-2016-11-14 01_52_11-SMath Studio - [FunctionBug.sm_].png - Visualizzatore foto d.png

Edited by user 14 November 2016 03:56:48(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
Offline Alex M.  
#3 Posted : 14 November 2016 04:59:00(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: Davide Carpi Go to Quoted Post
Feature Good

You are using pass-by-reference, that assign a value to an input argument when it is the target of an assignment inside the procedure (see here f.e.)

2016-11-14 01_50_19-Feature or a bug_ Cannot force numeric evaluation within a function.png

the last assignment is missing; to assign the same value both to the result and to the input variable you have to define ID#:eval(ID#+1) even after the loop.

2016-11-14 01_53_10-2016-11-14 01_52_11-SMath Studio - [FunctionBug.sm_].png - Visualizzatore foto d.png


Davide, pass by reference assignment is intentional. What i do not understand is why
The result is 56 and not 10 - I used eval() to assign a static value to ID#, or so I thought, but ID# was assigned a dynamic ID# = ID# + 1, which was not the intent.
Offline Jean Giraud  
#4 Posted : 14 November 2016 05:20:37(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Forum Sum.gif
thanks 1 user thanked Jean Giraud for this useful post.
on 14/11/2016(UTC)
Offline mikekaganski  
#5 Posted : 14 November 2016 06:53:25(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Hey, in first block, you incremented ID by 1 in loop; in second you do it by self-incrementing i!
Best regards,
Mike Kaganski
thanks 2 users thanked mikekaganski for this useful post.
on 14/11/2016(UTC),  on 14/11/2016(UTC)
Offline Jean Giraud  
#6 Posted : 14 November 2016 08:12:24(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
... more conveniently and generalised.

Maths SUM.sm (11kb) downloaded 15 time(s).
thanks 1 user thanked Jean Giraud for this useful post.
on 14/11/2016(UTC)
Offline Davide Carpi  
#7 Posted : 14 November 2016 10:42:09(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1340 time(s) in 879 post(s)
Originally Posted by: Alex M. Go to Quoted Post
Davide, pass by reference assignment is intentional. What i do not understand is why
The result is 56 and not 10 - I used eval() to assign a static value to ID#, or so I thought, but ID# was assigned a dynamic ID# = ID# + 1, which was not the intent.

Ah! Now I see it.

Originally Posted by: mikekaganski Go to Quoted Post
Hey, in first block, you incremented ID by 1 in loop; in second you do it by self-incrementing i!

This is the cause Good

Edited by user 15 November 2016 01:35:21(UTC)  | Reason: marked as solved

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 14/11/2016(UTC)
Offline Alex M.  
#8 Posted : 14 November 2016 23:29:37(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Thank you all; so far I understood that something should be clear to me by now, but its not. What can I do to encapsulate a seemingly simple for() loop in a function that produces same result (10)?
FunctionBug1.sm (7kb) downloaded 11 time(s).
FunctionBug1.png
Offline omorr  
#9 Posted : 14 November 2016 23:50:23(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello Alex M.

I just hope that you did not see "1" - one instead if "i" in the loop.
Was that the problem or something else?

onenoti.png

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Alex M.  
#10 Posted : 15 November 2016 00:06:10(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: omorr Go to Quoted Post
Hello Alex M.

I just hope that you did not see "1" - one instead if "i" in the loop.
Was that the problem or something else?

onenoti.png

Regards,
Radovan


I was blind as a mole. Thanks

Edited by user 15 November 2016 21:45:16(UTC)  | Reason: Not specified

Offline Jean Giraud  
#11 Posted : 15 November 2016 08:40:00(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
I'm sure something I don't understand in there,
i.e: in what you are trying to do !

Sum Unknown.gif
Users browsing this topic
Guest
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.