I’m trying to make a toy web app where the web server will interact with sclang. I’m doing this in Elixir, which doesn’t have an SC library already; that’s fine, I’m comfortable using sclang. However, when I open sclang from Elixir, I’m not sure how I can get sclang to execute commands correctly. For example, if I have the following simple code, how can I actually get the parenthesis groupings to work, and how can I sclang to block on running the next command while the previous one runs?
Thanks guys. I’m moving forward again! Out of curiosity, is there any way to break up code into multiple parts in SC? IE, an import/export system? As far as I can tell, the only thing you could (theoretically, but inadvisedly) do would be to read a file and eval it, or (laboriously) create an extension to load.
A few of my extensions use prototype-based programming to allow objects to be defined at runtime. Those definitions are loaded at runtime by executing file contents, but behaviorally those files are just creating containers for data and functions that are being stored but not necessarily used at that time. I’ve been doing this for years and it’s stable. (Of course it’s possible to abuse the mechanism, but it’s also possible to abuse a chainsaw to do damage to someone else’s property and we don’t ban chainsaws just for that reason.)
Now, it sounds like you’re asking about a Java or Python style import facility. We don’t have that as such. The class library is compiled once at the start of a session and we don’t load class definitions dynamically after that. (You can use LanguageConfig to include or exclude directories, but it doesn’t take effect until recompiling the class library.) There have been discussions about dynamic loading but it’s a big change to interpreter internals (i.e. difficult and risky).
My use of prototypes is a workaround for this limitation. Sure, prototypes are not to everyone’s taste, but they do work and I’ve built some quite elaborate OOPy designs with them.
Plus, if that was ever a concern for you, loading files is performed by the language, not by the server, which means that slow or blocking file I/O won’t be performed on the audio thread