Skip to content

Instantly share code, notes, and snippets.

@smosher
smosher / SiPrefixes.io
Last active Jul 21, 2019
SI Prefixes for Io
View SiPrefixes.io
# -- SiPrefixes.io --
#
# convenience Number methods essential
# for dealing with large scale ranges
# eg. EE calculations
#
# Ex:
# 24 giga
# 2.400000e+010
@smosher
smosher / phasedist.io
Created Jul 30, 2014
Phase Distortion Synthesis
View phasedist.io
// https://en.wikipedia.org/wiki/Phase_distortion_synthesis
// NB. completely untested
Range
pi := 3.14159265
tau := 2 * pi
FreqCtr := Object clone do(
@smosher
smosher / GrepRole.io
Last active Jan 3, 2016
Grep role for Sequences.
View GrepRole.io
Regex
GrepRole := Object clone do(
grep := method(x,
self split("\n") select(
matchesOfRegex(x) map(k, k) size > 0
) map(k, k)
)
)
@smosher
smosher / pattern_match.io
Created Dec 22, 2013
pattern matching demo in Io
View pattern_match.io
// 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
@smosher
smosher / iolanguage_todo.md
Last active Dec 15, 2015
todo list for Io
View iolanguage_todo.md

Purpose

  • To set up a useful, non-toxic Io base environment for development.
  • To promote (and simplify) the better practices.

Things to investigate

  • Complete knowledge of scoping.
  • Embedded docs.
  • Testing.
@smosher
smosher / ListLiteral.io
Last active Dec 15, 2015
DSL for List literals using List [ ... ] as a List-scoped constructor
View ListLiteral.io
/* Unsafe version:
List squareBrackets := method(
call message arguments clone map(x,
call sender doMessage(x)
)
)
*/
// Safe version:
List squareBrackets := method(
@smosher
smosher / MapLiteral.io
Last active Dec 15, 2015
DSL for Map literals using Map { ... } as a Map-scoped constructor
View MapLiteral.io
// 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
@smosher
smosher / introspection.io
Created Apr 4, 2013
http://rosettacode.org/wiki/Introspection — an Io solution exists, but makes no attempt at extra credit: Report the number of integer variables in global scope, and their sum.
View introspection.io
// 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
@smosher
smosher / pushpath.sh
Created Apr 18, 2012
bash: exports PATH with operand appended
View pushpath.sh
pushpath () { export PATH=${PATH}:${1}; }
# example: $ pushpath ~/bin
@smosher
smosher / simple_range.ml
Created Dec 28, 2011
OCaml -- simple infix range op.
View simple_range.ml
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