Rod Adams wrote:
Thomas Sandlaß wrote:
I'm not the junction expert, but it's said that they wrap around
indexing/slicing! So the @array[!-2] would just read @array[none(-2)]?
But how does none() get the base set where the second to last is excluded
from?

It does no such thing. It creates a new none() junction over what was stored at index -2. It's when you evaluate the new junction that the none comes into effect.

Interesting, how does that differ from none(@array[-2])?


And once again, I feel the need to remind people that junctions and sets are two different things.

I know. I've dubbed junction as "oracle value". But that somewhat restricts them to advanced control flow as a generalized form of boolean conditionals.


If I get to do what I'd like to to junctions, the above would actually be illegal. But for that I have to wait for Damian to get back.

Could we nonetheless start discussing our (mis)understandings? I for my part have a big difficulty on forming a coherent model of typing and dispatch on one side and the autothreading of junctions on the other side. In particular why the compiler has to produce code that branches into completely different implementations for junctions and non-junctions before the dispatcher sees the types. Only when junctions are syntactically visible this code overlaying can be optimized away. Consider the S09 example substr("camel", 0|1, 2&3) with variables of unknown content instead of literals: substr("camel", $a, $b). This would need to be compiled to something like:

if $a.does(Junction)
{
   if $b.does(Junction)
   {
      autothread over $a and $b
   }
   else
   {
      autothread over $a
   }
}
elsif $b.does(Junction)
{
    autothread over $b
}
else
{
    dispatch normally
}


This buries the type Junction deep inside the compiler, while types like Array, Scalar or Ref have to go through the dispatcher. BTW, I neither like it that this applies to the boolean type, too. But there it's just the usual embedding into the int type---not code morphing in the large as in the pseudocode above.


Coming back to the original subject of the thread, I think it could be achieved by implementing &postcircumfix:<[ ]>:(Array,Exclusion:) and a function or operator &exclude:(List returns Exclusion) that does nothing but re-typing its slice input. E.g. @array[ exclude 1, 2, 3 ] is dispatched to a multi method that knows the array and the fact that everything except the incoming slice shall be returned.

Regards,
--
TSa (Thomas Sandlaß)



Reply via email to