What's the deal with that backslash?

Hello,

reading SuperCollider for the creative Musician I came across the following code example:

// Code Example 5.21

(
Event.partialEvents.keys.do({ |n|
	n.postln;
	Event.partialEvents[n].keys.postln;
	\.postln;
});\ // <- ?
)

What is the purpose of the backslash after the semicolon? I can see the difference in the post window but don’t understand why it does what it does.

With \:

...
nodeEvent
Set[pauseServerNode, delta, addAction, nodeID, tailOf, stopServerNode, resumeServerNode, asEventStreamPlayer, map, isPlaying_, freeServerNode, hasGate, releaseServerNode, headOf, instrument, group, after, isPlaying, before, latency]

->

Without \:

...
nodeEvent
Set[pauseServerNode, delta, addAction, nodeID, tailOf, stopServerNode, resumeServerNode, asEventStreamPlayer, map, isPlaying_, freeServerNode, hasGate, releaseServerNode, headOf, instrument, group, after, isPlaying, before, latency]

-> Set[ampEvent, serverEvent, midiEvent, durEvent, playerEvent, bufferEvent, pitchEvent, nodeEvent]

Cheers

The post window will output the last “thing” in a block of code, so, without the \, the last thing is Event.partialEvent.keys. The \ at the end is an empty Symbol, so the last output is blank, making the debug info more clear in this case.

2 Likes

That’s exactly right. The backslash (interpreted as the empty symbol, which prints “invisibly” to the post window) is essentially of a cheap trick that suppresses the automatic behavior of the interpreter to post the returned value of the last expression when a block of code is evaluated. Sometimes, we’ll attach postcs or postln to something in the middle of a block of code, and that’s the only thing we want to see/debug. If SC is also posting the last line, then it can become more complicated than necessary to isolate the content of the post window that you actually care about.

You could do the same thing with an empty string:


(
Event.partialEvents.keys.do({ |n|
	n.postln;
	Event.partialEvents[n].keys.postln;
	\.postln;
});"" // <- empty string
)
2 Likes