Page 1 of 1

Clarification regarding Logical functions.

PostPosted: Tue Jan 22, 2013 3:02 am
by Viswanathchandru
Dear all,

I have a small logical function part which decides which one should be executed next. I was trying this from morning not sure if I'm wrong but seems the way I tried was correct. Its a very basic idea. The script counts the no of lines(1255) and if the value is less than 1255 and greater than 0 I need to execute some other function/para. I wrote the condition like this.

IF VAR4 << 1255  AND VAR4 > 0 THEN
  CALL FILMAN2
ELSE
CALL PAGEON


Trace shows the value of VAR4 is 1255 and hence the condition should fail and it should execute PAGEON para/function. But it gets a logical value =1( Trace output) and executes FILEMAN2. Please correct me if I'm wrong.


Regards,
Viswa

Re: Clarification regarding Logical functions.

PostPosted: Tue Jan 22, 2013 3:07 am
by prino
Ever thought about reading a manual? REXX \= COBOL!

Re: Clarification regarding Logical functions.

PostPosted: Tue Jan 22, 2013 3:13 am
by Viswanathchandru
Hi Prino,

Thanks for your time. I'm not understanding your thoughts. I can understand that Rexx is not like COBOL but why here?

Re: Clarification regarding Logical functions.

PostPosted: Tue Jan 22, 2013 3:30 am
by enrico-sorichetti
You were given already quite a few times the links to the Rexx manuals
did Yo ever care to use them ???

and why not use parentheses to show the logic

and why invent a logical AND operator when the & is more than enough ...

and why use the << which is the <strict> comparison operator

anyway here is what happens ...

rexx finds var4... <== shift
rexx finds an operator ( irrelevant if logical ) <== shift
rexx finds 1255 <== shift
rexx finds the " " abuttal operator <== shift
rexx finds the AND <== shift
rexx finds the < and ...
..... reduces the 1255 concatenation with the and
..... reduces the first comparison operator
which yields TRUE ==> the value 1
stacks the result, shifts the >
shifts the 0
at end of the statement
it reduces the comparison between 1 and 0
and finally it returns true

simply following the rules of the rexx grammar

Re: Clarification regarding Logical functions.

PostPosted: Tue Jan 22, 2013 3:32 am
by Akatsukami
Viswanathchandru wrote:Dear all,

I have a small logical function part which decides which one should be executed next. I was trying this from morning not sure if I'm wrong but seems the way I tried was correct. Its a very basic idea. The script counts the no of lines(1255) and if the value is less than 1255 and greater than 0 I need to execute some other function/para. I wrote the condition like this.

IF VAR4 << 1255  AND VAR4 > 0 THEN
  CALL FILMAN2
ELSE
CALL PAGEON


Trace shows the value of VAR4 is 1255 and hence the condition should fail and it should execute PAGEON para/function. But it gets a logical value =1( Trace output) and executes FILEMAN2. Please correct me if I'm wrong.


Regards,
Viswa

Why did you use the "strictly less than" (<<) operator? Are you sure that VAR4 is strictly less than 1255?

Why did you use the word "AND" rather than the logical AND symbol (&)? The results will not be the same.

Did you trace execution displaying Intermediates or just Results?

Re: Clarification regarding Logical functions.

PostPosted: Tue Jan 22, 2013 3:36 am
by Viswanathchandru
Hi Akatsukami,

Yes I'm Sure, VAR4 is strictly less than 1255.


Regards,
Viswa

Re: Clarification regarding Logical functions.

PostPosted: Tue Jan 22, 2013 3:38 am
by Akatsukami
Viswanathchandru wrote:Hi Akatsukami,

Yes I'm Sure, VAR4 is strictly less than 1255.


Regards,
Viswa

Well, Dr. Sorichetti just explained why you're wrong, so perhaps you should be less sure.

Re: Clarification regarding Logical functions.

PostPosted: Tue Jan 22, 2013 3:42 am
by enrico-sorichetti
Yes I'm Sure, VAR4 is strictly less than 1255.


if instead of replying to Akatsukami Sama You had read my post we would not be here wasting time :evil:

the AND is not a flucking REXX logical operator

run a snippet like

VAR4 = ...
trace "I"
say VAR4 << 1255
say VAR4 << 1255 AND
say VAR4 << 1255 AND > 0

and You will understand what is going on

Re: Clarification regarding Logical functions.

PostPosted: Tue Jan 22, 2013 3:46 am
by enrico-sorichetti
also meditate on the manual about the <strict> comparison operators

run this snippet and You will see the gotchas

numeric digits 4

if  "a" = "a   " then ,
    say one
else ,
    say two

if  "a" == "a   " then ,
    say one
else ,
    say two


a = 9999 + 9999

say a

say 19998 = a
say 19998 == a





as a general idea the strict operators do not carry on any <conversion> and act on the RAW variable strings

Re: Clarification regarding Logical functions.

PostPosted: Tue Jan 22, 2013 5:26 pm
by Viswanathchandru
Thanks a lot enrico for your time.


Regards,
Viswa