For Programmers: Free Programming Magazines  


Home > Archive > Prolog > December 2006 > ediprolog -- Emacs does Interactive Prolog









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ediprolog -- Emacs does Interactive Prolog
Markus Triska

2006-11-30, 7:01 pm


Here are Emacs definitions that let you transparently interact with
SWI Prolog in all buffers. You can load and syntax-check Prolog
programs and execute queries with minimal exposure to the toplevel:

http://stud4.tuwien.ac.at/~e0225855.../ediprolog.html

A video with a simple query, a CLP and a CHR program:

http://stud4.tuwien.ac.at/~e0225855...g/ediprolog.mpg


The definitions are self-contained and orthogonal to other Prolog
editing modes. The central function is "ediprolog-dwim" (Do What I
Mean). Depending on the line at point, it either loads the current
buffer into Prolog (moving point to the first error, if there are
any), or executes the query and inserts its results in the buffer. I
first saw this idea in Ulrich Neumerkel's GUPU teaching environment.

The code is in the public domain. While it currently depends on SWI's
prompts and "-q" switch, I hope that authors of other systems also
find it useful, and that they can adapt it to provide even better
development and teaching environments. If you have more suggestions or
ideas regarding editing/development features, please let me know.

All the best,
Markus Triska
Richard Szopa

2006-12-02, 6:59 pm

Hello,

I took a look at your program and it seems like something that can make
prologing a lot more comfortable.

However, ediprolog hangs my Emacs in some situations (I'm using GNU
Emacs 22.0.50.1 (i486-pc-linux-gnu, GTK+ Version 2.10.3)).

For example, if I write in a buffer something like this:

?- reverse([1,2,3], X).
and press <f10>
it outputs
%@% X = [3, 2, 1]

and directly enters the debugger (as I understand, this isn't an
intended behavior).

On the other hand, if I input a predicate that doesn't exist, for
example
?- reveraaaaaaaaaaaaaaaaaaaaaaaaaaase([1,2,
3], X).
it says
%@% Error: Undefined procedure: reveraaaaaaaaaaaaaaaaaaaaaaaaaaase/2
gives the message `press h for help.', but now Emacs is hanged, at
least until I manually kill the Prolog process.

Finally, if I write
?- reverse([1,2,3], X).

and on some other line press <f10> two times, then emacs hangs, and
killing prolog doesn't help much. What is more, I figured out that
after I kill emacs with xkill, there are 3 more instances of emacs
which do something very CPU consuming that also need to be killed.
This, however, may be not connected directly with your code.

Best regards,

-- Richard Szopa

Markus Triska

2006-12-02, 6:59 pm

"Richard Szopa" <ryszard.szopa@gmail.com> writes:

> For example, if I write in a buffer something like this:
>
> ?- reverse([1,2,3], X).
> and press <f10>
> it outputs
> %@% X = [3, 2, 1]
>
> and directly enters the debugger (as I understand, this isn't an
> intended behavior).


That's indeed not intended -- F10 on

?- reverse([1,2,3], X).

gives:

?- reverse([1,2,3], X).
%@% X = [3, 2, 1]

You then interact as on a terminal. Pressing ";" gives:

?- reverse([1,2,3], X).
%@% X = [3, 2, 1] ;
%@% No more solutions.

Does this work for you? What did you do to enter debug mode?


> example
> ?- reveraaaaaaaaaaaaaaaaaaaaaaaaaaase([1,2,
3], X).
> it says
> %@% Error: Undefined procedure: reveraaaaaaaaaaaaaaaaaaaaaaaaaaase/2
> gives the message `press h for help.', but now Emacs is hanged, at
> least until I manually kill the Prolog process.


You can always get out of such hangs with Ctrl + g in Emacs. While a
restart of the Prolog process isn't necessary in this case (since SWI
is already on the toplevel again, see below), you can always terminate
the background process with Ctrl+0 F10 (numeric argument zero for F10)
and automatically get a new one with the next press of F10.

Reason for the hang: Such an error takes SWI back to the toplevel,
whereas ediprolog thinks the output is just the result of your query
and waits for key presses (like ";" and "a") that are then sent to SWI
and meaningless to it on the toplevel. I currently don't check for
"Error:" in query output since it's prone to false positives. If
anyone needs a more specialised version for teaching environments, I
will provide one.

> and on some other line press <f10> two times, then emacs hangs, and
> killing prolog doesn't help much. What is more, I figured out that


I could reproduce this and have made a change that fixes the problem
for me. Please try the latest version from

http://stud4.tuwien.ac.at/~e0225855.../ediprolog.html

Thank you for your feedback, and best wishes!
Markus Triska

Jan Wielemaker

2006-12-03, 4:18 am

On 2006-12-02, Markus Triska <triska@gmx.at> wrote:
> Reason for the hang: Such an error takes SWI back to the toplevel,
> whereas ediprolog thinks the output is just the result of your query
> and waits for key presses (like ";" and "a") that are then sent to SWI
> and meaningless to it on the toplevel. I currently don't check for
> "Error:" in query output since it's prone to false positives. If


You can redefine message printing using rules for prolog:message/3.
That way you can add a few characters to avoid most false positives.
You could also redefine the toplevel prompt, so you can tell it is
at the toplevel more reliable.

Cheers --- Jan
Markus Triska

2006-12-03, 8:01 am

Jan Wielemaker <jan@nospam.ct.xs4all.nl> writes:

> You can redefine message printing using rules for prolog:message/3.
> That way you can add a few characters to avoid most false positives.
> You could also redefine the toplevel prompt, so you can tell it is
> at the toplevel more reliable.


Thank you, a more robust ways is now installed. The

?- reveraaaaaaaaaaaaaaaaaaaaaaaaaaase([1,2,
3], X).

example should work with the latest version.

All the best, -- Markus.
Richard Szopa

2006-12-05, 7:00 pm



On Dec 2, 9:57 pm, Markus Triska <tri...@gmx.at> wrote:
> "Richard Szopa" <ryszard.sz...@gmail.com> writes:
>
>
[snip][color=darkred]
> Does this work for you? What did you do to enter debug mode?


Basically, that's my problem--I did nothing to enter debug mode. It
just happened. ;-)

This problem is still present in the new version. Here's my session
with ediprolog (my comments are in angle brackets).

test(X) :- X=1.
%?- test(X).
%@% X = 1 a <Here I had to press a to get out of the debugger.>
%@% Yes


test2 :- print('123').
% ?- test2.
%@% 123
%@% Yes % <No problem here>


% ?- reverse([1,2,3,4], X).
%@% X = [4, 3, 2, 1]l
%@% Unknown action: l (h for help) <Return didn't work>
%@% Action? l
%@% Unknown action: l (h for help)
%@% Action? s
%@% Unknown action: s (h for help)
%@% Action? a
%@% Yes <Here I also had to press a to get out of the debugger.>

% ?- reverse([1,2,3,4,5], X).
%@% X = [5,4, 3, 2, 1]; <I pressed `;' and everything worked fine>
%@% No

% ?- print(a).
%@% a
%@% Yes <No problem here>

test3(1).
% ?- test3(X).
%@% X = 1;
%@% No

% ?- test3(1).
%@% Yes <OK>

It seems that there's a problem when you give Prolog an uninstantiated
variable and it has to assign some value to it. If

The rest of the problems I mentioned in my last post seem to be gone.

Anyway, when I took a look at the source of ediprolog I felt ashamed of
the dumb way I use Emacs (C-x C-f, C-x C-k, C-c C-b, C-x b, C-x C-s),
an that was an impulse for trying to learn at least some Emacs Lisp.
Thank you! ;)

Best wishes,

-- Richard

Markus Triska

2006-12-05, 7:00 pm

"Richard Szopa" <ryszard.szopa@gmail.com> writes:

> test(1).
>
> %?- test(X).
> %@% X = 1


The system reports a binding for X, X = 1. Press "h" at this point to
to see a list of things you can do; briefly (format is "key: action"):

;: redo t: trace & redo
b: break c: continue
w: write p: print
h: help


Pressing ";" for more solutions (there are none in this case):

%@% X = 1 ; <--- press ";"
%@% No

That's the same toplevel (not debugger) interaction as on a terminal,
just embedded in the buffer. Another example (showing "w" and "p"):

%?- numlist(1, 12, Ns).
%@% Ns = [1, 2, 3, 4, 5, 6, 7, 8, 9|...] w <-- press "w"
%@% Ns = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] p <-- press "p"
%@% Ns = [1, 2, 3, 4, 5, 6, 7, 8, 9|...] ; <-- press ";"
%@% No <-- (no more)

You can also start the graphical tracer with F10 on a query like:

%?- gtrace, test(X).


> % ?- reverse([1,2,3,4], X).
> %@% X = [4, 3, 2, 1]l
> %@% Unknown action: l (h for help) <Return didn't work>


RET is currently problematic; use one of its synonyms "c", "a" or SPC.


Thank you for your testing and best wishes,
Markus Triska

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com