Post Reply 
Type control
03-13-2015, 03:18 PM (This post was last modified: 03-13-2015 06:05 PM by salvomic.)
Post: #21
RE: Type control
(03-13-2015 03:04 PM)Han Wrote:  Ensure there are no conflicts between the CAS version of myprog and the non-CAS version of myprog. In other words, name them differently to make sure that when you type myprog you aren't running the wrong program (since different programs can actually have the same name). As for the error (w/ respect to the second code block in your post), it is being generated much further inside your program. What you have posted there does not produce any errors.

thank you!
I'll control soon.
However, please, see my ANOVA program (here)
If I use the function ANOVA_list() (that need values in D1, D2, D3 of Statistic 1var) without parameters, in CAS I get "Error: Bad argument value", in Home I get "Error: Syntax error", but with something like ANOVA_list(0.01) the program seems to work...
I've in the code some controls like:
Code:

local spar;
spar:= SIZE(a);
IF (TYPE(spar)==6 OR TYPE(a)<>0) THEN RETURN("Usage: ANOVA_list(a) a=significance level; data in Stat 1var");  END;
IF ((spar==0)) THEN RETURN("Usage: ANOVA_list(a) a=significance level; data in Stat 1var"); END;
IF (a <=0 OR a>= 1) THEN RETURN("Significance level must be > 0 AND <1"); END;
IF ((size(D1) == 0) OR (size(D1) == 0) OR (size(D3) = 0)) THEN RETURN("Statistics 1var, D1 means, D2 stddev, D3 numerosity"); END;
I would like to give a message when the user input ANOVA_list() without parameter... and also when it gives wrong parameter (but this seems to work).

But the line
Code:

IF ((spar==0)) THEN RETURN("Usage: ANOVA_list(a) a=significance level; data in Stat 1var"); END;

in this non CAS program perhaps does nothing and it doesn't intercept the error: with input ANOVA_list() without a number the program give the error and not the message...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-13-2015, 06:14 PM
Post: #22
RE: Type control
(03-13-2015 03:18 PM)salvomic Wrote:  
(03-13-2015 03:04 PM)Han Wrote:  Ensure there are no conflicts between the CAS version of myprog and the non-CAS version of myprog. In other words, name them differently to make sure that when you type myprog you aren't running the wrong program (since different programs can actually have the same name). As for the error (w/ respect to the second code block in your post), it is being generated much further inside your program. What you have posted there does not produce any errors.

thank you!
I'll control soon.
However, please, see my ANOVA program (here)
If I use the function ANOVA_list() (that need values in D1, D2, D3 of Statistic 1var) without parameters, in CAS I get "Error: Bad argument value", in Home I get "Error: Syntax error", but with something like ANOVA_list(0.01) the program seems to work...
I've in the code some controls like:
Code:

local spar;
spar:= SIZE(a);
IF (TYPE(spar)==6 OR TYPE(a)<>0) THEN RETURN("Usage: ANOVA_list(a) a=significance level; data in Stat 1var");  END;
IF ((spar==0)) THEN RETURN("Usage: ANOVA_list(a) a=significance level; data in Stat 1var"); END;
IF (a <=0 OR a>= 1) THEN RETURN("Significance level must be > 0 AND <1"); END;
IF ((size(D1) == 0) OR (size(D1) == 0) OR (size(D3) = 0)) THEN RETURN("Statistics 1var, D1 means, D2 stddev, D3 numerosity"); END;
I would like to give a message when the user input ANOVA_list() without parameter... and also when it gives wrong parameter (but this seems to work).

You need to use CASE and not separate IF statements. Suppose a is not a number object. Without using CASE, then your program will reach the third IF statement. However, the check IF (a<=0 OR a>=1) would not make sense and this is the cause of your error, since the <= and >= operators may not properly return the correct result to be used by the OR command. For example, try:

{1,2} >= {0,5} and you will see {1,0}

{1,0} OR {0,0} and the result is {1,0}

However, an IF statement does not know what to do with a list -- IF ({1,0}) makes no sense. To avoid this, you need to use CASE blocks surrounding your IF statements so that a list input in captured by only one IF statement and then program control is passed to the point beyond the end of the CASE block (i.e. skips all other IF tests).

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
03-13-2015, 06:29 PM (This post was last modified: 03-13-2015 06:30 PM by salvomic.)
Post: #23
RE: Type control
(03-13-2015 06:14 PM)Han Wrote:  You need to use CASE and not separate IF statements. Suppose a is not a number object. Without using CASE, then your program will reach the third IF statement. However, the check IF (a<=0 OR a>=1) would not make sense and this is the cause of your error...

To avoid this, you need to use CASE blocks surrounding your IF statements so that a list input in captured by only one IF statement and then program control is passed to the point beyond the end of the CASE block (i.e. skips all other IF tests).

I should control that a value is from 0 (excluded) and 1 (excluded): (0..1)

CASE. Do you mean like so?
Code:

CASE
IF (TYPE(spar)==6 OR TYPE(a)<>0) THEN RETURN("Usage: ANOVA_list(a) a=significance level; data in Stat 1var");  END;
IF ((spar==0)) THEN RETURN("Usage: ANOVA_list(a) a=significance level; data in Stat 1var"); END;
IF (a <=0 OR a>= 1) THEN RETURN("Significance level must be > 0 AND <1"); END;
IF ((size(D1) == 0) OR (size(D1) == 0) OR (size(D3) = 0)) THEN RETURN("Statistics 1var, D1 means, D2 stddev, D3 numerosity"); END;
END; // case

A priority list should be: control if value "a" is given, then if D1, D2 and D3 are set, than if a is from 0 to 1 (non include the limits), then if a is a number and only a number...

thanks!

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-13-2015, 06:34 PM
Post: #24
RE: Type control
(03-13-2015 06:29 PM)salvomic Wrote:  A priority list should be: control if value "a" is given, then if D1, D2 and D3 are set, than if a is from 0 to 1 (non include the limits), then if a is a number and only a number...

That doesn't make sense. How can you check if a is from 0 to 1 without first checking to see that a is in fact a number? I didn't read much into your code, except to look for how control flow was giving you errors.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
03-13-2015, 06:44 PM (This post was last modified: 03-13-2015 06:46 PM by salvomic.)
Post: #25
RE: Type control
(03-13-2015 06:34 PM)Han Wrote:  That doesn't make sense. How can you check if a is from 0 to 1 without first checking to see that a is in fact a number? I didn't read much into your code, except to look for how control flow was giving you errors.

thank you for your patience Smile
in fact I'm trying doing that: control if "a" is a number, but first if it was given (and this only doesn't works):

new code:
Code:

BEGIN local spar;
spar:= SIZE(a);
CASE
IF ((spar==0)) THEN RETURN("Usage: ..."); END
IF (TYPE(spar)==6 OR TYPE(a)<>0) THEN RETURN("Usage: ...");  END
// control to avoid lists {} and []...
IF (a <=0 OR a>= 1) THEN RETURN("Significance level must be > 0 AND <1"); END
// control for interval
IF ((size(D1) == 0) OR (size(D1) == 0) OR (size(D3) = 0)) THEN RETURN("Statistics 1var, D1 ..."); END
DEFAULT
END; // case

only the IF spar==0 doesn't control for no input, IMHO...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-13-2015, 10:39 PM
Post: #26
RE: Type control
Han,
so it goes better:

Code:

EXPORT ANOVA(a)
...
BEGIN
CASE
IF (SIZE(a)==0) THEN a:=0.05; END;
IF (TYPE(a)<>0) THEN ANOVA_help(); RETURN("Usage: ANOVA(a)");  END;
IF (a <=0 OR a>= 1) THEN RETURN("Significance level must be > 0 AND <1"); END;
DEFAULT
END; // case
...

I control that "a" be a number (or give the user a function with help), and if it's a number that its value be in the interval.
But SIZE(a)==0 still doesn't work.
I thought to make "a" parameter option, but I don't remember if it's possible in EXPORT myfunction()... or not.
i.e. EXPORT ANOVA(a:=0.05) doesn't work.

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-14-2015, 09:49 AM (This post was last modified: 03-14-2015 09:53 AM by Han.)
Post: #27
RE: Type control
(03-13-2015 10:39 PM)salvomic Wrote:  Han,
so it goes better:

Code:

EXPORT ANOVA(a)
...
BEGIN
CASE
IF (SIZE(a)==0) THEN a:=0.05; END;
IF (TYPE(a)<>0) THEN ANOVA_help(); RETURN("Usage: ANOVA(a)");  END;
IF (a <=0 OR a>= 1) THEN RETURN("Significance level must be > 0 AND <1"); END;
DEFAULT
END; // case
...

I control that "a" be a number (or give the user a function with help), and if it's a number that its value be in the interval.
But SIZE(a)==0 still doesn't work.
I thought to make "a" parameter option, but I don't remember if it's possible in EXPORT myfunction()... or not.
i.e. EXPORT ANOVA(a:=0.05) doesn't work.

Salvo

It appears I misunderstood you, then. If you want to have a sequence of control flow in which you add more conditions that must be met, then you need to nest your if statements:

Code:
IF (TYPE(a)<>0) THEN
    ANOVA_help(); RETURN("Usage: ANOVA(a)"); 
ELSE
    IF (a <=0 OR a>= 1) THEN
      RETURN("Significance level must be > 0 AND <1");
    ELSE
    ... (rest of your code here)
    END;
END;

There's no point to checking the size of 'a' since multiple arguments in Home view would produce an argument count error (no list behavior like in CAS view) as your program only specifies one argument (which must be given in order for the program to even run).

Non-CAS programs cannot be "overloaded" to handle both cases in which an argument is passed, or when no arguments are passed. You have to specify one or the other. This is why the SIZE(a)==0 check is redundant. Just to be clear, this is regarding the behavior of a non-CAS program.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
03-14-2015, 10:00 AM (This post was last modified: 03-14-2015 10:02 AM by salvomic.)
Post: #28
RE: Type control
(03-14-2015 09:49 AM)Han Wrote:  If you want to have a sequence of control flow in which you add more conditions that must be met, then you need to nest your if statements:
I'll try your solution in the afternoon, thanks
Quote:There's no point to checking the size of 'a' since multiple arguments in Home view would produce an argument count error (no list behavior like in CAS view) as your program only specifies one argument (which must be given in order for the program to even run).

Non-CAS programs cannot be "overloaded" to handle both cases in which an argument is passed, or when no arguments are passed. You have to specify one or the other. This is why the SIZE(a)==0 check is redundant. Just to be clear, this is regarding the behavior of a non-CAS program.

In fact, my problem was here: I would to "overload" and to handle (as I do in CAS programs) is a parameter is passed, and (if yes) whether it's only one, it's a number and so on...
Ok, if there is no solution, my controls (with your advice) will be "better than nothing" Smile

EDIT: a trick could be give the parameter a default value, but...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)