view functional.rhope @ 189:d0e3a13c1bd9 default tip

Remove old calculator example
author Mike Pavone <pavone@retrodev.com>
date Fri, 07 Oct 2011 00:24:04 -0700
parents f4fc0a98088a
children
line wrap: on
line source


_Fold[list,index,current,worker:out]
{
	newval <- [worker]Call[current, [list]Index[index], index]
	
	[list]Next[index]
	{
		out <- _Fold[list, ~, newval, worker]
	}{
		out <- Val[newval]
	}
}

Fold[worker,start,list:out]
{
	[list]First
	{
		out <- _Fold[list, ~, start, worker]
	}{
		out <- start
	}
}

_Map[list,worker,cur:out]
{
	val <- [list]Index[cur]
	nlist <- [list]Set[cur, [worker]Call[val, cur]]

	[nlist]Next[cur]
	{
		out <- _Map[nlist, worker, ~]
	}{
		out <- Val[nlist]
	}
}

Map[list,worker:out]
{
	[list]First
	{
		out <- _Map[list,worker,~]
	}{
		out <- list
	}
}

_Find[list,pred,cur:loc,not found]
{
	val <- [list]Index[cur]
	If[[pred]Call[val,cur]]
	{
		loc <- cur
	}{
		,not found <- [list]Next[cur]
		{ loc,not found <- _Find[list,pred,~] }
	}
}

Find[list,pred:loc,not found]
{
	,not found <- [list]First
	{
		loc,not found <- _Find[list,pred,~]
	}
}

_Filter[list,pred,cur,dest:out]
{
	val <- [list]Index[cur]
	If[[pred]Call[val,cur]]
	{
		ndest <- [dest]Append[val]
	}{
		ndest <- dest
	}
	[list]Next[cur]
	{
		out <- _Filter[list,pred,~,ndest]
	}{
		out <- Val[ndest]
	}
}

Filter[list,pred:out]
{
	[list]First
	{
		out <- _Filter[list,pred,~, List[]]
	}{
		out <- list
	}
}

_Zip[left,lindex,right,rindex,outlist:out]
{
	nlist <- [outlist]Append[
		[[()]Append[ [left]Index[lindex] ]]Append[ [right]Index[rindex] ]
	]
	nlindex <- [left]Next[lindex]
	{
		[right]Next[rindex]
		{
			out <- _Zip[left,nlindex,right,~,nlist]
		}{
			out <- Val[nlist]
		}
	}{
		out <- Val[nlist]
	}
}

Zip[left,right:out]
{
	lindex <- [left]First
	{
		[right]First
		{
			out <- _Zip[left,lindex,right,~,()]
		}{
			out <- ()
		}
	}{
		out <- ()
	}
}