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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |