FORMAT difference between APL2/APLX and Dyalog

General APL language issues

FORMAT difference between APL2/APLX and Dyalog

Postby mhpcto on Thu Sep 20, 2018 1:02 am

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?
mhpcto
 
Posts: 3
Joined: Tue Sep 18, 2018 5:36 pm

Re: FORMAT difference between APL2/APLX and Dyalog

Postby Veli-Matti on Thu Sep 20, 2018 6:00 am

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:
      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: 44
Joined: Sat Nov 28, 2009 3:12 pm

Re: FORMAT difference between APL2/APLX and Dyalog

Postby JohnS|Dyalog on Thu Sep 20, 2018 6:30 am

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-numbers

1 0 nfmt 1 2'⍵'
12⍵
or, more generally,
      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

Postby mhpcto on Thu Sep 20, 2018 5:38 pm

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.
mhpcto
 
Posts: 3
Joined: Tue Sep 18, 2018 5:36 pm

Re: FORMAT difference between APL2/APLX and Dyalog

Postby mhpcto on Thu Sep 20, 2018 5:51 pm

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-numbers

1 0 nfmt 1 2'⍵'
12⍵
or, more generally,
      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: 3
Joined: Tue Sep 18, 2018 5:36 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest