Proper way to force char array to type 80?

General APL language issues

Proper way to force char array to type 80?

Postby paulmansour on Fri Sep 10, 2010 2:43 pm

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
paulmansour
 
Posts: 370
Joined: Fri Oct 03, 2008 4:14 pm

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

Postby Phil Last on Fri Sep 10, 2010 3:14 pm

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

Not quicker, in fact it takes nearly twice as long, but it looks nicer.
User avatar
Phil Last
 
Posts: 572
Joined: Thu Jun 18, 2009 6:29 pm

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

Postby Morten|Dyalog on Tue Sep 21, 2010 8:28 am

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
Morten|Dyalog
 
Posts: 406
Joined: Tue Sep 09, 2008 3:52 pm

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

Postby Phil Last on Tue Sep 21, 2010 9:08 am

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.
User avatar
Phil Last
 
Posts: 572
Joined: Thu Jun 18, 2009 6:29 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest