Re: cl.apl

2020-12-25 Thread Dr . Jürgen Sauermann

  
  
Hi Bill,
  
  as to my previous email, I have checked the EACH operator again
  and it seems like
  my previous suspicion regarding the EACH macros was wrong.
  
  I have created an automated testcase (see attachment) that
  compares the EACH results for both 
  primitive dyadic functions (which use the built-in non-macro
  variant of EACH)
  and for defined functions (which uses one of the EACH macros that
  I mentioned.

You can run the testcase it with:

apl -T Macros.tc

Every run uses different test data and it shows no differences
between the two variants. That doesn't fully prove that
there are no faults related to EACH, but if there are any then they
seem to exist in
both the build-in EACH and in the macro based EACH.

Regarding your initial problem, I share your view that the two
expressions that you mentioned
should be the same, but I can't quite see where the problem is. If
one of the expressions
does not execute (and you can't see know why) then you may want to
try ]log 25 and ]log 26 to
get more details.

Happy Xmas to you and your family,
Jürgen



On 12/23/20 4:32 PM, Bill Daly wrote:

Hi
  Jürgen,
  
  
  I'm sending a not-yet-ready-for-prime-time version 0-2-10 of APL
  Library and version 0_2_0 of the cl workspace that was included in
  version 0-2-9 of the library.
  
  
  Can you look at function cl∆assign and line 5.  I replaced the
  phrase ' (⊂cl∆dropFlag) utl∆stringEquals ¨ toc[;1]' with
  '{cl∆dropFlag utl∆stringEquals ⍵}¨ toc[;1]' so that the function
  would execute.
  
  
  I'm of the view that the two phrases should be equivalent.
  
  
  If you find, as I have done over the past few days, that staring
  at this stuff on the screen gives you a headace, could you test
  the function test_data in workspace find_test_data?  I wrote this
  thing to find my test data on some foreign machine but have only
  tested it on my own.
  
  
  Thanx
  
  
  w
  
  


  

⍝ Macros.tc
⍝ --

⍝ Test the equivalence of:
⍝  1. the build-in dyadic EACH operator (A f ¨ B when f is primitive)
⍝  2. the build-in dyadic EACH macros   (A f ¨ B when f is defined)
⍝

  ⍝ initialize ⎕RVAL
  ⊣0 ⎕RVAL 8↑256|⎕TS

⍝ set A and B to values with the same structure but different ravels
⍝
A←B←1∣⎕RVAL 2 2 (0 10 0 0 1) 3
(∈A)←1⌽∈B

⍝ set S to a random integer scalar
⍝
S←100 | ⎕RVAL ''


⍝⍝⍝
⍝ compute the build-in operator dyadic EACH for the primitive +
⍝
SS←S +¨ S   ⍝ scalar /scalar
SB←S +¨ B   ⍝ scalar /array
AS←A +¨ S   ⍝ array /scalar
AB←A +¨ B   ⍝ array /array

⍝ create a defined function
⍝
∇Z←A PLUS B
 Z←A + B
∇

⍝ check that EACH with the defined function
⍝ is equivalent to EACH with the prmitive function
⍝
SS ≡  S PLUS ¨ S
1

SB ≡  S PLUS ¨ B
1

AS ≡  A PLUS ¨ S
1

AB ≡  A PLUS ¨ B
1

⍝⍝⍝
⍝ compute the build-in operator dyadic EACH for the primitive ,
⍝
SS←S ,¨ S   ⍝ scalar /scalar
SB←S ,¨ B   ⍝ scalar /array
AS←A ,¨ S   ⍝ array /scalar
AB←A ,¨ B   ⍝ array /array

⍝ create a defined function which changes the shape
⍝
∇Z←A COMMA B
 Z←A , B
∇

⍝ check that EACH with the defined function
⍝ is equivalent to EACH with the prmitive function
⍝
SS ≡  S COMMA ¨ S
1

SB ≡  S COMMA ¨ B
1

AS ≡  A COMMA ¨ S
1

AB ≡  A COMMA ¨ B
1

⍝⍝⍝
⍝ compute the build-in operator dyadic EACH for the primitive ≡
⍝
SS←S ≡¨ S   ⍝ scalar /scalar
SB←S ≡¨ B   ⍝ scalar /array
AS←A ≡¨ S   ⍝ array /scalar
AB←A ≡¨ B   ⍝ array /array

⍝ create a defined function
⍝
∇Z←A EQUIV B
 Z←A ≡ B
∇

⍝ check that EACH with the defined function
⍝ is equivalent to EACH with the prmitive function
⍝
SS ≡  S EQUIV ¨ S
1

SB ≡  S EQUIV ¨ B
1

AS ≡  A EQUIV ¨ S
1

AB ≡  A EQUIV ¨ B
1

⍝⍝⍝
⍝⍝⍝
⍝
∇Z←A RANDOM_REPLACE B;VB;VS
 ⍝
 ⍝ randomly replace half of the top-level items of B with A
 ⍝
 VB←,B   ⍝ keep it simple
 VS←{2|⎕RVAL '' ⊣  ⍵ } ¨VB   ⍝ random 0/1 vector of length ⍴VB
 (VS/VB)←A   ⍝ replace random subset with A
  Z←(⍴B)⍴VB
∇

QA←S RANDOM_REPLACE A
QB←S RANDOM_REPLACE B

(QA , ¨ QB) ≡  (QA COMMA ¨ QB)
1

)SIC
)ERASE A B S SS SB AS AB PLUS COMMA



Re: APL Christmas 2020 doodle: Tree

2020-12-25 Thread Hans-Peter Sorge

Hi,

in GNU APL  monadic ↑ takes the first element ( that is of a vector or 
higher ranking matrix, try ↑ 3 3 3 ⍴'abc' 'cde').
As the resulting vector has three elements you end up replicating them 
9, 2, 9 times ( 9 2 9 / 'abc').


So there is no application of the replication vector 9 2 9 to all of the 
right elements.
Side note 9 2 9 / 'abc' 'def' 'xyz' is an *element wise* replication as 
left and right vectors are of same length.
Try each: 9 2 9 /¨ 'abc' 'def' . The left argument is being applied to 
each right vector.


Using monadic ⊃ you end up disclosing a vector of vectors resulting in a 
matrix.

 ⊃'abc' 'def'
abc
def

Using 9 2 9 / ⊃'abc' 'def' will replicate the matrix column wise.
That is the same effect as with  ⊃ 9 2 9 /¨ 'abc' 'def' .

Best Regards
Hans-Peter






Am 24.12.20 um 09:08 schrieb Russtopia:
Thank you so much for a rapid answer. With no background into the 
history of the language, I would not have known where to look for this 
sort of thing.


I see now in Dyalog's "Mastering Dyalog APL, 1st Ed.", ~p372 
"Specialists Section" there are discussions about this and related 
language differences.
There are a few items to digest there in regards to their ⎕ML System 
Variable and how it handles APL2 (IBM) vs. Dyalog APL dialects.


The more I explore, the more I question whether I must choose to study 
"the APL2 path" or "the Dyalog APL path" ... :) I hope I do not have 
to choose!
So far, trying both dialects while learning has illuminated some 
concepts for me, but I fear I might confuse myself with implementation 
differences.


Again, thank you very much for the insight.
-Russ


On Wed, 23 Dec 2020 at 23:21, Kacper Gutowski > wrote:


On Wed, Dec 23, 2020 at 10:46:13PM -0800, Russtopia wrote:
> [Dyalog]
> 9 2 9/↑'∘⌹∘' ' ⌹ '
> ∘⌹⌹∘
>          ⌹⌹
>
> [GNU]
> 9 2 9/↑'∘⌹∘' ' ⌹ '
> ∘⌹⌹∘
>
> Is it unexpected that GNU APL does not apply the Compress (/)
across
> multiple right-hand items?

There are some subtle differences in how / works in Dyalog and in
GNU APL,
but here the reason is much more prosaic.

By default the monadic ↑ and ⊃ are swapped in Dyalog.  It has a
setting
called ⎕ML that controls it, and if you set ⎕ML←2, it will interpret
this expression the same way GNU APL does:

       9 2 9/⊃'∘⌹∘' ' ⌹ '
∘⌹⌹∘
          ⌹⌹


-k