Skip to content

Read exercises

For each of the following exercises, try to figure out what the input will produce in the TryAPL terminal. Check your answers by opening the "Output" tab.

If you think an error will occur, try to predict which error it will be and where the arrow will point to.

The exercises are not checked or graded: use them to check your knowledge!

Read problem 1

      'softheartedness'~'otherness'
      'softheartedness'~'otherness'
fad

The set difference ~ function removes all occurrences of the right-hand array elements from the left-hand array


Read problem 2

      'platform''formatting'

      'emergency''encyclopedia'

      'networking''kingdom'

      'spring''ringtone'
      'platform''formatting'
platforming
      'emergency''encyclopedia'
emergencylopdia
      'networking''kingdom'
networkingdm
      'spring''ringtone'
springtoe

The union ∪ function adds to the left array elements of the right array not already in the left array.


Read problem 3

The two arrays below list some English and Finnish words.

        EN  'home' 'cat' 'tie' 'door' 'on' 'me' 'auto'

        FI  'kissa' 'ovi' 'auto' 'on' 'tie' 'home' 'talo'
      ⍝ English words that are also Finnish words
      EN  FI
      ⍝ Finnish words that are also English words
      FI  EN
        EN  'home' 'cat' 'tie' 'door' 'on' 'me' 'auto'
home  cat  tie  door  on  me  auto
        FI  'kissa' 'ovi' 'auto' 'on' 'tie' 'home' 'talo'
kissa  ovi  auto  on  tie  home  talo
      ⍝ English words that are also Finnish words
      EN  FI
home  tie  on  auto
      ⍝ Finnish words that are also English words
      FI  EN
auto  on  tie  home

The intersection function keeps the elements of the left array that also occur in the right array, so the result takes its order from the left argument. That is, EN ∩ FI lists them in the order they appear in EN, and FI ∩ EN in the order they appear in FI.


Read problem 4

      ('re'),¨'play' 'cord' 'peat' 'serve' 'quest' 'present'
      ('re'),¨'play' 'cord' 'peat' 'serve' 'quest' 'present'
LENGTH ERROR
      ('re'),¨'play' 'cord' 'peat' 'serve' 'quest' 'present'
            

What the previous code attempts to do is catenate each element of the left array, 'r' and 'e', with each element of the right array, but the lengths clearly do not match.


Read problem 5

      ('re'),¨'play' 'cord' 'peat' 'serve' 'quest' 'present'
      ('re'),¨'play' 'cord' 'peat' 'serve' 'quest' 'present'
replay  record  repeat  reserve  request  represent

Read problem 6

      arrow  5 7' ▉▉     ▉▉     ▉▉    ▉▉▉▉    ▉▉    '
      arrow
 ▉▉    
 ▉▉    
 ▉▉    
▉▉▉▉   
 ▉▉    
      arrow
      arrow  5 7' ▉▉     ▉▉     ▉▉    ▉▉▉▉    ▉▉    '
      arrow
 ▉▉    
 ▉▉    
 ▉▉    
▉▉▉▉   
 ▉▉    
      arrow
    
▉▉▉▉▉
▉▉▉▉▉
    

Read problem 7

      'm'{()}'nonemployments'



      'i'(≠⊆⊢)'pestilentially'
      'm'{()}'nonemployments'
┌────┬────┬────┐
noneployents
└────┴────┴────┘
      'i'(≠⊆⊢)'pestilentially'
┌────┬────┬────┐
pestlentally
└────┴────┴────┘

The second function is a tacit form of the first function.


Read problem 8

The following code makes heavy use of the ⍨ commute operator, try rewriting it using parentheses to figure out what it does.

      ↓↑1,⍨¨0/⍨¨1-5
      ↓↑1,⍨¨0/⍨¨1-5
┌─────────┬─────────┬─────────┬─────────┬─────────┐
1 0 0 0 00 1 0 0 00 0 1 0 00 0 0 1 00 0 0 0 1
└─────────┴─────────┴─────────┴─────────┴─────────┘

Without the commute operator, this would be ↓↑((((⍳5)-1)/¨0),¨1)


Read problem 9

      |5-9

      (|5-9)(/⍤0)'█'
      |5-9
4 3 2 1 0 1 2 3 4
      (|5-9)(/⍤0)'█'
████
███ 
██  
   

   
██  
███ 
████

Read problem 10

      {⍉↑(|) (10-|2×) (|)}5-9

      ({⍉↑(|) (10-|2×) (|)}5-9)(/⍤1 2)'█ █'
      {⍉↑(|) (10-|2×) (|)}5-9
4  2 4
3  4 3
2  6 2
1  8 1
0 10 0
1  8 1
2  6 2
3  4 3
4  2 4
      ({⍉↑(|) (10-|2×) (|)}5-9)(/⍤1 2)'█ █'
████  ████
███    ███
██      ██
        

        
██      ██
███    ███
████  ████

(/⍤1 2) matches the 1-cells of the left-hand argument with the 2-cells of the right-hand argument. Since the right-hand array is only 1-dimensional, a 2-cell is interpreted as the whole array instead of returning an error. That is, the rows of the left-hand array are matched with the whole of the right-hand array.


Read problem 11

        v  2*⍳10

      v

      ⍉⍪v

      ⍴⍉⍪v
        v  2*⍳10
2 4 8 16 32 64 128 256 512 1024
      v
10
      ⍉⍪v
2 4 8 16 32 64 128 256 512 1024
      ⍴⍉⍪v
1 10

The phrase ⍉⍪ can be used to turn a vector into a one-row matrix.


Read problem 12

        M  ⍉⍪2*⍳10

        M  3*⍳10

      M,⍪'XY'
        M  ⍉⍪2*⍳10
2 4 8 16 32 64 128 256 512 1024
        M  3*⍳10
3 9 27 81 243 729 2187 6561 19683 59049
      M,⍪'XY'
2 4  8 16  32  64  128  256   512  1024 X
3 9 27 81 243 729 2187 6561 19683 59049 Y