Lev and Dex
11 posts
• Page 1 of 2 • 1, 2
Lev and Dex
There has been some debate in the Yahoo group about the proposed implementation of Lev ⊣ and Dex ⊢.
Dex is, I think, uncontentious: it will be a marginally quicker and shorter alias of {⍵}, which ignores its left argument (if there is one) and returns its right argument as an explicit result.
Lev is also straightforward as long as a left argument is present: it is an alias of {⍺}, which ignores its right argument and returns its left argument.
However, what should Lev do if called monadically (without a left argument)?
A number of suggestions have been proposed:
If we take each of these definitions for a (monadic) spin, this is what we find:
Any thoughts?
Dex is, I think, uncontentious: it will be a marginally quicker and shorter alias of {⍵}, which ignores its left argument (if there is one) and returns its right argument as an explicit result.
Lev is also straightforward as long as a left argument is present: it is an alias of {⍺}, which ignores its right argument and returns its left argument.
However, what should Lev do if called monadically (without a left argument)?
A number of suggestions have been proposed:
- Code: Select all
levJ ← {×⎕nc'⍺':⍺ ⋄ ⍵ } ⍝ return ⍵. Same as J's "[".
lev0 ← {×⎕nc'⍺':⍺ ⋄ 0 0⍴0 } ⍝ return non-displaying null.
lev2 ← {×⎕nc'⍺':⍺ ⋄ ⎕signal 2} ⍝ signal SYNTAX ERROR
lev_ ← {×⎕nc'⍺':⍺ } ⍝ return "void" (don't return a result).
lev6 ← {×⎕nc'⍺':⍺ ⋄ ⎕signal 6} ⍝ signal VALUE ERROR (same as {⍺}).
If we take each of these definitions for a (monadic) spin, this is what we find:
- Code: Select all
levJ 456 ⍝ return right arg
456
10 × levJ 456 ⍝ 10 × right arg
4560
- Code: Select all
lev0 456 ⍝ return null matrix
10 × lev0 456 ⍝ 10 × null matrix
- Code: Select all
lev2 456 ⍝ no left arg for dyadic fn (cf: =⍵)
SYNTAX ERROR
10 × lev2 456 ⍝ ditto
SYNTAX ERROR
- Code: Select all
lev_ 456 ⍝ calling context doesn't require result: OK.
10×lev_ 456 ⍝ calling context requires missing result.
VALUE ERROR
- Code: Select all
lev6 456 ⍝ no left arg
VALUE ERROR
10×lev6 456 ⍝ ditto
VALUE ERROR
Any thoughts?
- JohnS|Dyalog
Re: Lev and Dex
my preference: do not implement the LEV primitive.
In case that we need to use it, we can write
that is both monadic and diadic
Probably my opinion has a minor share and LEV shall have an implementation: please let it be a scalar (monadic and diadic) function
In case that we need to use it, we can write
- Code: Select all
⊢⍨
that is both monadic and diadic
Probably my opinion has a minor share and LEV shall have an implementation: please let it be a scalar (monadic and diadic) function
-
giangiquario - Posts: 46
- Joined: Thu Nov 26, 2009 8:55 am
- Location: Milano, Italia
Re: Lev and Dex
I don't know if this is quite what Gianluigi means but I've always harboured a wish that lev and dex were scalar functions rather than, as Ken defined them, having infinite rank. The repercussions would be interesting at least:
Of course as Dan said in dyalogusers, with the rank operator we can do this (more or less) anyway.
- Code: Select all
1 ⊣ 2
1
1 ⊣ 2 3
1 1
DISPLAY 1 7 9 ⊣ ⊂2 1⍴'Hello' 'world
┌→────────────────────────────────────────────────┐
│ ┌→────────────┐ ┌→────────────┐ ┌→────────────┐ │
│ ↓ ┌→──────┐ │ ↓ ┌→──────┐ │ ↓ ┌→──────┐ │ │
│ │ │1 1 1 1│ │ │ │7 7 7 7│ │ │ │9 9 9 9│ │ │
│ │ └~──────┘ │ │ └~──────┘ │ │ └~──────┘ │ │
│ │ ┌→────────┐ │ │ ┌→────────┐ │ │ ┌→────────┐ │ │
│ │ │1 1 1 1 1│ │ │ │7 7 7 7 7│ │ │ │9 9 9 9 9│ │ │
│ │ └~────────┘ │ │ └~────────┘ │ │ └~────────┘ │ │
│ └∊────────────┘ └∊────────────┘ └∊────────────┘ │
└∊────────────────────────────────────────────────┘
Of course as Dan said in dyalogusers, with the rank operator we can do this (more or less) anyway.
-
Phil Last - Posts: 557
- Joined: Thu Jun 18, 2009 6:29 pm
Re: Lev and Dex
FYI: I think that Gianluigi's proposal:
gives us the same functionality as levJ from above.
- Code: Select all
lev ← ⊢⍨
gives us the same functionality as levJ from above.
- JohnS|Dyalog
Re: Lev and Dex
Yes. This is the equivalent I use {⍵}⍨ to allow function/array ambivalence in operators.
-
Phil Last - Posts: 557
- Joined: Thu Jun 18, 2009 6:29 pm
Re: Lev and Dex
... and Giangi's scalar lev idea, if I understand it, would make:
a nippy alternative to
for simple ⍵.
- Code: Select all
0⊣⍵
a nippy alternative to
- Code: Select all
(⍴⍵)⍴0
for simple ⍵.
- JohnS|Dyalog
Re: Lev and Dex
My view (as of today - it may change in the future)...
[0] Please call the dyadic cases "Left" and "Right".
[1] My Iverson APL Reference manual (page 5-44) offers an interesting alternative verbalisation for "Left", as in
n*2 ⊣ n←3 ("n to the power 2 where n is 3")
[2] I don't see any real utility in the monadic(s), but if they were defined I'd prefer the J definition (and naming - call it/them "Same")
[0] Please call the dyadic cases "Left" and "Right".
[1] My Iverson APL Reference manual (page 5-44) offers an interesting alternative verbalisation for "Left", as in
n*2 ⊣ n←3 ("n to the power 2 where n is 3")
[2] I don't see any real utility in the monadic(s), but if they were defined I'd prefer the J definition (and naming - call it/them "Same")
Visit http://apl.dickbowman.com to read more from Dick Bowman
-
Dick Bowman - Posts: 235
- Joined: Thu Jun 18, 2009 4:55 pm
Re: Lev and Dex
Careful not to confuse rank with pervasiveness. With rank only the example
would be
1 7 9
regardless of rank setting (0 or infinite)
My vote for default rank would be infinite. Otherwise you would have to set 'rank 99' (there is no infinite in Dyalog) everytime you want to discard the right arg, e.g.
/D
- Code: Select all
DISPLAY 1 7 9 ⊣ ⊂2 1⍴'Hello' 'world'
would be
1 7 9
regardless of rank setting (0 or infinite)
My vote for default rank would be infinite. Otherwise you would have to set 'rank 99' (there is no infinite in Dyalog) everytime you want to discard the right arg, e.g.
- Code: Select all
year←2009 ⊣ name←'danb'
/D
Phil Last wrote:I don't know if this is quite what Gianluigi means but I've always harboured a wish that lev and dex were scalar functions rather than, as Ken defined them, having infinite rank. The repercussions would be interesting at least:
- Code: Select all
1 ⊣ 2
1
1 ⊣ 2 3
1 1
DISPLAY 1 7 9 ⊣ ⊂2 1⍴'Hello' 'world
┌→────────────────────────────────────────────────┐
│ ┌→────────────┐ ┌→────────────┐ ┌→────────────┐ │
│ ↓ ┌→──────┐ │ ↓ ┌→──────┐ │ ↓ ┌→──────┐ │ │
│ │ │1 1 1 1│ │ │ │7 7 7 7│ │ │ │9 9 9 9│ │ │
│ │ └~──────┘ │ │ └~──────┘ │ │ └~──────┘ │ │
│ │ ┌→────────┐ │ │ ┌→────────┐ │ │ ┌→────────┐ │ │
│ │ │1 1 1 1 1│ │ │ │7 7 7 7 7│ │ │ │9 9 9 9 9│ │ │
│ │ └~────────┘ │ │ └~────────┘ │ │ └~────────┘ │ │
│ └∊────────────┘ └∊────────────┘ └∊────────────┘ │
└∊────────────────────────────────────────────────┘
Of course as Dan said in dyalogusers, with the rank operator we can do this (more or less) anyway.
- DanB|Dyalog
Re: Lev and Dex
My proposal is:
DEX primitive must be pervasive (scalar function, i.e. rank 0 function). In this way we have a new usefull dyadic function which maintains a kind of link between left and right argument.
If we want a dull "DISCARD" function (rank 99 function), we can continue to use {⍵} or {⍵}⍨
DEX primitive must be pervasive (scalar function, i.e. rank 0 function). In this way we have a new usefull dyadic function which maintains a kind of link between left and right argument.
If we want a dull "DISCARD" function (rank 99 function), we can continue to use {⍵} or {⍵}⍨
-
giangiquario - Posts: 46
- Joined: Thu Nov 26, 2009 8:55 am
- Location: Milano, Italia
Re: Lev and Dex
DanB|Dyalog wrote:Careful not to confuse rank with pervasiveness. With rank only the example
. . . DISPLAY 1 7 9 ⊣ ⊂2 1⍴'Hello' 'world'
would be
1 7 9
regardless of rank setting (0 or infinite)
I knew someone would notice. The concept of scalar function everywhere but in Sharp APL and J automatically goes hand-in-hand with pervasiveness as we have only the numeric scalar functions as examples. So when I mentioned infinite rank I was careful to contrast it with "scalar" rather than "rank zero".
Interesting to note that scalar (pervasive) "right" and "left" are easy to emulate for numbers:
. . . right←{⍵+⍺≠⍺} ⋄ left←{⍺+⍵≠⍵}
or
. . . right←+∘(≠⍨)⍨ ⋄ left←+∘(≠⍨)⍨⍨
but not so for other domains.
We can use these with any domain for the "other" argument, as = and ≠ are applicable to any domain, but not for the argument to be returned.
-
Phil Last - Posts: 557
- Joined: Thu Jun 18, 2009 6:29 pm
11 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group