Re: Circular Next/Previous
Hi Eros,
This is similar to a request for a cyclic string I made some time ago - so how about:
CYCLENEXT ; CYCLEPREVIOUS
or CYCLE_FORWARD; CYCLE_BACK
Cheers,
catventure
Re: Circular Next/Previous
Yes, you are right :-[ http://community.thinbasic.com/index.php?topic=1754.0
I will revamp it while I'm working on that.
Thanks for remembering to me.
Eros
Re: Circular Next/Previous
I had forgotten all about it... :)
But maybe you are already on the right track to make it with similar adaptation to the new "StrFormat$" command?
"StrFormat$" looks very interesting new string command.
Bye,
catventure
Re: Circular Next/Previous
Hi Eros,
very useful function.
Hard to invent the name, maybe we could use that CYCLE_NEXT, CYCLE_PREV or INTERVAL_NEXT, INTERVAL_PREV.
Petr
Re: Circular Next/Previous
I like CYCLE_NEXT and CYCLE_PREV
Re: Circular Next/Previous
I like the idea of this new command a lot.
CYCLE_NEXT / CYCLE_PREV does not look too BASIC like to me, especially if it will be a core language command and not a special module command like tbgl.
It seems to match BASIC more it should be 2 separate words or one word.
Another idea about circular prev/next
Well, I am way WAY late to this party, but since I had considered this feature myself some years ago, I thought you might like my two cents.
First, ideally you'd like to be able to define an enumeration of items for your prev/next operation. Maybe:
ENUM myEnum() AS WORD = MyNumber, nMin, nMax, nIncr
This is different that BEGIN/END CONST, because that *defines* the constants, but the enumeration defines a particular *use* of those constants.
Of course, such an ENUM list would be static as coded above. You would be able to assign an ENUM at runtime:
myEnum = (MyNumber, nMin, nMax, nIncr)
You would also be able to clear the enum:
myEnum = ()
and add new items:
myEnum += (nDecr)
or remove them:
myEnum -= (nMin)
Now, as part of the enumeration, you have an implied "iterator" (in the C++ sense of the word), so that when you are going forward or backward, the iterator gets incremented or decremented. In the case of this example, there are 4 initial entries. Assuming the iterator was 0-based, you would get an index to the 'next' item by
iterator = (iterator + 1) MOD 4
and if it was 1-based,
iterator = (iterator MOD 4) + 1
The fact that a modulus operation is implied suggests a good name for this.
So, when you wanted a 'circular next' for your enumeration, it could be:
MOD INCR myEnum
and
MOD DECR myEnum
You'd need some kind of syntax to set the iterator to the first or last entry of the enumeration. Obvious syntax might be:
MOD FIRST myEnum
MOD LAST myEnum
but I am less certain about this part of it.
If you wanted to get the "location" where the iterator is currently pointing (as an index value between 1 and the number of entries currently held in the enumeration), MOD LOC myEnum would do it. It is possible that all of the enumerated entries might have been deleted, so MOD LOC might return 0.
Finally, when you just the currently-set value where the iterator is pointing to, you would simply use myEnum as a plain value.
Well, that's my 2¢ worth