Closed vsbogd closed 1 month ago
@ngeiswei could you please check if it what you needed?
Works like a charm, thanks!
Unfortunately I spoke too fast :-(, it does not work in my case, but it is a complex one, I want to simplify it a bunch before pasting it here. But to give you an idea, the following
!(unique (bc &kb
(fromNumber 5)
(: $prg (-> (: $x (SongIn "English")) (SongIn "Chinese")))))
does not work, while the following
!(let* (($results (collapse
(bc &kb
(fromNumber 5)
(: $prg (-> (: $x (SongIn "English")) (SongIn "Chinese"))))))
($uniq-results (unique (superpose $results))))
$uniq-results)
does. Meaning that I need to explicitly collapse the results, then call unique
on their superposition, and then it works.
I am not sure if it is a bug or a feature, I can still use that, but of course it is not as elegant as just calling unique
on my non-deterministic function call.
Please find a simplified example
(= (f) a)
(= (f) a)
!(unique (f))
!(let $y (collapse (f)) (unique (superpose $y)))
Thanks @ngeiswei. Seems like it is a bug which prevented me to implement it last time. unique
is implemented in stdlib and thus when collapse
is called from implementation it uses stdlib
space as a context. As consequence (f)
is not evaluated and stays (f)
because stdlib doesn't have definition of (f)
. It is the reason why unique
returns (f)
and after collapse it is evaluated in two instances of a
.
This is better than nothing, I can still use it by collapsing and superposing, so I approve merging if that's the best we can get for now.
Well, I think we can merge it, because it is better then previous state. Then I will think how to fix it properly and raise another PR.
Btw, @ngeiswei , the following code works:
(= (f) a)
(= (f) a)
!(unique (capture (f)))
Fixes #760 Also removes interpreter from the functions implementations.