{
   "is_private" : null,
   "id" : "1-5f6",
   "code" : "~constructPseudoMethods = { |envir|\r\n\tvar newEnvir = envir.collect { |value|\r\n\t\tvar argNames, argBlock, namesBlock, code, func;\r\n\t\tif(value.isKindOf(Function)) {\r\n\t\t\tfunc = value;\r\n\t\t\targNames = func.def.argumentString(withDefaultValues: true);\r\n\t\t\tnamesBlock =  func.def.argumentString(withDefaultValues: false);\r\n\t\t\targBlock = if(argNames.notNil) { \"|self, \"  ++ argNames ++ \"|\" };\r\n\t\t\tcode = \"{ |func, envir| { % envir.use { func.value(%) } } }\".format(argBlock ? \"\", namesBlock ? \"\");\r\n\t\t\t//code.postln;\r\n\t\t\tcode.interpret.value(func, envir)\r\n\t\t} {\r\n\t\t\tvalue\r\n\t\t}\r\n\t};\r\n\tnewEnvir.know = true; // we want a prototype object style environment\r\n};",
   "labels" : [
      "environment",
      "prototyping"
   ],
   "description" : "/*\r\nI often like to write out a library as an environment, like:\r\n\r\n~start_sound = { |freq, amp| <...> };\r\n~start_high_pitch_sound = { |amp| ~start_sound.(14000, amp) };\r\n\r\n… and then use loadRelative to load that library.\r\n\r\nThis, however has the problem that you can't stick the whole library into an environment that you call from the outside. e.g.\r\n\r\nq = ();\r\nq.use { resolveRelative(\"/library.scd\") };\r\n\r\nand then trying:\r\n\r\nq.start_sound(700, 0.1);\r\nq.start_high_pitch_sound(0.1);\r\n\r\nwill not work. Firstly, it will expect the environment as first argument of each function, second, it won't find a function like ~start_sound from within the call context.\r\n\r\nHere is a way to convert an environment as needed.\r\n\r\n*/",
   "ancestor_list" : [],
   "name" : "Converting an environment in a prototype object",
   "author" : "julian.rohrhuber"
}
