|
Re: prolog like operation in erlang ?: msg#00368lang.erlang.general
HP Wei <hp@xxxxxxxxxx> writes: > Suppose I define a relation through the following function: > > rel(x1, m1, m2) -> true; > rel(x2, m1, m2) -> true; > rel(x3, m3, m6) -> true; > .... > > In prolog, if I am not mistaken, > something like rel(X, m1, m2) can give me X = [x1, x2]. It has been a long time since I wrote Prolog but to get a result like this in Prolog you have to use something like findall/setof/bagof. > In erlang, how do I in general get the corresponding X ?? > Or should I encode the relation in a structure in this case ? Erlang being functional you can't get a result like that without splitting up the relation to functions with the mappings you want to use. You may be able to simulate what you want using an ets table, something like test() -> T = ets:new(foo,[duplicate_bag]), ets:insert(T, {x1, m1, m2}), ets:insert(T, {x2, m1, m2}), ets:insert(T, {x3, m3, m6}), X = ets:select(T, [{{'$1',m1, m2},[],['$1']}]). but the order of the result will be undefined, kent (did I just write my first match specification? ;-) |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | prolog like operation in erlang ?: 00368, HP Wei |
|---|---|
| Next by Date: | Re: testing codes in erl with running processes: 00368, Matthias Lang |
| Previous by Thread: | prolog like operation in erlang ?i: 00368, HP Wei |
| Next by Thread: | Announce ERES (Re: prolog like operation in erlang ?): 00368, Corrado Santoro |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |