Change array inside DFNS

General APL language issues

Change array inside DFNS

Postby Yves on Wed Jun 20, 2018 8:15 am

Dear All,
i need to verify char in text file.
Actually, i follow this way :
      content ← ⎕nget filename
tab ← { (⎕ucs ⍺) , ⍺ , ⍴⍵ } ⌸ (⊃ content)

but if LF, FF or RL character is inside, a simple display is alterate
      ┌→────────┐
↓ 10 │
│ 12 │
│ 38 & 47│
│ 35 # 47│
│ 50 2 59│
│ 51 3 59│
...

i replace them by a blank space.
      tab[ ⍸ (⎕ucs 10) = tab ] ← ' '

i play with more array, and i need to clarify code.
i would like to convert in dynamic function.
i try
      changeLF ← { ⍵[ ( ⍸ (⎕ucs 10) = ⍵ ) ] ← ' ' }
changeLF tab

and i receive a syntax error.
Where i am wrong ?

Not only, i try to sort array in the same way
      sortbyQty ← { ⍵[ ⍋⍵[;3] ; ] }
sortbyQty tab
and it works.

Explanations are welcome !

have a good day
Yves
Yves
 
Posts: 39
Joined: Mon Nov 30, 2015 11:33 am

Re: Change array inside DFNS

Postby AndyS|Dyalog on Wed Jun 20, 2018 10:34 am

Hi Yves

In changeLF you are attempting to assign to ⍵ (or more precisely, attempting to apply selective assignment to ⍵). That is not supported in Dyalog APL.
Assigning to ⍺ has special meaning; it allows you to specify a default left argument to a dfn.

In SortByQty you are not attempting to assign to ⍵, so that will work.

You could alter your code to read something like:
      changeLF ← { tmp←⍵ ⋄ tmp[ ( ⍸ (⎕ucs 97) = w ) ] ← ' '  ⋄ tmp}

In 16.0 onwards you can use the At operator:
      changeLF←{' '@{(⎕ucs 10)=⍵}⍵}

or better still
      changeLF←{' '@((⎕ucs 10)=⊢)⍵}
User avatar
AndyS|Dyalog
 
Posts: 257
Joined: Tue May 12, 2009 6:06 pm

Re: Change array inside DFNS

Postby Yves on Thu Jun 21, 2018 9:55 am

Hi Andy,
Thank you for your time.

i am not sure to well understand usage of ⊢, but it is wonderful solution.

finally, DFNS is only to transform something like
      tab ← changeLF tab


Yves
Yves
 
Posts: 39
Joined: Mon Nov 30, 2015 11:33 am


Return to Language

Who is online

Users browsing this forum: Bing [Bot] and 1 guest