2

In prolog I have do to something like this:

    ************************
    *                      *
    *      ##########      *
    *      # button #      *
    *      ##########      *
    *                      *
    ************************

User gives the width and height of window (created with *), and coordinates, width, height and text of button (created by #). This "window" is written in prolog console. I don't have trouble with writing the window itself but I don't know how to do it with something in it. Can anyone help me, I don't mean writing it for me, but even small guidenes will be helpfull.

false
  • 10,264
  • 13
  • 101
  • 209
lukasz128
  • 45
  • 4

2 Answers2

1

Write it with the help of a DCG as a clean grammar.

Here is a start. More details, here.

:- use_module(library(double_quotes)).
:- set_prolog_flag(double_quotes,chars).

newline --> "\n".

pre --> "# ".

post --> " #".

button -->
   pre,
   "button",
   post.

Now you can query it on the toplevel:

?- phrase(button, Xs).
   Xs = "# button #".

And you can print it out directly:

?- phrase(button, Xs), atom_chars(A, Xs), write(A).
false
  • 10,264
  • 13
  • 101
  • 209
  • phrase and atom_chars seems promising but the thing you did with button is not so simple. I don't know the width of button, it not always will look like this # button # – lukasz128 Jan 15 '13 at 19:09
  • @lukasz128: This is a starting point only - as you demanded it – false Jan 15 '13 at 19:44
  • I know. But anyway I can't figure out how to do this. I'm trying to built a list for each line, but I've got no results. – lukasz128 Jan 15 '13 at 19:52
0

Look at format/2, which works like printf in C++

Anniepoo
  • 2,152
  • 17
  • 17