Type: Difference between revisions
Jump to navigation
Jump to search
m (Text replacement - "<source" to "<syntaxhighlight") |
(Uses and additional types) |
||
Line 22: | Line 22: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>=</nowiki>1}} | {{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>=</nowiki>1}} | ||
=== Additional types === | |||
Dyalog APL has additional data types, besides for the traditional numeric, character, and nested ones. [[Null]]s and [[Object Representation]]s are their own type, while instances of objects with [[niladic]] constructor (or no constructors) cause the creation of new instances of the same class. Other objects, namely [[namespace]]s and classes with constructors but no niladic constructor, cause a [[NONCE ERROR]]. | |||
== Examples == | |||
Type can be used to construct universal utilities that adapt to the type of data given as argument. For example: | |||
<syntaxhighlight lang=apl> | |||
Null ← ≡∘∊⍨ ⍝ Indicate empty or all blank and/or zero | |||
Nil ← ∊∘∊⍨ ⍝ Indicates null items | |||
Clean ← ~∘∊⍨ ⍝ Without null items | |||
Split ← (⊢⊆⍨∊≢¨⊢) ⍝ Split on null items | |||
data ← 'Hello' ' ' 'World' ⎕NULL (2 7 1 8) (3 1 4 1 5) (0 0 0) (0 0 7) | |||
Null 2⊃data | |||
1 | |||
Null 3⊃data | |||
0 | |||
Nil data | |||
0 1 0 1 0 0 1 0 | |||
Clean data | |||
┌─────┬─────┬───────┬─────────┬─────┐ | |||
│Hello│World│2 7 1 8│3 1 4 1 5│0 0 7│ | |||
└─────┴─────┴───────┴─────────┴─────┘ | |||
Split data | |||
┌───────┬───────┬───────────────────┬───────┐ | |||
│┌─────┐│┌─────┐│┌───────┬─────────┐│┌─────┐│ | |||
││Hello│││World│││2 7 1 8│3 1 4 1 5│││0 0 7││ | |||
│└─────┘│└─────┘│└───────┴─────────┘│└─────┘│ | |||
└───────┴───────┴───────────────────┴───────┘ | |||
</syntaxhighlight> | |||
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>=</nowiki>0}} | |||
== External links == | == External links == |