|
|
|
08-19-2019, 06:08 AM
|
#1
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
|
JSFX - While syntax checking.
Please, please, make this throw up a compilation error:
Code:
while (midirecv(mpos, msg1, msg23)) ? (
midisend(mpos, msg1, msg23);
// .... more valid statements
);
I've just spent an hour tracking it down
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
|
|
|
08-19-2019, 11:27 AM
|
#2
|
Human being with feelings
Join Date: Aug 2009
Location: NL
Posts: 1,453
|
It could be a valid approach in some cases though as long as the body of the if statement returns zero at some point.
|
|
|
08-20-2019, 03:51 PM
|
#3
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
|
Are you sure? Could you explain, step by step, what that construct would do?
As I understand it the two valid constructs, to get each MIDI message and process it, are:
Code:
while (
midirecv(mpos, msg1, msg23) ? (
// .... more valid statements
midisend(mpos, msg1, msg23);
); // .... end of midirecv() test
); // .,.. end of while
or
Code:
while (midirecv(mpos, msg1, msg23)) ( // .... no ? operator
// .... more valid statements
midisend(mpos, msg1, msg23);
); // .... end of while/midirecv()
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
|
|
|
08-21-2019, 10:07 AM
|
#4
|
Human being with feelings
Join Date: Aug 2009
Location: NL
Posts: 1,453
|
I didn't test it to be honest (not at home), but I'd expect it to keep executing the true case of that if-statement as long as midirecv returns non-zero.
If that "true"-case body ends on zero (the last statement being zero or not returning a value), I expect the while statement to terminate early (before running out of midi messages).
If midirecv returns zero, I would expect the body to not be called at all.
What actually happens?
I mean, I don't disagree that that construct is usually not what you want, but by excluding certain syntaxes, you risk removing other valid uses of them.
|
|
|
08-21-2019, 10:10 AM
|
#5
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
|
The problem was that I had the syntax I posted in my original post and that was giving me some odd (not really explainable) results.
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
|
|
|
08-21-2019, 10:12 AM
|
#6
|
Human being with feelings
Join Date: Aug 2009
Location: NL
Posts: 1,453
|
It didn't do what I just posted? What I wrote is what I would've expected for the syntax. Which is probably not what you wanted since it'd early out quite often before receiving all midi messages, thereby dropping some or all depending on the last statement in the body of the if-statement.
Now I'm curious! Maybe I'll investigate on the weekend.
|
|
|
08-22-2019, 01:59 AM
|
#7
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
|
Here's DarkStar's while construction rewritten to make it clear what's actually going on:
Code:
while(
// Repeats midirecv() until it returns zero. Note that this is all that happens
// inside the while loop.
midirecv(mpos, msg1, msg23)
)
? // Evaluates the result of the while loop after it has finished.
(
// This never gets executed, because a finished while loop always returns zero.
midisend(mpos, msg1, msg23);
// .... more valid statements
);
So yeah, this is valid JSFX, even though it includes unreachable code. Maybe an optional warning would be nice, but IMHO this shouldn't throw an error.
|
|
|
08-22-2019, 05:23 AM
|
#8
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
|
Guys, thank you for the clarifications. I'll have to check my typing more closely.
Also, this seems to work:
Code:
while (midirecv(mpos, msg1, msg23) ? (
midisend(mpos, msg1, msg23);
// .... more valid statements
); );
I've highlighted the parenthesis pairs.
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
|
|
|
08-22-2019, 06:02 AM
|
#9
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
|
Quote:
Originally Posted by DarkStar
Also, this seems to work:
|
Yeah, that's my favorite JSFX while variant.
Do note that in this case you will have to end your while loop with a non-zero statement, because else it stop looping if the last statement inside the loop happens to return zero.
Code:
while (midirecv(mpos, msg1, msg23) ? (
midisend(mpos, msg1, msg23);
// .... more valid statements
1; // Force while to loop
); );
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 05:56 PM.
|