Results 1 to 9 of 9

Thread: Circular Next/Previous

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Circular Next/Previous

    I've developed 2 new functions to simplify circular numbers that is numbers that must have a range of values and be incremented/decremented by something but when they reach their bounds (upper or lower) they restart from the other side.

    For example imagine you have a set of options from 1 to 4 and want always add 1 but when it reach 4, adding 1 will restart from 1. The same when subtracting 1 if it will reach 1 it will restart from 4.

    I've developed the following 2 functions:
    MyNumber = NNEXT(MyNumber, nMin, nMax, nIncr)
    MyNumber = NPREV(MyNumber, nMin, nMax, nDecr)
    
    but I do not like the names: NNEXT and NPREV.

    Do you have something to suggest? I was thinking about CIRCULAR_NEXT and CIRCULAR_PREV

    Ciao
    Eros
    Last edited by ErosOlmi; 10-06-2013 at 22:30.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    637
    Rep Power
    83

    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
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    637
    Rep Power
    83

    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
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736

    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Re: Circular Next/Previous

    I like CYCLE_NEXT and CYCLE_PREV
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    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.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  8. #8

    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

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    This is quite old: 2008. Almost 5 years ago discussion.

    Well, 5 years ago we had much less options we have now in thinBasic.
    if I had to develop this feature right now I would use thinBasic module classes in order to have something like the following:

    ...
    Dim MyIter as cIterator
    MyIterator = New cIterator(MinVal, MaxVal, CurrentVal)
    MyIterator.Incr[(<AnyNumberIfNotOne>)]
    MyIterator.Decr[(<AnyNumberIfNotOne>)]
    MyIterator.GetCurVal
    MyIterator.Set(<any number>)
    ...
    
    So it would be a class with a create method and some additional methods in order to use it.

    See cTimer class example/help
    Last edited by ErosOlmi; 10-06-2013 at 22:45.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •