0

I am a novice in Prolog. Recently I saw a piece of code. I want to know the meaning of some parts of it and how to use it.

the code as below:

MatrixTconcat([]) --> [].
matrix_tconcat([Cs|Css]) -->
   row_rows_rest_(Cs,Css,Mss),
   matrix_tconcat(Mss).

first, what's the meaning of -->?

second, why MatrixTconcat starts with a capital letter while matrix_tconcatstarts with a lower one? what the difference between them?

here is another piece of code:

RowRowsRest([],Css,[]) -->
   { emptylists(Css) }.
row_rows_rest_([X|Xs],Xss,[Xs|Mss]) -->
   [X],
   nonemptyrows_rest(Xss,Mss).

what are { and } in prolog used for, and how to use it?

Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
Lin Jiayin
  • 499
  • 1
  • 6
  • 11
  • 5
    Please see the related question: [http://stackoverflow.com/questions/32579266/what-does-the-operator-in-prolog-do](http://stackoverflow.com/questions/32579266/what-does-the-operator-in-prolog-do). – mat Sep 26 '15 at 08:32
  • Copy/paste failure: start over with the original code, http://stackoverflow.com/a/32734744/4609915 – repeat Sep 26 '15 at 11:02

1 Answers1

0

MatrixTconcat seems wrong — predicate names should start with a lowercase, and in any case, all clauses of a predicate should have the same name:

matrix_tconcat([]) --> [].
matrix_tconcat([Cs|Css]) -->
   row_rows_rest_(Cs,Css,Mss),
   matrix_tconcat(Mss).

The curly brackets { and } in general are just an operator to construct terms, with the functor name being {}. The exact meaning depends on interpretation, or context. In this case, since the predicates are defined as Definite Clause Grammars, or DCG’s for short, the purpose of curly brackets is to embed non-DCG constraints in the body of a DCG rule.

row_rows_rest([],Css,[]) -->  % notice lowercase
   { emptylists(Css) }.  % emptylists is a normal, non-DCG predicate
row_rows_rest_([X|Xs],Xss,[Xs|Mss]) -->
   [X],
   nonemptyrows_rest(Xss,Mss).
Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111