I'd like to access and use unsigned int at the level of Perl. Ideally I would not need to employ XS or inline C. Put simply I'd like to add 1 to 1, without 1 being converted into a signed integer first.

Using Perl 5 I seem to be able to coerce a scalar into storing a UV type, but initial attempts to use it in any form appear to be subject to up/downgrading.

If I use an approach such as bounding a tied scalar as exampled in Intermediate Perl (O'Reilly), I feel this may be suitable for prototyping methodology of usage, but falls short of actually using the underlying unsigned int type.

This quickly boils down to a question about fundamentals, and I am not so concerned about there being any straight forward yes or no answer, (though a yes would be great). As I sense the very nature of Perl 5's dualvar probably does not allow this. But will I find that Perl 6 has the same issue, or would this be something that Perl 6 would happily enable for me?

Maybe there is some way I can do this but where I do need to delve into XS or maybe overloading? I have been hacking at this using the MvT (Monkey vs Typewriter) method a lot and have included my latest effort where I get Devel::Peek to display a UV type.

I have also been doing various MvT with vec,pack,printf functions My overall sense is that any outcome from this could serve as the basis for some very useful Perl/CompSci tutorials.

#!perl use strict; use warnings; use vars q'$n'; use Devel::Peek; #my $n = 4; #&print_val; sub print_val{ # my $n = shift; my $n = shift() || $n; print ' ', Dump $n; print "###\n"; } $n = ~( 1 ); $n <<= 30; #&print_val($n); print "left shift 30\n"; &print_val; $n = ~( 1 ); $n <<= 31; print "left shift 31\n"; &print_val; #=head1 powers #my $n = ~( (2**32) -( (2**32)-1 # -( # (2**30) + ((2**29)-1) # ) ) ); print "base 2 combos\n"; &print_val; #=cut $n+=$n; print "self addition assignment\n"; &print_val; #=cut

I have asked as SoPW, as there may be some simple approach that I am just missing.

updated couple of spelling errors, nothing significant.

In reply to Can I access and use UV types from perl? by Don Coyote

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.