Skip to content

Instantly share code, notes, and snippets.

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?

intro to block params

analogy time!

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

def times_two(x)
  x * 2
end
require 'ripper'
class TestParser < Ripper::SexpBuilder
def self.from_file(filename)
TestParser.new(File.read(filename))
end
def parse
@methods = []
@calls = []
; (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:
Fronx Wurmus
Zionskirchstr. 11
10119 Berlin
(def rock
{ :snare '(_ O)
:kick '(O _) })
(def dnb
; '(1 _ . _ 2 _ . _ 3 _ . _ 4 _ . _)
{ :snare '(_ _ _ _ O _ _ o _ o _ _ O _ _ _)
:kick '(O _ _ _ _ _ _ _ _ _ O _ _ _ _ _) })
(def reggae
?- Whut.
% ... 1,000,000 ............ 10,000,000 years later
%
% >> 42 << (last release gives the question)
?-
c(1,2,3,4,5,6,7)[1:1 + 4 -1]
# => [1] 4
c(1,2,3,4,5,6,7)[1:(1 + 4 -1)]
# => [1] 1 2 3 4
@fronx
fronx / print_aligned.rb
Last active December 10, 2015 12:29
print tables on the console
#!/usr/bin/env ruby
def print_aligned(text, sep)
lines = text.to_s.split("\n").map do |line|
line.split(sep)
end
maxes =
lines.inject([]) do |maxes, line|
line.map(&:length).each_with_index do |length, index|
if length > maxes[index].to_i
#! /usr/bin/env ruby
require 'json'
STDIN.read.split("\n").each do |line|
data = JSON.parse(line)
puts JSON.pretty_generate(data)
# puts ARGV.map { |k| data[k] }.join(' ')
end