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 MarB  
#1 Posted : 26 March 2022 14:49:18(UTC)
MarB


Rank: Advanced Member

Groups: Registered
Joined: 21/10/2016(UTC)
Posts: 84

Was thanked: 21 time(s) in 17 post(s)
Hi!

Is this a bug in if()?

It turns to a real problem e.g. when used in a case like shown in the example.

bug_if.png
bug_if.sm (16kb) downloaded 11 time(s).

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

Offline overlord  
#2 Posted : 27 March 2022 03:18:52(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 1,124
Turkey

Was thanked: 506 time(s) in 337 post(s)
Originally Posted by: MarB Go to Quoted Post
Hi!

Is this a bug in if()?

It turns to a real problem e.g. when used in a case like shown in the example

Yes, it is a bug.

if() function doesn't like plotting, solvers, custom functions as in your example, etc.

You have to use cases() for that kind of usages.

Regards
Offline Davide Carpi  
#3 Posted : 29 March 2022 12:08:28(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1323 time(s) in 873 post(s)
Just to clarify, this is not a fault in the specific function, it works this way because the current architecture of the core doesn't allows a different implementation (thus can't be simply fixed with a change in the function itself).

if(...) currently requires the condition argument to be defined on evaluation, otherwise an error is thrown; this makes the if/else instructions sealed from further evaluations of the preprocessor.

As opposite cases(...) doesn't throw errors on simbolic conditions, but this makes instructions evaluable (thus you shouldn't add any definition in the case() arguments).



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 29/03/2022(UTC)
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.