Subject: Experiment - Different comparisons
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

Subject: Re: Experiment - Different comparisons
This syntax offers quite some possibilities, I like it ;)


Page 1 of 1


Jump to:  
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

Full Version
Powered by phpBB © phpBB Group
Design by phpBBXS.Com | Lo-Fi Mod.