lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Once, great Soni, wrote:
Does this mean functions should only ever accept other functions for arguments, otherwise it's not strong typed?

I don't think "strong typed languages" concept applies to function arguments (never heard of anything on this).
Converting a string to a number and allowing it to be summed to another number doesn't feel "natural".
Maybe that is the same reason why strings cannot be "summed" (therefore "..").
Not "really" the subject in question but, .. also has an very strange behavior. If both operands are strings or numbers,
it converts whichever operands needs to be converted to string, then concatenates. This behavior could be applied to all types,
but, boolean, per example, generates an error. It would be quite natural for "house is " .. true to output "house is true".

The example on the previous e-mail would look like this, if lua had a "stronger" type behavior (as I see it):

> -- lua 5.3
> 5+'5'
error -- 10.0
> 5+5
10
> 10.0 == 10
true
> tostring(5+'5') == tostring(5+5)
error -- false
> 5 .. '5'
55
>> 5 .. 5
55
>> 5 .. true
5true -- .. stringifies both sides before concatenating
> tostring(5..'5') == tostring(5..5)
true
> 5..5
55 -- error (this actually feels like a bug, because '5'..'5' works)
> '5'..'5'
55
> 5*5
25
> '5'*'5'
error -- 25

2017-06-19 20:21 GMT-03:00 Soni L. <fakedme@gmail.com>:


On 2017-06-19 08:11 PM, Italo Maia wrote:
Thanks for the example, *Soni*. Although I cannot read rust to save my life (nor mandarin, as a matter of fact), I understand what you put there. It still seems vague when a language can be considered strong or weakly typed. In my understanding, if all operations defined in the language only work with the same type (number and number, string and string, etc), unless explicitly defined otherwise, it is strong typed.

Does this mean functions should only ever accept other functions for arguments, otherwise it's not strong typed?


2017-06-19 20:04 GMT-03:00 Italo Maia <italo.maia@gmail.com <mailto:italo.maia@gmail.com>>:

    Ok ... then, could someone provide an example of a weakly typed
    language? If there is no problem to operate on different types
    because the operation is defined, I'm quite unsure of what could
    be weakly typed.

    2017-06-19 20:00 GMT-03:00 Andrew Starks <andrew@starksfam.org
    <mailto:andrew@starksfam.org>>:


        On Mon, Jun 19, 2017 at 17:52 Italo Maia <italo.maia@gmail.com
        <mailto:italo.maia@gmail.com>> wrote:

                (1) it's an explicitly documented behavior of the +
                operator


            I'm unsure if documenting it makes it "ok" to use and
            still be consider it strongly typed. _javascript_ would kind
            of splash close in that pool. But the string concatenation
            operator does add some spice to the mix.

            > -- lua 5.3
            > 5+'5'
            10.0
            > 5+5
            10
            > 10.0 == 10
            true
            > tostring(5+'5') == tostring(5+5)
            false
            > 5 .. '5'
            55
            >> 5 .. 5
            55
            > tostring(5..'5') == tostring(5..5)
            true
            > 5..5
            error
            > '5'..'5'
            55
            > 5*5
            25
            > '5'*'5'
            25

            Well, the examples above leave some room for thought.


        The thought that I had was, "yup. That seems clear to me."
        Putting all of the possibilities next to each other makes for
        a good exercise though.




            2017-06-19 19:16 GMT-03:00 Coda Highland
            <chighland@gmail.com <mailto:chighland@gmail.com>>:

                On Mon, Jun 19, 2017 at 4:49 PM, Italo Maia
                <italo.maia@gmail.com <mailto:italo.maia@gmail.com>>

                wrote:
                > (1) '5' + 5 gives you an 10.0 in the interactive
                console. Isn't this a
                > weakly typed language behavior?
                > (2) '5' + 5 > 10.0, string plus integer equals
                float. If an error was throw
                > here, it would be easier to understand than the
                given behavior.

                (1) In this case, it's a strongly-typed behavior. It's
                not treating
                strings and numbers as interchangeable; it's an
                explicitly documented
                behavior of the + operator, and there's a separate
                concatenation
                operator that has different semantics (number ..
                number -> string).
                This isn't like PHP where strings that look like
                numbers effectively
                ARE numbers and all sorts of bizarre things can happen
                with them. It's
                more like how C++ tries to find a type conversion to a
                function that
                doesn't directly support the types you used.

                (2) No, string plus number equals number, which can
                compare to another
                number. Lua does not have a distinct integer type; it
                didn't have an
                integer type _at all_ until 5.3 and that's a subtype
                with well-defined
                conversion rules (it coerces to a floating-point
                number very readily).

                /s/ Adam




            --             "A arrogância é a arma dos fracos."

            ===========================
            Me. Italo Moreira Campelo Maia
            Co-fundador do Grupo de Usuários Python do Ceará
            Secretário ForHacker (fb.com/ForHackerSpace
            <http://fb.com/ForHackerSpace>)
            Desenvolvedor Full-Stack, Escritor, Empresário, Visionário
            -----------------------------------------------------
            Meu Livro <http://bit.ly/flask-amazon>, Site
            <http://www.italomaia.com/>, Blog
            <http://eusouolobomau.blogspot.com/>
            ===========================




    --     "A arrogância é a arma dos fracos."

    ===========================
    Me. Italo Moreira Campelo Maia
    Co-fundador do Grupo de Usuários Python do Ceará
    Secretário ForHacker (fb.com/ForHackerSpace
    <http://fb.com/ForHackerSpace>)
    Desenvolvedor Full-Stack, Escritor, Empresário, Visionário
    -----------------------------------------------------
    Meu Livro <http://bit.ly/flask-amazon>, Site
    <http://www.italomaia.com/>, Blog <http://eusouolobomau.blogspot.com/>
    ===========================




--
"A arrogância é a arma dos fracos."

===========================
Me. Italo Moreira Campelo Maia
Co-fundador do Grupo de Usuários Python do Ceará
Secretário ForHacker (fb.com/ForHackerSpace <http://fb.com/ForHackerSpace>)
Desenvolvedor Full-Stack, Escritor, Empresário, Visionário
-----------------------------------------------------
Meu Livro <http://bit.ly/flask-amazon>, Site <http://www.italomaia.com/>, Blog <http://eusouolobomau.blogspot.com/>
===========================

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.





--
"A arrogância é a arma dos fracos."

===========================
Me. Italo Moreira Campelo Maia
Co-fundador do Grupo de Usuários Python do Ceará
Secretário ForHacker (fb.com/ForHackerSpace)
Desenvolvedor Full-Stack, Escritor, Empresário, Visionário
-----------------------------------------------------
Meu Livro, Site, Blog
===========================