Unique: Difference between revisions

Jump to navigation Jump to search
54 bytes added ,  09:07, 29 October 2019
m
Text replacement - "<code>" to "<source lang=apl inline>"
Miraheze>Marshall
Miraheze>Adám Brudzewsky
m (Text replacement - "<code>" to "<source lang=apl inline>")
Line 64: Line 64:
== APL model ==
== APL model ==


For [[Vector|vectors]] the following implementation based on [[Union]] can be used. It repeatedly adds cells of the argument to an accumulated unique vector <code>u</code>, using Union so that duplicate cells are never added.
For [[Vector|vectors]] the following implementation based on [[Union]] can be used. It repeatedly adds cells of the argument to an accumulated unique vector <source lang=apl inline>u</code>, using Union so that duplicate cells are never added.
<source lang=apl>
<source lang=apl>
VecUnique ← {
VecUnique ← {
Line 83: Line 83:
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}


While the model <code>{((⍳≢⍵)=(⍵⍳⍵))⌿⍵}</code>, 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>{((⍳≢⍵)=(⍵⍳⍵))⌿⍵}</code>, 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.


== Properties ==
== Properties ==
Line 99: Line 99:
* [http://microapl.com/apl_help/ch_020_020_392.htm APLX]
* [http://microapl.com/apl_help/ch_020_020_392.htm APLX]


* [https://www.jsoftware.com/help/dictionary/d221.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/tildedot J NuVoc] (as <code>~.</code>)
* [https://www.jsoftware.com/help/dictionary/d221.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/tildedot J NuVoc] (as <source lang=apl inline>~.</code>)
{{APL built-ins}}
{{APL built-ins}}

Navigation menu