Comment by taeric
21 hours ago
That example for "some permutation" is not at all easy for me to understand. I'm assuming I'm just not familiar with the general style?
21 hours ago
That example for "some permutation" is not at all easy for me to understand. I'm assuming I'm just not familiar with the general style?
I'm unfamiliar as well, but my best guess is that it relies on non-determinism. i.e. both definitions of 'insert' might be valid, and the runtime chooses which to use at random, resulting in either x or y being prepended to the returned list.
it's not random. it tries definitions in declaration order until one succeeds. it's then yielded as an assignment of variables and control returns to the caller. if that assignment gets contradicted it will backtrack and try the second definition, so on and so forth. it's more like coroutining.
Does this definition somehow cause all random permutations of a given list? The definition of "Some Permutation" seems to imply it can be used any place you need to try any/all permutations, one at a time? At the least, repeated calls to this would be different permutations?
4 replies →