Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Non-A6/S6 Question: Junctions

10 views
Skip to first unread message

Austin Hastings

unread,
Apr 23, 2003, 4:37:39 PM4/23/03
to perl6-l...@perl.org
If I say:

%hash = ( A => 1, B => 2, C => 3);
$a = all(%hash.keys);
$a = $a & none('A');

Does $a.states now return ('B', 'C') ?

=Austin

Damian Conway

unread,
Apr 23, 2003, 4:59:53 PM4/23/03
to perl6-l...@perl.org
Austin Hastings wrote:

> %hash = ( A => 1, B => 2, C => 3);
> $a = all(%hash.keys);

means: $a = 'A' & 'B' & 'C';

> $a = $a & none('A');

means: $a = 'A' & 'B' & 'C' & none('A')

> Does $a.states now return ('B', 'C') ?

No. C<.states> returns an empty list.

There is no non-junctive value that is simultaneously A and B and C, and
certainly no value that is both A and not A.

However:

$a = any(%hash.keys);
$a &= none('A');

would produce a junction for which C<.states> returns <<B C>>.

Damian

Austin Hastings

unread,
Apr 23, 2003, 5:15:11 PM4/23/03
to Damian Conway, perl6-l...@perl.org

One day I'll figger this stuff out...

:-(

Thanks, Damian.

=Austin

Joseph F. Ryan

unread,
Apr 23, 2003, 5:18:54 PM4/23/03
to perl6-l...@perl.org, Austin_...@yahoo.com
Austin Hastings wrote:

If you're asking how to do set difference, I think the best way would
be to do:

%hash = ( A => 1, B => 2, C => 3);
$a = all(%hash.keys);

$a ^= 'A';

Although I can understand what you are trying to do, I'm not really
sure what that code segment would do.


Joseph F. Ryan
ryan...@osu.edu

Damian Conway

unread,
Apr 23, 2003, 5:34:05 PM4/23/03
to perl6-l...@perl.org
Joseph F. Ryan wrote:
> Austin Hastings wrote:
>
>> If I say:
>>
>> %hash = ( A => 1, B => 2, C => 3);
>> $a = all(%hash.keys);
>> $a = $a & none('A');
>>
>> Does $a.states now return ('B', 'C') ?
>>
>> =Austin
>>
>
> If you're asking how to do set difference, I think the best way would
> be to do:
>
> %hash = ( A => 1, B => 2, C => 3);
> $a = all(%hash.keys);
> $a ^= 'A';

Err. No.

Mathematical sets are inherently disjunctive.
So you need to base them on an C<any>.

That second attempt is equivalent to:

$a = ('A' & 'B' & 'C') ^ 'A'

which has the single C<.state>: 'A'

Damian

Joseph F. Ryan

unread,
Apr 23, 2003, 6:29:02 PM4/23/03
to Damian Conway, perl6-l...@perl.org
Damian Conway wrote:


Ah, you're right. My mnemonic for remembering the junctional operators
threw me off; "& is like AND, | is like OR, ^ is like XOR..." However,
^ isn't really like XOR, its more like a pseduo-grep.

Thanks,

Joseph F. Ryan
ryan...@osu.edu


Marcello Mathias Herreshoff

unread,
May 5, 2003, 7:13:30 PM5/5/03
to
Hi,
I am a mathematitian, and I think that this notation is probably a
little bit out of whack.

You are all switching and and or.

It would be far more intuitive, if the way to create a set were:
('a' | 'b' | 'c')

This would literally mean that this set was a ``superposition'' that
could contain
a OR b OR c.

Think of it this way;
let's say we encode the sets as bit strings:
i.e. 'a' -> b001
'b' -> b010
and c -> b100
(where b means binary)

If we OR these three togeather it is that the result will be
b111 which is precicely what we want.

I am quite aware that it would be completely impractical to actually
implement it this way, however, this is a usefull way to think about
it.

Further more, there would be no controversy over the meanings of & and
<xor operator> as and would select all items in both lists and <xor>
would take
all the items in one and only one list.

In fact, any operator that works on two booleans could have an analog
which works on sets. This would work by running the boolian operator
on the exeistances of the value in either of the two sets.
Sets could be ordinary

We could make a special character a bit like the hyperoperators in
arrays to do this,or we could use some other syntactic trick. It
doesn't really matter how this part is done.

If the character were a ~j sign
(Just for the sake of argument, I am sure there is a better choice)

Examples:

my $j1 = any(%hash.keys);
#to remove the value 'a':
$j1 ~j||= ~j!any('a');
#or
$j1 ~j||= none('a');

#to check whether 'a' exists:
print "yes" if $j1 ~j&& any('a');

-=+Marcello

0 new messages