Hi Lutz,
Perhpas you have a hint?
Is there way to create a somekind of "intelligent" addon for difference and intersect?
Currently these functions always handle from List-A to List-B but the function is
not smart enough the detect if List-A is i.e. bigger then List-B or even that List-A
has more symbols then List-B and thus should compare to List-B instead of List-A.
Secondly, Is there a way/function to automaticly select between 'intersect and 'difference.
Sometimes comparing lists 'difference should be used and sometimes 'intersect.
But this depends on the structure of the lists and is not easy to build a function around,
This is also linked to the problem above.
Regards, Norman.
difference and intersect
difference and intersect
-- (define? (Cornflakes))
This could lead to ambigous situations:
... it would only work for lists A and B
... in that case you could do:
Lutz
Code: Select all
> (set 'A '(a b c d e f g) 'B '(c d e) 'C '(a b c e f g h))
(a b c e f g h)
> (difference C A)
(h)
> (difference A C)
(d)
>
Code: Select all
> (difference A B)
(a b f g)
> (difference B A)
()
>
Code: Select all
> (or (difference A B) (difference B A))
(a b f g)
It seems to be quite clear from the manual that 'difference' and 'intersect' conform to their usual set theoretic definitions (notions). Note also that 'difference' is not a commutative operation, but 'intersect' is.
As an aside, with 'difference', we can define the subset relation as the empty difference relation (with the help of our composer, discussed in another thread).
Better yet, why not fold the empty difference over (possibly) more than 2 sets?
('foldr' is a right associative reducer, 'curry' is the partial call functor, and 'empty-set' should be '() in our case.)
Then you can see if A ⊆ B ⊆ C by saying
I haven't tested it, but you get my drift.
And the superset relation is the inverse of the subset.
Does anyone already have a set library? Curious, --Rick
As an aside, with 'difference', we can define the subset relation as the empty difference relation (with the help of our composer, discussed in another thread).
Code: Select all
(define subset? (compose empty? difference))
Code: Select all
(define subset? (curry foldr (compose empty? difference) empty-set))
Then you can see if A ⊆ B ⊆ C by saying
Code: Select all
(subset? A B C)
And the superset relation is the inverse of the subset.
Code: Select all
(define (superset?) (apply subset? (reverse (args))))
(λx. x x) (λx. x x)