Created
October 12, 2014 21:30
-
-
Save marinuso/884915fb157c0c102fa8 to your computer and use it in GitHub Desktop.
Explanation of APL code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type←{ | |
''≡0↑⍵:'str' ⍝ if the first zero items are the empty string, this is a string. | |
⍬≢⍴⍵:'list' ⍝ if it is not a string, but it has more than zero dimensions, it is a list. | |
⍵=⌈⍵:'int' ⍝ if it is equal to its ceiling, it can be considered an int. | |
⍝ (there is literally no way to tell the difference between 1 and 1.0 in APL.) | |
'float' ⍝ if it isn't one of the above, it must then be a float. | |
} | |
round←{ | |
0::1 ⍝ if something goes wrong, return 1 | |
∆←10*⍺ ⍝ 10 log left arg | |
∆÷⍨⍎0⍕⍵×∆ ⍝ multiply right arg by ∆, format with zero decimal places, execute the result, and divide by ∆ again. | |
} | |
enumerate←{ | |
0::1 ⍝ if something goes wrong, return 1 | |
(¯1+⍳⍴⍵),¨⊂¨⍵ ⍝ combine each element with its position minus 1. | |
} | |
range←{ | |
0::1 ⍝ if something goes wrong, return 1 | |
0<∆←-⍺⍺:⌽∆+⍵(∆∇∇)⍺ ⍝ if the step is negative, build the reverse of the list with the positive step, then reverse that. | |
⍺<⍵:⍺,⍵∇⍨⍺-∆ ⍝ if ⍺ is smaller than ⍵, return ⍺ followed by the result of building the list with the next step. | |
⍬ ⍝ if not, return the empty list. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment