arturo-lang / arturo

Simple, expressive & portable programming language for efficient scripting
http://arturo-lang.io
MIT License
718 stars 32 forks source link

[Comparison\compare] verify it's working right #1377

Open github-actions[bot] opened 10 months ago

github-actions[bot] commented 10 months ago

[Comparison\compare] verify it's working right The main problem seems to be this vague else:. In a few words: Even comparisons that are simply not possible will return 1 (!) see also: https://github.com/arturo-lang/arturo/pull/1139#issuecomment-1509404906

https://github.com/arturo-lang/arturo/blob/411617a1906063cf0adfd3ac06804dc4b29403a0/src/library/Comparison.nim#L39

#=======================================
# Definitions
#=======================================

# TODO(Comparison) add built-in function for "approximately equal"
#  This could serve in cases where we want to compare between weirdly-rounded floating-point numbers and integers, e.g.: 3.0000001 and 3.
#  But: we'll obviously have to somehow "define" this... approximate equality.
#  labels: library, enhancement, open discussion

proc defineLibrary*() =

    #----------------------------
    # Functions
    #----------------------------

    # TODO(Comparison\compare) verify it's working right
    #  The main problem seems to be this vague `else:`.
    #  In a few words: Even comparisons that are simply not possible will return 1 (!)
    #  see also: https://github.com/arturo-lang/arturo/pull/1139#issuecomment-1509404906
    #  labels: library, critical, bug
    builtin "compare",
        alias       = unaliased, 
        op          = opNop,
        rule        = PrefixPrecedence,
        description = "compare given values and return -1, 0, or 1 based on the result",
        args        = {
            "valueA": {Any},
            "valueB": {Any}
        },
        attrs       = NoAttrs,
        returns     = {Integer},
        example     = """
            compare 1 2           ; => -1
            compare 3 3           ; => 0
            compare 4 3           ; => 1
        """:
            #=======================================================
            if x < y:
                push(I1M)
            elif x == y:
                push(I0)
            else:
                push(I1)

    #----------------------------
    # Predicates
    #----------------------------

    builtin "between?",
        alias       = thickarrowboth, 

cedaca62ab8fe1ed225bb4a8f1517c8a96433034

RickBarretto commented 10 months ago

Should this raise an error? Or return null?

Since you told me that you'll change some things for the Error lib, I won't touch this for while.

stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.