Flávio Jardim
Flávio Jardim

Reputation: 175

How to print this in one line statement in Prolog

How can i print this string in prolog in the best way:

predicate([], L, Id, L2):-
   length(L2, N),
   write('The length '),
   write(Id),
   write(' is '),
   write(N),
   write(' elements.'),
   nl.

Upvotes: 0

Views: 894

Answers (1)

slago
slago

Reputation: 5509

In SWI-Prolog, you can use the built-in predicate format/2:

predicate([], L, Id, L2):-
   length(L2, N),
   format('The length of ~w is ~w elements\n', [Id, N]).

Upvotes: 1

Related Questions