FORMAT difference between APL2/APLX and Dyalog
5 posts
• Page 1 of 1
FORMAT difference between APL2/APLX and Dyalog
I am in the process of converting my APLX workspaces to Dyalog 16.
With ML cranked to 3 it's actually going pretty well (and Dyalog certainly as some nifty stuff) but I hit one issue with dyadic ⍕ (format):
Assume a vector mixed vector of integers and characters:
A←1 2 '⍵'
Using dyadic format on APLX:
1 0⍕A
12⍵
While in Dyalog I get a domain error. According to the Dyalog language spec, ⍕ is strict and requires a numeric only argument.
"APL2 In Depth" is silent about the mixed case A that works in APLX.
What's the portable way to handle this simple formatting case?
With ML cranked to 3 it's actually going pretty well (and Dyalog certainly as some nifty stuff) but I hit one issue with dyadic ⍕ (format):
Assume a vector mixed vector of integers and characters:
A←1 2 '⍵'
Using dyadic format on APLX:
1 0⍕A
12⍵
While in Dyalog I get a domain error. According to the Dyalog language spec, ⍕ is strict and requires a numeric only argument.
"APL2 In Depth" is silent about the mixed case A that works in APLX.
What's the portable way to handle this simple formatting case?
- mhpcto
- Posts: 18
- Joined: Tue Sep 18, 2018 5:36 pm
Re: FORMAT difference between APL2/APLX and Dyalog
First: welcome! A person who uses []ML 3 must be a nice one ;)
You are right, number formatting is somewhat different in Dyalog than in APL2 (or APLX). The handy Picture formatting is not supported. But you should have a look, a deep look, at the dyadic []FMT, which is pretty nice tool for almost any formatting purposes. There are some caveats, though!
For example:
The right argument has to be matrix. Instead of repeating all identifiers, you can use multipliers:
..but after all these years I cannot understand why this mixed formatting is not possible:
-Veli-Matti
You are right, number formatting is somewhat different in Dyalog than in APL2 (or APLX). The handy Picture formatting is not supported. But you should have a look, a deep look, at the dyadic []FMT, which is pretty nice tool for almost any formatting purposes. There are some caveats, though!
For example:
a←1 2 '⍵'
'I2,I2,A2'⎕FMT a
DOMAIN ERROR
The right argument has to be matrix. Instead of repeating all identifiers, you can use multipliers:
'2I2,A2'⎕FMT ⍉⍪a
1 2 ⍵
..but after all these years I cannot understand why this mixed formatting is not possible:
a←1.1 2 '⍵'
'F5.2,I2,A2'⎕FMT ⍉⍪a
DOMAIN ERROR
-Veli-Matti
- Veli-Matti
- Posts: 93
- Joined: Sat Nov 28, 2009 3:12 pm
Re: FORMAT difference between APL2/APLX and Dyalog
I notice that NARS2000 also allows this. I'll log it as a request-for-enhancement (RFE) for Dyalog.
In the meantime, you could try:
John
In the meantime, you could try:
nfmt ← ⍕@(2|⎕dr¨) ⍝ format-at-numbersor, more generally,
1 0 nfmt 1 2'⍵'
12⍵
nums ← @(2|⎕dr¨) ⍝ at-numbers
1 0 ⍕nums 1 2'⍵'
12⍵
10 ×nums 1 2'⍵'
10 20 ⍵
John
- JohnS|Dyalog
Re: FORMAT difference between APL2/APLX and Dyalog
I should probably clarify the problem space a bit.
The vectors being formatted are a combination of numeric and single character elements (actually the rows of a matrix). So the input may look like this:
1 0 0
0 1 ⍵
1 ⍵ 0
1 1 1
0 0 1
1 0⍕ is used to character vector from each row '110' '01⍵' '1⍵0' ...
I think ⎕FMT has the same issue with mixed type arguments not allowed.
The vectors being formatted are a combination of numeric and single character elements (actually the rows of a matrix). So the input may look like this:
1 0 0
0 1 ⍵
1 ⍵ 0
1 1 1
0 0 1
1 0⍕ is used to character vector from each row '110' '01⍵' '1⍵0' ...
I think ⎕FMT has the same issue with mixed type arguments not allowed.
- mhpcto
- Posts: 18
- Joined: Tue Sep 18, 2018 5:36 pm
Re: FORMAT difference between APL2/APLX and Dyalog
JohnS|Dyalog wrote:I notice that NARS2000 also allows this. I'll log it as a request-for-enhancement (RFE) for Dyalog.
In the meantime, you could try:nfmt ← ⍕@(2|⎕dr¨) ⍝ format-at-numbersor, more generally,
1 0 nfmt 1 2'⍵'
12⍵nums ← @(2|⎕dr¨) ⍝ at-numbers
1 0 ⍕nums 1 2'⍵'
12⍵
10 ×nums 1 2'⍵'
10 20 ⍵
John
That is a cool workaround. I am pretty much a straight APL2 guy but Dyalog sure has some interesting enhancements.
- mhpcto
- Posts: 18
- Joined: Tue Sep 18, 2018 5:36 pm
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group