Skip to content

Instantly share code, notes, and snippets.

Fronx Wurmus
Zionskirchstr. 11
10119 Berlin
; (this is all fantasy code.)
;
; a response is a thing that takes in a trigger, and outputs a sequence of intensities.
;
; parentheses are used for zooming in.
; if a sequence has three items, it is automatically interpreted as a triplet. (same for any number of notes.)
; symbols can be mapped to note configurations using a "let"-like construct.
; parsing of strings using "notes": add spaces between all characters, then interpret as list.
; example:
require 'ripper'
class TestParser < Ripper::SexpBuilder
def self.from_file(filename)
TestParser.new(File.read(filename))
end
def parse
@methods = []
@calls = []

intro to block params

analogy time!

you know methods. methods can bind names to arguments, like so:

def times_two(x)
  x * 2
end
5 1 3 <. 3 2 4 NB. element-wise minimum
3 2 4
5 1 <. 3 2 4
|length error NB. okay, makes sense
1 <. 3 2 4
1 1 1 NB. huh?
data Unit a = Kilogram a
| Meter a
| Second a
-- 1 N = 1kg * m/s^2
-- lalala pseudo-code here!!!
type Newton a = Div (Div (Mul (Kilogram a) (Meter a))
(Second a))
(Second a)
module FunctorComposition where
import Prelude hiding ( Functor
, fmap
)
data Tree a = Leaf a | Branch (Tree a) (Tree a) deriving Show
class Functor f where
fmap :: (a -> b) -> f a -> f b
HTTP:
GET /some/path?a=b&c=d
Sinatra, inside 'get' block:
params == {:a => 'b', :c => 'd'}
HTTP:
GET /blog/post-123?page=1
Sinatra, inside 'get' block:
@fronx
fronx / scope.md
Last active December 28, 2015 23:39

Scope of Names

For each of the following programs: what is the return value of the last expression? Why?

def a(a)
  a
end
if (reader == NULL) {
for (i=0; i < n_frames; i++) {
*writer++ = SAMPLE_SILENCE; } }
else {
for (i=0; i < n_frames; i++) {
*writer++ = *reader++; } }
// HAHAHA