Error in console from supercollider book figure 1.1

In this thread a user is reporting a syntha error only to find out that he didn’t hightlight the play when analyzing the code

It seems that whenever I break up the code as shown in the book , and select after the last parenthese , the whole code is selected but I still get the error , iow the play is neglected

play({
var sines= 5, speed = 6;
Mix.fill(sines,
{arg x;
Pan2.ar(
SinOsc.ar(x+1*100,
mul:max(0,
LFNoise1.kr(speed)+
Line.kr(1,-1,30)
)
),rand2(1.0))})/sines})
This will not work when selecting after the last parenthese , it will give a
quote
ERROR: syntax error, unexpected BADTOKEN, expecting $end
in interpreted text
line 1 char 6:

			 ),rand2(1.0))})/sines})

unquote

When selecting everything with the cursor it works , or when writing the.whole code in one line !

Looks like a ,rand2 that should have been .rand2.

No, no the code is correct because it plays when selecting it all , it’s just when breaking it up that it refuses to play
That is def. a comma before rand2
Here’s the example from the book
1

Here 's the code , there absolutely no syntax errors , otherwise it would also refuse to play when selecting it all manually .
1

play({
var sines = 5, speed = 6;
Mix.fill(sines,
{arg x;
Pan2.ar(
SinOsc.ar(x+1*1000,
mul: max(0,
LFNoise1.kr(speed) +
Line.kr(1,-1, 30)
)
),rand2(1.0))})/sines})

AFAIU the reported problem is that the automatic code block selection does not include “play”, is that correct?
While that’s unfortunate for the syntax used in the example, I don’t think this is something we can change. Code block execution is meant for contents inside the parentheses. I personally tend to include external parentheses, like

(
play({
var sines = 5, speed = 6;
Mix.fill(sines,
{arg x;
Pan2.ar(
SinOsc.ar(x+1*1000,
mul: max(0,
LFNoise1.kr(speed) +
Line.kr(1,-1, 30)
)
),rand2(1.0))})/sines})

)

but for examples that are already printed that’s not much help I guess.

Best,
Marcin

Hi,

no worries, this is a common source of misunderstandings. My students always struggle with evaluation in the first sessions. It’s complicated by different operating systems and differences of evaluation in the IDE and the help system in previous SC versions.
However, the chapter “First Steps” in the included “Getting started”-Tutorial provides the basic idea. As Marcin pointed out, something outside parenthesis cannot be expected to be selected (except the special case of selecting a whole line). BTW, you got the code from here?

I am still verry confused .
I am replicating aan example by eli fieldsteel
1

this works when selecting everything with cursor and analyzing , I am aware of the begin end parentheses , but in the example he doesn’t use it

Sorry , new users can not post more then image at a time

When breaking up the code it doesn’t , unless I putt parentheses at both the beginning and the end
I’,ve read in the manual that it doesn’t matter that there any empty spaces in the code
2

I would like to know if blank spaces are best to be avoided or not
ANd genuine question, what the the difference between an arrow ( show in picture ) and a bold dot , they both seem to indicate blanck spaces , but I guess there is more to it

This is the example shown inthe you tube video , he clicks on the inside of the code and it executes ( he’;s on mac btw, I’m on pc )
video can be found here , example at the 05,36 mark

My code looks identical except for the arrow on the second line , yet it does not execute
If I backspace the second line of code so it lines up perfectly with the first line ( as his example ) it still does not execute like his does
I still need to select everything
1

@ noppes I got the code from the book , but thanks for pointing me out to the github page

My code looks identical except for the arrow on the second line , yet it does not execute
If I backspace the second line of code so it lines up perfectly with the first line ( as his example ) it still does not execute like his does
I still need to select everything

The example from your first screenshot is a SINGLE line. It’s broken into two lines visually because of “word wrapping” (note that there’s no “number” in front of the “second line” because it’s the continuation of the first line).
The example from your second screenshots clearly has a newline after “(MouseX.kr(1,”, note the line number (“2”) in front of “2000, 1)”.

What is the problem here? If you have multiple lines, you need to select them all before evaluating. If you’d like to evaluate without selecting, then either a) put everything in a single line (reasonable for shorter examples only) or b) but parentheses around the whole code block, e.g.
(
{SinOsc…


}.play
)

BTW blank spaces and tabs/indentation generally make no difference in SuperCollider. The choice to use them or not should be used for code readability primarily.
Newlines make difference only for code evaluation (i.e. evaluate a single line with shift-enter vs evaluate multiple lines, inside parentheses, with ctrl-enter - on Windows).

Regards,
Marcin

The arrow is a tab character; the dot is a space. The compiler treats both identically.

Spaces are not at all important to the compiler but they make a huge difference for humans reading your code (including yourself).

Imagine yourself 10 years from now, coming back to code you had written 5 years earlier. You could have written the code as a solid block without any spaces, but you won’t be able to make any sense of it in that case. Or you could write the code with logical line breaks, consistent indentation, and spaces after commas and around math operators – and the formatting will help guide your eye to what is important.

Sctweets are an exercise in packing maximum functionality in minimum space. They should not be taken as a model for good coding style.

hjh

Guys here’s another one taken straight from the manual , pasted into s.c.
It automatically created the indents but refuses to play when placing cursor outside last parenthese

When selecting them all with the cursor , or placin all in one line , it does work

As shown in the previous post , the parentheses still don’t work , I need to select the whole block for analyzing

So how to paste code , without the pasted code inserting new lines , meaning the actual numbers before the lines


Being a non coder , this is really confusing and haven’t come across anything that adresses this in the manual or the S.C.book

I’m sorry that this is becoming a stumbling block for you… But I think you’re almost there.

I’d strongly – very strongly – in the strongest possible terms – advise against writing your code all on one line.

When you reach the point of writing a SynthDef that spans 50 lines, you will need them to be formatted properly so that you can read it later.

The solution here is to figure out what is happening with the region detection.

There is a known… behavior? bug?.. in the IDE where a syntax error earlier in the file may cause regions after the syntax error not to be detected.

I’m considering these facts:

  • The bit you posted is from line 33, so there are almost three dozen lines before this snippet.

  • The code above is unknown, but there was some code pasting and editing, and some prior execution issues.

So it seems at least plausible that there could be a mismatched paren or something in the earlier lines.

Is it a bug? It’s logged as one… It’s because the editor keeps track of the grammar of the code file, for highlighting, indentation and region detection. An open paren without a matching closing paren changes the reading of the grammar. A region is marked by a line starting with a paren, at the top level of grouping (no open brackets)… if that condition isn’t met, then the region won’t work.

As an experiment, does the region work if you paste those lines 33-38 at the top of a new document? If this does work (and it should), then that was the problem. If it doesn’t, a/ I’d be surprised and b/ we’d have to investigate exactly what’s being copied.

Note that this isn’t to say you must always paste code at the top of a document – only that this is a valid diagnostic test to see if the problem was caused by a syntax issue earlier in the other document. By itself, this is a troubleshooting step, not the solution.

hjh

1 Like