New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undocumented syntax for "'{;' Comprehensions" #6264
Comments
I could only get this to output a constant value. Could you please provide an example of where you might use this? |
It's because It's a demonstration. Would you like more examples? (It's also related to Python Generators in a way, you might know it) EDIT: List comprehension is a bit like recursions for those who always use for loops, sort of.... the same problems can be done both ways, but sometimes you just prefer one way over another |
It's called a termination termination clause apparently!
Edit: Oh wait ignore me! This is wrong. |
Ok, but that's also a SC terminology, right? I don't remember this elsewhere. Another thing is that it does not just terminate, it can continue as the second example. Let's see what's that. |
Sorry I messed up, ignore that last thing. Here is the grammer from the help doc.
I'm also quite confused by lines like this {;x, x <- (5..15), x > 10} which returns 5. I also still can't see why you'd r = Routine { loop { {; if (x*2 > 10) { yield (x*2)}, x <- (2..6) } } }; over r = {: x*2, x <- (2..6), x*2 > 10 }
r.all or r.next |
It's deep in the parser of the language. In what sense it is "wrong"? |
This line means list comprehension must begin with the literal Either the documentation is wrong, or the actual parser is wrong. I'm just saying, before considering documenting the behaviour of Here the bit of the parser for reference
It is clearly there.
|
Can you have an interactive control flow, or when you can combine timing and selection to alter the result? r = Routine { |
So JMC wrote a bad parser that does this thing? It looks like like it was just "forgotten", but was indeed implemented. It's part of the language, it's clear. Many ideas never went to the foreground for one reason or another. We can just forget about it too )))) But some curiosity would be nice. I will ask him, maybe he remembers. |
There is a good chance I'm missing something, but I just can't see the use-case? This does the same but is much easier to read. x = {: x*2, x <- (1..100), (x*2).mod(7) == 0 }
x.next
I wasn't suggesting not to do this! Just that it is new to me and violates what the existing docs say. I do think a use-case where there is some clear benefit over using |
It's not a list comprehension, it's something else. But related. People experiment with other "comprehensions" in other languages, like Haskell. Maybe it was just forgotten. Not even LC is known in the SC community. Not rarely do people find it strange in the code, which is unfortunate. Let's give some time to this one, no need to rush. )))) |
I think, just playing a little and without any reference, that it is more flexible in terms of control inside the comprehension, how much and when then will deliver new values independently etc. Am I wrong? |
The examples you've posted so far can more concisely be reproduce in the It is also a little confusing because it returns the value, not the routine, but perhaps there are situations where this is useful? It should definitely be documented — assuming it isn't an unfinished feature —, the question is to what extent? |
I will come up with more examples exploring it, and we will analyze them and see if it makes sense to resurrect it after two decades, or let it be forgotten forever )) (No time today, though) Anyway, we need to figure all out before writting documentation |
SuperCollider has had the great feature of implementing List Comprehension for decades.
But taking a look around the source code, I found a strange syntax that I don't remember being documented anywhere. And it's not an "exotic" curiosity, it's a sophisticated feature.
Have you ever seen List Comprehensions using
{;
instead of{:
? These aren't your typical list comprehensions, but they've got some similar vibes. I will call it "Monad Comprehension", because that's a way it could be interpreted in Haskell.Look:
Normal List Comprehension syntax:
{:
This one gives you control over what gets yielded and when.
Use
{;
when you only want to output specific results or need to control outputs based on certain conditions, present of past states, etc.It doesn’t exist as List Comprehension in Haskell, but can be achieved as a Monad Comprehension. See:
Another Example in SuperCollider:
It deserves proper documentation.
--
The text was updated successfully, but these errors were encountered: