Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-20 00:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found