{
   "id" : "1-4R5",
   "is_private" : null,
   "code" : "// let's say there is a directory \"pat\" with *.scd files where each file contains, for example:\r\n// test.scd \r\n{ |dict,loc| // recieve global dict\r\n\tloc = ( //and define local(this file) dict, but if don't need it - just return anonymously\r\n\t\tselector: { |self, ev| self.at([\\p1,\\p2].choose).fn(ev) }, // sample selector\r\n\t\tp1: ( // some object \r\n\t\t\tfn: { |self, ev| // recieve self and some args\r\n\t\t\t\tPbind(*[ // return something\r\n\t\t\t\t\tinstrument: \\default,\r\n\t\t\t\t\tdelta: ev.delta/8,\r\n\t\t\t\t\tamp: Pseq((0.3..0.8).scramble, inf),\r\n\t\t\t\t\toctave: self.state.next\r\n\t\t\t\t])\r\n\t\t\t}, \r\n\t\t\tstate: Pseq((3..6), inf).asStream  // i.e. object attribute\r\n\t\t),\r\n\t\tp2: ( // altered version of p1\r\n\t\t\tfn: { |self, ev|  // able to access both local and global dict\r\n\t\t\t\tPbindf(loc.p1.fn(ev), \\mtranspose, self.state.next) // * dict.some_name.some_key.fn(ev),\r\n\t\t\t},\r\n\t\t\tstate: Pseq((1..3),inf).asStream\r\n\t\t)\r\n\t\t// etc..\r\n\t)\r\n}\r\n\r\n// and while working in file which resides above directory where test.scd located\r\n(\r\nvar dict = \"pat/*.scd\".resolveRelative.pathMatch.inject((), { |d, i| // create dictionary\r\n\td[i.basename.splitext[0].asSymbol] = i.load.(d) \r\n});\r\ndict.test.p2.fn((delta:2)).play;\r\n// or\r\nPspawn(\r\n\tPbind(*[\r\n\t\tmethod:\\par,\r\n\t\tdelta:Pseq((1..4),inf),\r\n\t\tpattern:Pfunc({ |ev|  // choose some random pattern from dict\r\n\t\t\tPfindur(ev.delta, dict.values.choose.selector(ev)) \r\n\t\t})\r\n\t]);\r\n).play\r\n)",
   "labels" : [
      "trick",
      "sclang",
      "dry"
   ],
   "description" : "i don't like scrolling large files and stick to \"don't-repeat-youself\" principle - therefore i come to this technique for code structuring which involves [using Environments as object prototypes](http://bit.ly/LAFfEg) and closures. sclang is cool )",
   "ancestor_list" : [],
   "author" : "vividsnow",
   "name" : "scrolless"
}
