TomDLux has asked for the wisdom of the Perl Monks concerning the following question:
I'm looking at the Perl6 code in rakudo-star, because I have some ideas about junctions, and I want to see how they correspond to what's actually being implemented.
Junction.pir has a lot of stuff, but it's fairly low-level, so it doesn't add up to all that much, just what you expect, new(), boolean comparisons, .perl .... Junction.pm is tiny and contains something interesting ... but challenging to decypher:
method postcircumfix:<( )>($c) { my @result = $.eigenstates.map({ $^code(|$c) }); Junction.new(@result, type => self!type); }
It defines parentheses that go after the junction object, wrapped around an argument that's assigned to the parameter $c, I think. The Junction 1 | 2 | 3 has one attribute $.type which in this case is any, and another attribute $.eigenstates containing the list (1,2,3). So the body of the method is map-ing across the list with the code block { $^code(|$c) }. $^code is an anonymous positional parameter ... the only one in the code block, and it uses the postcircumflex parameter $c as it's argument ... but what is $^code? What is a reasonable value for the $c? I tried:
my $k = $j2 ); my $k = $j( {^c != 2} ); # But both generated the message .. invoke() not implemented in class 'Integer'
My hope is that there is a way to alter a Junction object. In Sudoku, every cell begins with the potential to be any digit: 1|2|3|4|5|6|7|8|9. As cells are initialize to a specific value, all cells in the same row, the same column, and the same region (What's a quadrant when there are nine of them?) no longer have the potential to contain that value.</>
Alternately, the Conway-esque Quantum Superposition interpretation is that the cells ARE all those values at the same time: 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9. As cells are assigned values, the related cells lose the potential to contain that value ... one little Schrodinger's Digit dies, until each cells has a single specific value.
It would be equally useful for other problems which involve building up combinations or narrowing down possibilities: games like Battleships, Fish or Canasta, crossword puzzles, Hangman ... not necessarily the best solution for any of them, I'm saying, but a possibility.
I was hoping that that postcircumflex multi would enable me to do the necessary building up, or breaking of cyanide capsules, but at the moment, I'm confused
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl6 junctions and postcircumflex
by moritz (Cardinal) on Aug 24, 2010 at 08:36 UTC |