There is this paper:
William E. Byrd, Eric Holk, Daniel P. Friedman, 2012
miniKanren, Live and Untagged
Quine Generation via Relational Interpreters
http://webyrd.net/quines/quines.pdf
Which uses logic programming to find a Scheme Quine. The Scheme subset that is consider here does not only contain lambda abstraction and application, but also a little list processing by the following reduction, already translated to Prolog:
[quote,X] ~~> X
[] ~~> []
[cons,X,Y] ~~> [A|B], for X ~~> A and Y ~~> B
So the only symbols are quote, [] and cons, besides lembda for lambda abstraction and bound variables. And we would use Prolog lists for the Scheme lists. The goal is to find a Scheme programm Q via Prolog, so that we get Q ~~> Q, i.e. evaluates to itself.
There is one complication, which makes the endeavour non-trival, [lembda,X,Y] doesn't evaluate syntactically to itself, but is rather supposed to return an environment closure. So the evaluator would be unlike the Plotkin evaluator here.
Any Prolog solutions around? Merry X-Mas
I'm using SWI Prolog with the occurs check turned on here (but
dif/2
skips the occurs check anyway):Tests:
Find Scheme expressions that eval to
(i love you)
-- this example has a history in miniKanren:In other words, the first 4 things it finds are:
It looks like the Scheme semantics are correct. The language-lawyer type of constraints it places are pretty neat. Indeed, real Scheme will refuse
but will accept
So how about quines?
miniKanren uses BFS, so maybe that's why it produces results here. With DFS, this could work (assuming there are no bugs):
or
but SWI doesn't necessarily limit the recursion with
call_with_depth_limit
.