SPONSORS:






User Tag List

Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Jun 2001
    Location
    Bedford, MA, USA
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using an enumerated type value in ListFind

    OK, so very few people will care about this but...
    The ListFind function does not work with an ennumerated type as the object of the search. Here's an example.

    code:
    ____________________________________________

    type SUITES is enum
    DIAMOND
    HEART
    SPADE
    CLUB


    main()
    integer iIndex = 0
    list of integer liSuitesInMyHand = {3,4,4,3,1,2}

    iIndex = ListFind(liSuitesInMyHand, DIAMOND)

    print(iIndex) // should return 5 in this case
    _____________________________________________

    In this case I expect ListFind to return a 5 because the value 1, i.e. the "diamond" is the 5th card in my hand. But ListFind always returns 0, meaning it could not find the 1 in the list. Clearly it's not looking for a 1. It must be looking for a literal string of "DIAMOND" which makes no sense.

    Silk translates the enum just fine when used as an index.
    code:
    _______________________________________
    liSuitesInMyHand[DIAMOND]______________________________________
    Not that the above example is logical, but it works.

    Does the fellowship see this as a Silk bug or a user error?

    Thanks for your attention.
    - Jim

    ------------------

  2. #2
    Member
    Join Date
    Jun 2001
    Location
    Bedford, MA, USA
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Using an enumerated type value in ListFind

    Thank you TC and John for your thoughtful solutions. Casting the enum name to an integer worked fine.

    It's interesting to me that Silk lets me put emum values into the list of integers:
    code:
    _____________________________________
    ListAppend(liSuitesInMyHand, DIAMOND)
    _____________________________________
    But once they're in there it can not "find" them without using an explicit cast.
    code:
    _____________________________________
    ListFind(liSuitesInMyHand, [integer]DIAMOND)
    _____________________________________

    Silk must be doing an implicit cast at ListAppend time?

    I always thought of enum values as integer values with names, e.g. DIAMOND=1, HEART=2, etc. but I guess Silk makes a distinction.

    - Jim

    ------------------

  3. #3
    Member
    Join Date
    Aug 2002
    Location
    Durham, NC USA
    Posts
    60
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Using an enumerated type value in ListFind

    This seems to me more like a feature than a bug (just like the "can't use an assignment as a test" thing). It looks like Silk is trying to keep the user from common programming error, which may or may not be a positive thing if you are the programmer.

    If the list is of the SUITES type, the function finds as expected, or you can cast (e.g. ListFind(liSuitesInMyHand,[INTEGER]DIAMOND)) the search parameter and there is no trouble.

    It looks like it's just trying to prevent the programmer from unintentionally finding something that is not specifically in the list.

    This also seems to mean that the enumerated types are used at runtime instead of compile time. Intriguing.

    -TC
    --
    Tim Crone
    Broadcom

  4. #4
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Using an enumerated type value in ListFind

    The solution here is that the data type of the list being searched needs to match the data type of the item being located. Your ListFind() call is looking in a list of integers for an ENUM. If you were to cast the find value like this:

    you'd be searching a list of integers for a matching integer and it would work.

    Note that if you instead defined the "list of enum ... " as

    your existing ListFind() call would work.

    Does your example expose a hole in Silk's implied ANYTYPE-processing for the ListFind() function? Possibly. Submit it as a problem to Segue Support and let us know what they say.

    As a side note, you might consider avoiding the use of literal integer values as equivalent replacements for enum labels in your actual testcases because that association cannot be trusted. Just one addition or deletion of an enum value will trash every integer reference that depended on the original sequence.


    John


    ------------------

 

 

Posting Permissions

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

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 05:55 AM.

Copyright BetaSoft Inc.