(Prolog + LISP + Erlang) with integration issues versus C++

snickl@REDACTED snickl@REDACTED
Thu Aug 25 11:49:00 CEST 2005


On Thu, 25 Aug 2005, Dev Functional wrote:

> Alternatively, is it possible to implement goal seek, AI applications
> in Erlang ?
> That way we get rid of gprolog and clisp. So, it is then a single
> language solution.
 
Sure it is, you just won't have the language do it for you like
prolog does :)

I don't remember what the attached example does, but it translated
into definitly less erlang-code than it was in LISP ...

CU, SN

-- 
I have a BDI2000 and I'm not afraid to use it
                           -- Pantelis Antoniou
-------------- next part --------------
-module(depthpack).
-export([start/0, visit/1]).

start() ->
	visit({{lfr, 70}, [{50, 2}, {25, 3}, {15, 1}, {5, 2}, {2, 1}]}).

visit([]) -> [];
visit([Node|T]) ->
	visit(Node),
	visit(T);
visit(Node) ->
	{ {lfr, Lfr}, _ } = Node,
	if
		Lfr == 0 ->
			io:format("~n *** Found solution: ~w ***~n", [Node]),
			exit(solved);
		true ->
			Active = new_nodes(Node),
			visit(Active)
	end.

% Generates the new Nodes next to Node
new_nodes(Node) ->
	new_nodes([], Node, 1).

new_nodes(Active, _, 5 +1 ) ->
	Active;
new_nodes(Active, Node, I) when integer(I), I > 0 ->
	{ {lfr, Lfr}, Items } = Node,
	{L, N} = lists:nth(I, Items),
	NNode = if
		Lfr >= L , N > 0 ->
			{ {lfr, Lfr-L}, 
				lists:keyreplace(L, 1, Items, {L, N-1})};
		true ->
			[]	
	end,
	new_nodes(Active ++ [NNode], Node, I + 1).
	


More information about the erlang-questions mailing list