PHP code example of mudge / php-microkanren

1. Go to this page and download the library: Download mudge/php-microkanren library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mudge / php-microkanren example snippets




use MicroKanren\Core as U;

$f = U\callFresh(function ($q) {
  return U\eq($q, 5);
});

echo $f(U\emptyState());
/* => (((#(0) . 5)) . 1) */

$c = cons(1, cons(2, cons(3, nil())));

$c = cons(1, cons(2, nil()));
car($c);
/* => 1 */

$c = cons(1, cons(2, nil()));
cdr($c);
/* => cons(2, nil()) */

$n = nil();
$n === nil();
/* => true */

isPair(cons(1, nil())); /* => true  */
isPair(4);              /* => false */
isPair(nil());          /* => false */

isNull(nil());          /* => true  */
isNull(cons(1, nil())); /* => false */

$list = alist(cons(1, 'a'), cons(2, 'b'));
$isEven = function ($x) { return $x % 2 === 0; };

assp($isEven, $list);
/* => cons(2, 'b') */

alist(1, 2, 3);
/* => cons(1, cons(2, cons(3, nil()))) */

length(alist(1, 2, 3));
/* => 3 */

$list = alist(1, 2, 3);
map(function ($x) { return $x + 1; }, $list);
/* => alist(2, 3, 4) */
javascript
{
    "hp-microkanren": "v0.1.0"
    }
}