[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] include files




On Dec 22, 2007, at 3:03 PM, William Brent wrote:
thanks to all.  that works.

but i guess i still need to use global variables with this, right?  i tried declaring a few in the header file, then referencing them in the main file after loading.  as i'm sure you know, the declarations don't carry through.  

any thoughts on this?  i think it would be nice to have a method for embedding the text of another file as though it were actually in the main file.  i guess .load evaluates the contents of the other file, but doesn't copy it in.  in a perfect world, what i'm looking for would be the same as a #include < header.h> from C.  is there a reason this would be a bad idea?

Unfortunately, that isn't possible structurally.

To execute any code, the interpreter has to compile it first into a function, which it then executes. Any variables that you declare belong to that function.

In a way, you're asking for the following:

f = { var aa = 1;
g = { var bb = 2; bb };
aa + bb  // the variable bb to be accessed outside its scope
}

... which is an interesting idea, but that would open up the following ambiguity which could not be supported logically at all:

f = { 
g = { var aa = 1; aa };
h = { var aa = 2; aa };

aa
};

What should this function return? 1 or 2? There is, of course, no correct answer, and SuperCollider properly prevents you from writing this.

So, if you want a variable namespace that persists across multiple files (and, thereby, multiple function definitions), environment variables are the right way to go. (You might also search the archives for an earlier post of mine explaining why environment variables are technically not global variables, even though you can use them as such.... oh, here it is... http://www.nabble.com/question-about--7E-to11295150.html#a11320423 )

hjh


: H. James Harkins

: jamshark70@xxxxxxxxxxxxxxxxx

: http://www.dewdrop-world.net

.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:


"Come said the Muse,

Sing me a song no poet has yet chanted,

Sing me the universal."  -- Whitman