开发者

Is Erlang a Constraint-Logic programming language?

Since Erlang i开发者_JAVA百科s based upon Prolog, does this mean that Erlang is a Constraint-Logic Language?

Does Erlang have Prolog's building blocks: Facts, Rules and Query


No.

Erlang's syntax is very similar to Prolog's, but the semantics are very different. An early version of Erlang was written using Prolog, but today's Erlang can no longer meaningfully be said to be "based on Prolog."

Erlang does not include backtracking or other features of Prolog regularly used for logic programming. You can of course implement Prolog atop other languages, and Erlang is an easier choice for this than some others. This can be seen in Robert Virding's "Erlog" project:

https://github.com/rvirding/erlog


Yes.

The first version of Erlang was not written in Prolog, it was written in one of the committed-choice logic programming languages. These languages dropped Prolog's backtracking hence the name "committed choice" meaning once a choice was made it was not possible to backtrack and try another. This was done in order to simplify making a form of logic programming concurrent. Another way of looking at it is that concurrent processes would apply constraints to variables, but being logic variables and hence not re-assignable these would be successive constraints not changes of value. The constraint might assign a partial value to a variable, containing another variable which would be assigned later. This is the underlying model of Erlang. Constraint logic programming has tended to be used for versions where the constraints could also include mathematical statements about possible ranges of variables with intended numerical values.

The syntax of Erlang shows its logic programming heritage, but it is important to understand it picked this up through the committed choice logic programming languages which picked it up from Prolog, not directly from Prolog. Although several committed choice logic programming languages were devised during the 1980s, they were unable to pull out of the shadow of Prolog, and were pulled down by their association with the failed Japanese Fifth Generation initiative, and also by competing teams of developers who bickered over minor differences so no standard was established.

Erlang's developers introduced a syntactic sugar which gave a more functional appearance to the code, and made the marketing decision to promote it as a functional rather than logic programming language, which enabled it not to be dragged down by the post fifth generation dismissal of logic programming.


In short, no it's not :) It doesn't have those building blocks. It's focus is on concurrency, parallel programming, distributed applications and fault-tolerance (while being a functional, strict, declarative language).


You may well use the list comprehension feature in Erlang as a way of implementing in a constraint programming style.

% Produce the tuple {1, 0}
%
constraint_test() -> [ {A, B} ||
  A <- lists:seq(0, 1),
  B <- lists:seq(0, 1),
  A > B].

You alternatively place generators of elements taken from lists (A <- lists:seq(0, 1)) and constraints (A > B).

I recently solved the problem linked below. And if you place the constraints correctly you will have the answer in an instant of a second.

http://www.geocaching.com/seek/cache_details.aspx?guid=a8605431-53b5-4c2c-97fb-d42ee299b167

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜