PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 18, 2022

[FIXED] How to print this in one line statement in Prolog

 September 18, 2022     printing, prolog, swi-prolog     No comments   

Issue

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.

Solution

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]).


Answered By - slago
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing