SIMPLE UNIFY( string1 string2 )
From
Graham Cooper@grahamcooper7@gmail.com to
comp.lang.prolog on Wed May 3 01:49:31 2023
From Newsgroup: comp.lang.prolog
www.miniPROLOG.com
function top($list)
{
$list = $list . "\n";
$cr = strpos( $list , "\n" );
$top = substr( $list , 0 , $cr );
return trim($top);
}
function rest($list)
{
if ($list[strlen($list)-1] != "\n") { $list = $list . "\n"; }
$cr = strpos( $list , "\n" );
$rest = substr( $list , $cr+1 );
return $rest;
}
function first($string)
{
if ($string[strlen($string)-1] != " ") { $string = $string . " "; }
$space = strpos( $string , ' ' );
$first = substr($string , 0 , $space);
return trim($first);
}
function remainder($string)
{
if ($string[strlen($string)-1] != " ") { $string = $string . " "; }
$space = strpos( $string , ' ' );
$remainder = substr( $string , $space+1 );
return $remainder;
}
function unifytolist($goal1)
{
global $dat;
$list = $dat;
$eol = false;
$found = false;
while (!$found & !$eol )
{
$toplist = top($list);
echo "<br>" . $toplist . "<br>";
$found = unify( $goal1 , $toplist );
if (!$found)
{
$list = rest($list);
if ($list == '') { $eol = true; }
}
}
return $found;
}
function unify( $string1 , $string2 )
{
$match = true;
$eol = $false;
while ($match & !$eol)
{
$first1 = first($string1);
$first2 = first($string2);
echo $first1 . '-' . $first2 . " ";
if ($first1==$first2)
{
$string1 = remainder($string1);
$string2 = remainder($string2);
if ( ($string1=='') | ($string2=='') ) { $eol=true; }
}
else
{
$match = false;
}
}
return $eol;
}
--- Synchronet 3.20a-Linux NewsLink 1.114