4,500
edits
m (→History) |
m (Text replacement - " ⊢( *[^∘])" to " ⎕←$1") |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Built- | {{Built-ins|Unique|∪|↑}}, or '''Nub''', is a [[monadic]] [[set function]] which removes duplicate [[major cells]] from an array. It returns only the distinct cells (those which do not [[match]] an earlier distinct cell) in the order they appeared in the array. | ||
== Examples == | == Examples == | ||
Line 17: | Line 17: | ||
In some languages, such as [[J]] and [[Dyalog APL 17.0]] and later, Unique applies to the [[major cells]] of an array, including those with rank greater than 1: | In some languages, such as [[J]] and [[Dyalog APL 17.0]] and later, Unique applies to the [[major cells]] of an array, including those with rank greater than 1: | ||
<source lang=apl> | <source lang=apl> | ||
⎕←x ← (⍳10)∘.∨2 3 6 | |||
1 1 1 | 1 1 1 | ||
2 1 2 | 2 1 2 | ||
Line 49: | Line 49: | ||
⎕CT←1e¯14 | ⎕CT←1e¯14 | ||
⎕PP←18 ⍝ Print all digits | ⎕PP←18 ⍝ Print all digits | ||
⎕←x←1+⎕CT×0 0.6 1.2 | |||
1 1.000000000000006 1.000000000000012 | 1 1.000000000000006 1.000000000000012 | ||
⍳⍨x ⍝ Each element equal to the previous | ⍳⍨x ⍝ Each element equal to the previous | ||
Line 91: | Line 91: | ||
{{Works in|[[Dyalog APL]]}} | {{Works in|[[Dyalog APL]]}} | ||
While the model <source lang=apl inline>{((⍳≢⍵)=(⍵⍳⍵))⌿⍵}</source>, based on [[Nub Sieve]], is often described as an implementation of Unique, it does not correctly handle [[tolerant comparison]]. A correct implementation of Nub Sieve could be used to implement Unique, but writing such an implementation is no easier than implementing Unique directly. | While the model <source lang=apl inline>{((⍳≢⍵)=(⍵⍳⍵))⌿⍵}</source>, based on [[Nub Sieve]], is often described as an implementation of Unique, it does not correctly handle [[tolerant comparison]].<ref>Hui, Roger. [https://dyalog.tv/Dyalog17/?v=fPWky9IOG40 Tolerant Unique]. [[Dyalog '17]].</ref> A correct implementation of Nub Sieve could be used to implement Unique, but writing such an implementation is no easier than implementing Unique directly. | ||
== Properties == | == Properties == | ||
Line 108: | Line 108: | ||
* [https://www.jsoftware.com/help/dictionary/d221.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/tildedot J NuVoc] (as <source lang=apl inline>~.</source>) | * [https://www.jsoftware.com/help/dictionary/d221.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/tildedot J NuVoc] (as <source lang=apl inline>~.</source>) | ||
{{APL built-ins}} | |||
== References == | |||
<references /> | |||
{{APL built-ins}}[[Category:Primitive functions]][[Category:Set functions]] |