Remove duplicate elements: Difference between revisions
→{{header|CafeOBJ}}
Line 958:
=={{header|CafeOBJ}}==
The parametrized module NO-DUP-LIST(ELEMENTS :: TRIV) defines the signature of simple
<lang> red (1 2 3 4) (3 2 1 5) .
--> (4 5 1 2 3):Int
Line 969:
<lang CafeOBJ>
mod! NO-DUP-LIST(ELEMENTS :: TRIV) {
op
}
Line 976:
-- Test on lists of INT
open NO-DUP-LIST(INT) .
red 2
-- Gives (2
open NO-DUP-LIST(INT) .
reduce 1
close
open NO-DUP-LIST(CHARACTER) .
reduce 'a'
close
open NO-DUP-LIST(STRING) .
reduce "abc"
close
</lang>
Line 994:
The evaluation automatically uses right associativity. So starting with
<lang> (1
The system places appropriate brackets on the entire expression:
<lang> (1
By idempotency applied at rightmost brackets:
We get rewrite ''(1
<lang> (1
Any further occurrence of 1 will be removed.
By idempotency applied at inner brackets ''(1
We get rewrite ''(1
<lang>(1
By already established idempotency we finally get
<lang>(2
=={{header|Ceylon}}==
|