4,577
edits
m (Text replacement - "http://help.dyalog.com" to "https://help.dyalog.com") |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
Line 1: | Line 1: | ||
{{Built-ins|Nest|⊆|⊃}}, also called '''Conditional Enclose''' or '''Enclose If Simple''' (commonly abbreviated as '''eis'''), is a [[monadic]] [[primitive function]] that applies [[Enclose]] to the given [[argument]], but only if it is [[simple]]. Nest first appeared as an extension to [[SHARP APL]]<ref>[https://www.jsoftware.com/papers/satn45.htm "Language Extensions of May 1983"]. SATN-45, 1983-05-02.</ref> using the [[glyph]] <source lang=apl inline>⊃</ | {{Built-ins|Nest|⊆|⊃}}, also called '''Conditional Enclose''' or '''Enclose If Simple''' (commonly abbreviated as '''eis'''), is a [[monadic]] [[primitive function]] that applies [[Enclose]] to the given [[argument]], but only if it is [[simple]]. Nest first appeared as an extension to [[SHARP APL]]<ref>[https://www.jsoftware.com/papers/satn45.htm "Language Extensions of May 1983"]. SATN-45, 1983-05-02.</ref> using the [[glyph]] <source lang=apl inline>⊃</syntaxhighlight>, and was added to [[Dyalog APL]] 16.0 using the glyph <source lang=apl inline>⊆</syntaxhighlight>. | ||
== Examples == | == Examples == | ||
Line 7: | Line 7: | ||
<source lang=apl> | <source lang=apl> | ||
EWords←{+/'E'∊¨⍵} | EWords←{+/'E'∊¨⍵} | ||
</ | </syntaxhighlight>{{Works in|[[Dyalog APL]]}} | ||
If the user gives multiple words in the usual notation, it works correctly: | If the user gives multiple words in the usual notation, it works correctly: | ||
Line 14: | Line 14: | ||
EWords 'I' 'ATE' 'DINNER' 'AND' 'WENT' 'TO' 'SLEEP' ⍝ ATE, DINNER, WENT, SLEEP | EWords 'I' 'ATE' 'DINNER' 'AND' 'WENT' 'TO' 'SLEEP' ⍝ ATE, DINNER, WENT, SLEEP | ||
4 | 4 | ||
</ | </syntaxhighlight>{{Works in|[[Dyalog APL]]}} | ||
But if the user gives only one word, <source lang=apl inline>EWords</ | But if the user gives only one word, <source lang=apl inline>EWords</syntaxhighlight> will count E's in each ''letter'' instead, giving the wrong answer: | ||
<source lang=apl> | <source lang=apl> | ||
EWords 'SLEEP' | EWords 'SLEEP' | ||
2 | 2 | ||
</ | </syntaxhighlight>{{Works in|[[Dyalog APL]]}} | ||
In this case, the programmer can apply Nest to the argument so that the array has a consistent structure. | In this case, the programmer can apply Nest to the argument so that the array has a consistent structure. | ||
Line 31: | Line 31: | ||
EWords2 'SLEEP' | EWords2 'SLEEP' | ||
1 | 1 | ||
</ | </syntaxhighlight>{{Works in|[[Dyalog APL]]}} | ||
== External links == | == External links == |