3 ms·
> In both instances a[2] is a reference to a position in an array. Sure, but the reference invokes function calls (semantically; the compiler usually optimizes
by raiph 13y ago
> In both instances a[2] is a reference to a position in an array.
Sure, but the reference invokes function calls (semantically; the compiler usually optimizes them away) that depend on context: when 'a[2]' is on the left of an '=' the function calls result in assigning the value to the right of the '='; when 'a[2]' is on the right, it results in just reading 'a[2]'. Imo this as an intuitive and appropriate context aware variation in behavior based on whether or not the 'a[2]' is an "lvalue" (value on the left of an assignment), which is the contextual variation in behavior you first called out as problematic and which I'm suggesting is not.
In your latest comment you switched the focus to Perl's distinction of singular vs plural ($ vs @) as seen in the following Perl code:
@people = keys payroll # @ means list context (many)
$count = keys payroll # $ means item context (one)
Given the above code @people would end up with a list (of zero or more items), presumably of objects or somesuch representing people, and $count would end up with a singular value, presumably the number of people.
Aiui you think at least one of those lines ought to be invalid, and there should be multiple functions or constructs to replace 'keys': 'keys' and 'count_of_keys', or 'keys.list' and 'keys.count', or somesuch, rather than Perl's singular/plural polymorphic approach. If so, we disagree.