My understanding of the semantic of pairs as in A6:
   A pair in a given scalar context should return its first element
   coerced to match the said context.

This seems to be a prerequisite to use pairs as function arguments.

Example with the boolean context:

   bool $b =  a => 10;  #  $b == 1

But what about C<Scalar>, C<Ref> and C<string> contexts?

I expect an object to return a reference to itself in Ref Context.
I have trouble to remember if assignation in Scalar context gives
a reference to the assigned object, or its size.
I expect that assigning a to string gets me a string that can
usually get evaluated to return a value equal to the the original
one.

In the three cases where I assume to have described the nornal
semantic, I don't get a behavior compatible with my
understanding of pairs used as arguments.

To solve that dilemma, can we just say that pairs used as arguments is
a special case.

Now let's talk about the implementation of perl pairs and lisp
pairs as a PMC, assuming pairs as arguments is a special case.

We need both the normal pair semantic and the one about arguments
as pairs. This mean that the argument as pair is implemented as
keyed PMC methods. I propose special methods to avoid that
overhead. They are the moral equivalent of the lisp car and cdr
in a language with context.

These methods would be:

  (get|set)_first_(integer|number|bool|pmc)
  (get|set)_second_(integer|number|bool|pmc)

Note that they can be used as optimization for array pmcs,

Now I run in a second problem that I have already touched on
perl6-internal. For storage optimization purposes, I want to
avoid as possible to use pmcs for pairs elements.

Say I set the key is an int (they can be in Perl6?), I want to avoid
to promote it to a PMC. But I must do it if one takes a reference
to that key. This happens if someone does a get_first_pmc()
or a get_second_pmc(). But sometimes one would just access a
pmc to clone it. This does not mean that a reference is really
taken and that there is no need to promote the element to a pmc.

So we need a clone_first() and a clone_second() to avoid
unecessary element promotion.

More generally, in pmcs that act as composite containers which
elements are not necessarily pmc, we need these cloning methods as well:

  PMC* clone_pmc_keyed(PMC* key)
  PMC* clone_pmc_keyed_int(INTVAL key)
  PMC* clone_pmc_keyed_str(STRING* key)

Comments?

--
 stef

Reply via email to