I should have made clearer what I meant with "run time checking or code optimization..."

"run time checking"

If I'm indexing with $i into an array, its clear that $i should never be a string or a ref.

So flagging the type with  my int $i; could help checking at runtime (or compile-time) if ever something else than an integer was assigned to $i and consequently raising an error. (maybe using a "static" bit)²

"code optimization"

you mentioned JIT-compiler, the old Panther mentions a C-converter (most likely B::CC) to take advantage of it.

To avoid further misunderstandings I'm thinking about little snippets, embedded for time-critical loops, but much easier and intuitive than with XS.

The python community uses cython for this purpose facilitating to embed C-code.

my motivation

I'm writing a little hack emitting elisp snippets out of Perl-Code by translating the optree.

(mainly because I hate writing lisp syntax)

Actually I have to take care for implicit type conversions:

--- example
something like "abc".$i can't simply be translated to (concat "abc" i) because I get a Wrong type argument if $i is a integer.

Sure, this can easily be solved by defining an "perl operator like" function pl-concat which does the needed type conversion. This slows down execution but normally thats not too important in emacs. But if I could give the compiler a static hint that $i is an integer, I could make pl-concat a macro which generates the appropriate code at compile time.

Unfortunately I can't read out of the opcodes if $i was explicitly declared as of TYPE integer¹, I have to realize workarounds (e.g naming conventions like $i_INT) to transport this information.

future ???

I could read out of the old panther that this kind of usage was intended and it seems natural. Furthermore the docs read like the old usage of fields is deprecated now.

So what are the plans/use cases for TYPE?

Or is it completely deprecated now?

Cheers Rolf

UPDATES:

¹) Example:

perl -MO=Concise -e '{package int}; my int $y' 8 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 2 -e:1) v:{ ->3 5 <2> leaveloop vK/2 ->6 3 <{> enterloop(next->5 last->5 redo->4) v ->4 4 <0> stub v ->5 6 <;> nextstate(main 2 -e:1) v:{ ->7 7 <0> padsv[$y:2,3] vM/LVINTRO ->8
line 7 doesn't change if write my $y instead.

²) Of course this could be achieved using tie, but much slower and with more verbose code.


In reply to Re^2: my TYPE EXPR ? by LanX
in thread my TYPE EXPR ? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.