#1445: Add ResizableStringArray.get_number VTABLE function
-----------------------------+----------------------------------------------
Reporter: Austin_Hastings | Owner:
Type: todo | Status: new
Priority: normal | Milestone:
Component: none | Version: 2.0.0
Severity: medium | Keywords: rsa, ResizableStringArray,
get_number, NQP
Lang: | Patch:
Platform: |
-----------------------------+----------------------------------------------
Comment(by whiteknight):
Replying to [comment:6 pmichaud]:
> Turning this thread around a bit -- while it might seem nonsensical for
a caller to ask an Array for a floating point value, I suppose one could
argue that it's equally nonsensical for an Array to refuse to provide a
floating point value if asked, given that it's perfectly willing to
provide an integer value (and integers are subsets of floats).
Point noted, and in the spirit of musing I would turn this around on you
again and ask why treating an array as an integer value should return the
element count of that array? This is very much a perlism, when many other
languages would require you to call length($P0), or $P0.count, or
$P0.length, or some variation thereof. The fact that we can say "$I0 =
$P0" to get the length of the array really does require a cognitive leap
and a familiarity with Perl5's notions of arrays in a scalar context.
If getting the integer form of an array is really code for "get the number
of elements" (which, I think, is especially unnecessary in light of the
"elements" opcode and VTABLE), it really is a bit of an extra stretch to
suggest that calling get_number should only be able to return a floating-
point representation of what get_integer returns (which, again, is just a
convenience copy of VTABLE_elements). Maybe I suggest that get_number
should return a value for the array which is more suited for representing
as a floating point: Maybe memory utilization percentage, some sort of
compression metric, memory fragmentation percentage? In the case of sparse
arrays, VTABLE_get_number could easily return a some kind of utilization
percentage.
If we look at everything through perl-colored glasses we can say that it
only makes good sense that Parrot's array types behave in various contexts
the same was as Perl's arrays do. If we look at a language like Octave,
asking for an integer from an array (a vector) is actually intended to
return an array where all the elements of the input array are converted to
integers, recursively. Array types there are multi-dimensional, so Octave
needs concepts of "length" and "width", in addition to a total count of
"elements". So obviously we wouldn't use Parrot's VTABLE_get_integer for
that behavior, but it does go to show that other languages have very
different notion of how an array type should respond to a "get an integer"
or "get a number" request.
--
Ticket URL: <https://trac.parrot.org/parrot/ticket/1445#comment:7>
Parrot <https://trac.parrot.org/parrot/>
Parrot Development
_______________________________________________
parrot-tickets mailing list
[email protected]
http://lists.parrot.org/mailman/listinfo/parrot-tickets