Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Experiment - Different comparisons

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> ViviFire language
View previous topic :: View next topic  
Author Message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 729

PostPosted: Mar 31st, 2012, 6:25pm    Post subject: Experiment - Different comparisons Reply with quote

This is another thought experiment in which I send out feelers concerning VF's possible syntax. Please feel free to comment.

ViviFire will have comparison operators the same as LB and about every other language. The set includes equality (=), inequality (<>), less than (<), less than or equal (<=), greater than (>), and greater than or equal (>=).

One common task for comparison operators is to test if a value is within a range. For example, we might need to test if a person is of adult working age: between 18 and 65. In LB this might look like
Code:
If age >= 18 And age <= 65 Then ...

The only gripe about that example is that it is a bit verbose. However, if instead of having age in a variable, we have to call a function, it becomes more interesting.
Code:
If getAge(aPerson) >= 18 And getAge(aPerson) <= 65 Then ...

Not only is this verbose, it could have unforeseen side effects since the function is being called twice.

VF tries to solve this by using a shortcut syntax that any math aficionado would recognize.
Code:
If 18 <= age <= 65 Then ...
- or -
If 18 <= getAge(aPerson) <= 65 Then ...

Besides being a bit easier to determine what is intended, the example with the function call reduces to just a single call of getAge(), thus reducing the chances of unintended side effects.

Another area where comparisons are possible is the Require statement. You probably have seen this before if you have been reading my postings here, but I have not shown its full potential.

Reusable modules can specify some arbitrary metadata in the Module statement like so.
Code:
Module myModule, author="J Random Hacker", version=2.1.0

The name of the module is rather prone to name collisions, so we might need to disambiguate which "myModule" we want. If we want to use the one above we might write the following.
Code:
Require myModule Where author="J Random Hacker"

If we have multiple versions of the same author's myModule and need a particular version
Code:
Require myModule Where author="J Random Hacker" And version=2.1.0

But more frequently I think someone would want a minimum for the version.
Code:
Require myModule Where version >= 2.1.0

Occasionally, one might have several versions of the same module and prefer a range that balances needed functionality with perceived bloat.
Code:
Require myModule Where 2.0.1 <= version < 3.0.0

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
STPendl
Full Member


Joined: 20 Aug 2007
Posts: 161
Location: Austria

PostPosted: Mar 31st, 2012, 8:39pm    Post subject: Re: Experiment - Different comparisons Reply with quote

This syntax offers quite some possibilities, I like it Wink
_________________
Stefan

Any code I post can be freely used, just give credit.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> ViviFire language All times are GMT
Page 1 of 1
Jump to:  
Quick Reply
Username:
Message:
   Shortcut keys: Alt+Q to activate, Alt+P to preview, Alt+S to submit
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group