- To set up a useful, non-toxic Io base environment for development.
- To promote (and simplify) the better practices.
- Complete knowledge of scoping.
- Embedded docs.
- Testing.
# -- SiPrefixes.io -- | |
# | |
# convenience Number methods essential | |
# for dealing with large scale ranges | |
# eg. EE calculations | |
# | |
# Ex: | |
# 24 giga | |
# 2.400000e+010 |
// https://en.wikipedia.org/wiki/Phase_distortion_synthesis | |
// NB. completely untested | |
Range | |
pi := 3.14159265 | |
tau := 2 * pi | |
FreqCtr := Object clone do( |
Regex | |
GrepRole := Object clone do( | |
grep := method(x, | |
self split("\n") select( | |
matchesOfRegex(x) map(k, k) size > 0 | |
) map(k, k) | |
) | |
) |
// Work in progress, code coming soon: | |
Io> match(1) [2: 5, 4: 2, 1: "yay"] | |
==> yay | |
Io> match(2) [2: 5, 4: 2, 1: "yay"] | |
==> 5 | |
Io> a := 10 | |
==> 10 | |
Io> match(a) [2: 5, 4: 2, 10: "yay"] | |
==> yay |
/* Unsafe version: | |
List squareBrackets := method( | |
call message arguments clone map(x, | |
call sender doMessage(x) | |
) | |
) | |
*/ | |
// Safe version: | |
List squareBrackets := method( |
// mostly a guess: | |
OperatorTable addOperator(":", 13.5) | |
// : is a key-value pair (list) constructor on sequences: | |
Sequence : := method(a, return list(self, a) ) | |
Message : := method(a, return list(self, a) ) | |
Map curlyBrackets := method( | |
env := call sender clone | |
x := Map clone |
// dumb test for int-ness, since Io doesn't have ints | |
// rather than being cheeky and doing Integer := Number clone | |
Number isInt := method(self == self roundDown) | |
countAndSumLobbyIntegers := method( | |
_ := Lobby slotNames select(x, | |
(Lobby getSlot(x) type == "Number") | |
) map(x, Lobby getSlot(x)) select(x, x isInt) | |
("There are " .. (_ size) .. " integer Numbers in Lobby") println |
pushpath () { export PATH=${PATH}:${1}; } | |
# example: $ pushpath ~/bin |
let ( -- ) x y = | |
let step_y = match y > x with | |
| true -> ( fun n -> n - 1 ) | |
| false -> ( fun n -> n + 1 ) | |
in | |
let rec mklist x y ll = | |
if x == y then y::ll | |
else mklist x (step_y y) (y::ll) | |
in |