Proper way to force char array to type 80?

General APL language issues
Post Reply
paulmansour
Posts: 431
Joined: Fri Oct 03, 2008 4:14 pm

Proper way to force char array to type 80?

Post by paulmansour »

Hi,

In the Unicode version, I have a character array (a simple matrix). I want to force it to type 80, no matter what type is in it. I have this so far:

Code: Select all

     {
       80=⎕DR ⍵:⍵
       r←⍵
       b←,255≤⎕UCS r
       (b/,r)←'?'
       r[⍳↑⍴r;]
      }

Is there a better way to do this? to force compaction?

Thanks
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Proper way to force char array to type 80?

Post by Phil Last »

      {⎕UCS⊃63 ⍵+.×1 0=⊂256≤⍵}∘⎕UCS

Not quicker, in fact it takes nearly twice as long, but it looks nicer.
User avatar
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: Proper way to force char array to type 80?

Post by Morten|Dyalog »

This is slightly faster... And "nicer" according to my taste:

{⎕IO←0 ⋄ ((⎕UCS⍳256),'?')[256⌊⎕UCS ⍵]}

I think there is a bug in your function; it folds UCS 255 (ÿ) to ? if the argument has type 160, but not if the type is already 80.
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Proper way to force char array to type 80?

Post by Phil Last »

Morten|Dyalog wrote:I think there is a bug in your function; it folds UCS 255 (ÿ) to ? if the argument has type 160, but not if the type is already 80.


Yes it's

      b←,255≤⎕UCS r

that should be 256. ' wasn't going to mention it.
Post Reply