in reply to Re^5: Reason for this discrepancy with scalar?
in thread Reason for this discrepancy with scalar?

Anyway does Perl really set the IV slot in your example?
No, perl regards it as a pure string at that point.

It's just an example of what perl regards as an initial type and what we think of as a "useful" initial type not always coinciding. So I'm sceptical that putting in effort to make perl record the initial type is going to help serialisation as much as people expect.

Dave.

  • Comment on Re^6: Reason for this discrepancy with scalar?

Replies are listed 'Best First'.
Re^7: Reason for this discrepancy with scalar?
by LanX (Saint) on Mar 16, 2024 at 17:03 UTC
    > So I'm sceptical that putting in effort to make perl record the initial type

    Well - as I just remembered - at least we don't need a new flag, but a type attribute.

    my TYPE VARLIST

    This obscure feature of my was already there since the very beginning of Perl 5

    > is going to help serialisation as much as people expect.

    I think not only serialization could profit here.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      But lexical types largely don't do what people expect; in particular, they don't stop something which isn't an Int or whatever from being assigned to the lex var; nor do they coerce the assigned value to that type.

      In general, adding types to perl is a big topic which tends to trigger the occasional heated discussion on p5p and elsewhere.

      Dave.

        Yes I remember digging into it and the fields Pragma.

        And ....

        # this will generate a compile-time error my Foo $foo = Foo->new;

        I could see a use case in extending this already existing syntax for other purposes, like

        • allowing to translate a subset of Perl to inline C
        • helping IDEs to intellisense method expansions
        • defining an initial type (e.g. for serializers ; sic)

        But probably I'm naive.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery