Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Does QB64pe already have a function like IFF ?
#11
(06-05-2023, 04:26 PM)bplus Wrote: Hi Charlie what does BAM do here?
Code: (Select All)
Boolean = (7 < 8) ' this is a boolean expression NOT a string! that evaluates to 1 or -1
Print Boolean

Boolean = (7 > 8) '  this is a boolean expression NOT a string! that evaluates to 0
Print Boolean
I ask because IFF typically takes a numeric expression that evaluates to "True" or "False" numerically -1 or 1 and 0 for false.

mnrvovrfc had it setup correctly, I don't see where you are inferring a string expression for the first parameter.

The first expression in IFF can be anything that results in either TRUE (i.e. anything other than zero) or FALSE (i.e. zero).

The second expression IFF will be the return value when the first expression yields "TRUE" (i.e. non-zero).  The second expression can be anything at all that results in either a number or a string.

The third expression in IFF will be the return value when "FALSE" (i.e. zero).  The third expression can be anything at all that results in either a number or a string.



   
Reply
#12
(06-05-2023, 04:26 PM)bplus Wrote: I ask because IFF typically takes a numeric expression that evaluates to "True" or "False" numerically -1 or 1 and 0 for false.

That's incorrect.

The first parameter in IFF is an expression that results in an integer number (or any number, really; the number will get treated as an integer).

The expression in the first parameter of IFF could be as simple as a literal number, or a numeric constant, or a numeric variable.   Or it could be a function that returns a number.  Or it could be any kind of complex expression that results in a number.
Reply
#13
(06-05-2023, 04:47 PM)CharlieJV Wrote:
(06-05-2023, 04:26 PM)bplus Wrote: I ask because IFF typically takes a numeric expression that evaluates to "True" or "False" numerically -1 or 1 and 0 for false.

That's incorrect.

The first parameter in IFF is an expression that results in an integer number (or any number, really; the number will get treated as an integer).

The expression in the first parameter of IFF could be as simple as a literal number, or a numeric constant, or a numeric variable.   Or it could be a function that returns a number.  Or it could be any kind of complex expression that results in a number.

Huh, and now I'm also incorrect.

Just tried, and:

If the first expression is a null string, then FALSE expression happens..

If the first expression is a non-null string, then TRUE expression happens.

This has me thinking: potential use cases?

Ooooooo:

Code: (Select All)
IFF( name$, name$, "Guest")

   
Reply
#14
(06-05-2023, 04:47 PM)CharlieJV Wrote:
(06-05-2023, 04:26 PM)bplus Wrote: I ask because IFF typically takes a numeric expression that evaluates to "True" or "False" numerically -1 or 1 and 0 for false.

That's incorrect.

The first parameter in IFF is an expression that results in an integer number (or any number, really; the number will get treated as an integer).

The expression in the first parameter of IFF could be as simple as a literal number, or a numeric constant, or a numeric variable.   Or it could be a function that returns a number.  Or it could be any kind of complex expression that results in a number.
So why are you saying IFF(string, ...   ? 

It should be IFF(integer, ...

I quote you: "This IFF in BAM will only work with primitive types (string, integer, floating point)."
b = b + ...
Reply
#15
(06-05-2023, 04:53 PM)CharlieJV Wrote:
(06-05-2023, 04:47 PM)CharlieJV Wrote:
(06-05-2023, 04:26 PM)bplus Wrote: I ask because IFF typically takes a numeric expression that evaluates to "True" or "False" numerically -1 or 1 and 0 for false.

That's incorrect.

The first parameter in IFF is an expression that results in an integer number (or any number, really; the number will get treated as an integer).

The expression in the first parameter of IFF could be as simple as a literal number, or a numeric constant, or a numeric variable.   Or it could be a function that returns a number.  Or it could be any kind of complex expression that results in a number.

Huh, and now I'm also incorrect.

Just tried, and:

If the first expression is a null string, then FALSE expression happens..

If the first expression is a non-null string, then TRUE expression happens.

This has me thinking: potential use cases?

Ooooooo:

Code: (Select All)
IFF( name$, name$, "Guest")

Hi Charlie, could you show me a quick copy of BAM code for IFF? or are you using some Javascript jazz?
b = b + ...
Reply
#16
(06-05-2023, 04:55 PM)bplus Wrote:
(06-05-2023, 04:47 PM)CharlieJV Wrote:
(06-05-2023, 04:26 PM)bplus Wrote: I ask because IFF typically takes a numeric expression that evaluates to "True" or "False" numerically -1 or 1 and 0 for false.

That's incorrect.

The first parameter in IFF is an expression that results in an integer number (or any number, really; the number will get treated as an integer).

The expression in the first parameter of IFF could be as simple as a literal number, or a numeric constant, or a numeric variable.   Or it could be a function that returns a number.  Or it could be any kind of complex expression that results in a number.
So why are you saying IFF(string, ...   ? 

It should be IFF(integer, ...

I quote you: "This IFF in BAM will only work with primitive types (string, integer, floating point)."

Where and when did I ever say " IFF(string, ..."   ?
Reply
#17
(06-05-2023, 05:01 PM)bplus Wrote:
(06-05-2023, 04:53 PM)CharlieJV Wrote:
(06-05-2023, 04:47 PM)CharlieJV Wrote: That's incorrect.

The first parameter in IFF is an expression that results in an integer number (or any number, really; the number will get treated as an integer).

The expression in the first parameter of IFF could be as simple as a literal number, or a numeric constant, or a numeric variable.   Or it could be a function that returns a number.  Or it could be any kind of complex expression that results in a number.

Huh, and now I'm also incorrect.

Just tried, and:

If the first expression is a null string, then FALSE expression happens..

If the first expression is a non-null string, then TRUE expression happens.

This has me thinking: potential use cases?

Ooooooo:

Code: (Select All)
IFF( name$, name$, "Guest")

Hi Charlie, could you show me a quick copy of BAM code for IFF? or are you using some Javascript jazz?

BAM does not do javascript, and I can't ever see me allowing BAM to do javascript.  New BASIC statements/functions that might not exist in other BASIC implementations, and often non-strict typing, but no javascript crap.

   
Reply
#18
OK I read more into that line "I quote you" than was there, sorry.
b = b + ...
Reply
#19
(06-05-2023, 05:06 PM)CharlieJV Wrote:
(06-05-2023, 05:01 PM)bplus Wrote:
(06-05-2023, 04:53 PM)CharlieJV Wrote: Huh, and now I'm also incorrect.

Just tried, and:

If the first expression is a null string, then FALSE expression happens..

If the first expression is a non-null string, then TRUE expression happens.

This has me thinking: potential use cases?

Ooooooo:

Code: (Select All)
IFF( name$, name$, "Guest")

Hi Charlie, could you show me a quick copy of BAM code for IFF? or are you using some Javascript jazz?

BAM does not do javascript, and I can't ever see me allowing BAM to do javascript.  New BASIC statements/functions that might not exist in other BASIC implementations, and often non-strict typing, but no javascript crap.
OK not javascript crap ;-)) 

I was just wondering how you have IFF( ) coded for BAM, interesting that it allows both string and I assume numeric expressions for first parameter.

Nevermind, I guess you went over all this at beginning of thread. I was surprised BAM not sticking strictly to types.
b = b + ...
Reply
#20
(06-05-2023, 05:15 PM)bplus Wrote:
(06-05-2023, 05:06 PM)CharlieJV Wrote:
(06-05-2023, 05:01 PM)bplus Wrote: Hi Charlie, could you show me a quick copy of BAM code for IFF? or are you using some Javascript jazz?

BAM does not do javascript, and I can't ever see me allowing BAM to do javascript.  New BASIC statements/functions that might not exist in other BASIC implementations, and often non-strict typing, but no javascript crap.
OK not javascript crap ;-)) 

I was just wondering how you have IFF( ) coded for BAM, interesting that it allows both string and I assume numeric expressions for first parameter.

Nevermind, I guess you went over all this at beginning of thread. I was surprised BAM not sticking strictly to types.

Well, making changes/additions to the interpreter (wwwBASIC.js), that is all javascript crap all the time.  Drives me insane, but gotta deal with the pain to get this browser-based BASIC juuuuuust right.

The javascript code to implement IIF:

 
Code: (Select All)
      if (name=='iff') {
          Skip('(');
          var a = Expression();
          Skip(',');
          var b = Expression();
          Skip(',');
          var c = Expression();
          Skip(')');
          return '('+ a + ' ? ' + b + ' : ' + c + ')';
  }
Reply




Users browsing this thread: 1 Guest(s)