Impressum/Kontaktparent nodes: APL concepts in Smalltalk

Examples

Prime Numbers

A detailed description can be found in this Wikipedia article about APL


The APL function looks like this:
A←30
R←(~A∊A∘.×A)/A←1+ιA
Note: APL is evaluated from right to left

The corresponding Smalltalk code with AplLike package looks like this:
| a r |
a := (30 aplInterval) +1.
r := a aplCompress: ( a aplMembership: (a aplOuterProduct: #* with: a)) aplNot.
self assert: r aplContents  = #(2 3 5 7 11 13 17 19 23 29 31)
Note: Smalltalk is evaluated from left to right


Sudoku Board

R←SUDOKU N
R←⊃(,⍉C⍴¯1+V)⌽¨⊂V←⍳×/C←N,N
In the smalltalk Solution the following variables are used:
shape C←N,N
numberVector V←⍳×/C
rotateVector (,⍉C⍴¯1+V)

Note that the aplEach (¨) on aplRotate is done differently on AplLike.
We use the Smalltalk block as argument to aplEach.
There are still some issues with disclose/enclose which are not solved yet.
create: n
| rotateVector numberVector shape |
myCellSize := n.
shape := (Array with: n with: n) asApl.
numberVector := (shape aplReduce: #*) aplInterval.
rotateVector := (numberVector - 1 asApl aplReshape: shape) aplTranspose aplRavel.
self
 myBoard:
  (rotateVector aplEachBlock: [ :e :v | (v aplDisclose aplRotate: e) aplEnclose ] with: numberVector aplEnclose)
    aplDisclose