I have accidentally came up with the code below:
(format t "~{~[~:R~;~S~:;none~] chance~^, ~}" '(0 1 0 2 0 3))
But I can’t explain why does it work the way it does. The behaviour that I see is such that:
odd elements of the list seem to define the number of conses to feed to the conditional. So, in the form it is above, it will print:
;; first chance, second chance, third chance
And if you replace zeros with ones, then the output is:
(format t "~{~[~:R~;~S~:;none~] chance~^, ~}" '(1 1 1 2 1 3))
;; 1 chance, 2 chance, 3 chance
Though, you’d expect that if you then feed it:
(format t "~{~[~:R~;~S~:;none~] chance~^, ~}" '(2 1 2 2 2 3))
Then you would get 3 times “none chance”, But the actual result is:
;; none chance, 2 chance, none chance, none chance, none chance
To be honest, I wrote this by mistake, I intended to do something else entirely. Was just puzzled by this behaviour.
Now, if I understand it correctly, the ~[~] directives depend on the number of arguments passed, on the other hand ~{~} may consume variable number of arguments. So, is the behaviour I’m seeing intended, or is it just some sort of “undefined” behaviour which happens when you randomly and / or deliberately put incompatible directives together?
From what I understand, this is correct.
~{~}consumes list until it is exhausted.~[~]consumes one argument as an index choosing alternative. For 0 and 1 you get another format directive, ~:R or ~S that consume extra item from the list. Hence, as a result, the list of arguments is consumed in pairs.However, for anything larger than 1 (because there’s colon here:
~:;) you get literal ‘none’ that does not consume extra argument. So in the last case the list is parsed like that:2 -> none chance
1 2 -> 2 chance
2 -> none chance
2 -> none chance
3 -> none chance