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? |
| 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 |
| #!/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 |