PARLOG Question 
Author Message
 PARLOG Question

Hello Everybody !!

 I'm  a student of computer science, and will participate in a course about
logic programming in autum. I have to deliver a speech about the language
PARLOG (86). It is based on an article from G. A. Ringwood
'PARLOG86 AND THE DINNING LOGICANS' (ACM Jan/1988). It shows how PARLOG can
be used to solve concurrent programming paradigms, especially the problem of
the dinning philosophers. Most of the programs in this article work with
data-streams, realized by shared variables. There is one program, which
should merge two streams. But in my opinion it can't work within PARLOG86.
Here it is:

merge([Item|Stream1],Stream2,[Item,Outstream]) :-
    merge(Stream1,Stream2,Outstream).
merge(Stream1,[Item|Stream2],[Item,Outstream]) :-
        merge(Stream1,Stream2,Outstream).

I think it should be:

merge([Item|Stream1],Stream2,Outstream) :-
    Output = [Item,Output2],
    merge(Stream1,Stream2,Output2).
merge(Stream1,[Item|Stream2],Outstream) :-
    Output = [Item,Output2],
    merge(Stream1,Stream2,Output2).

Am I right? I really don't know, because as I have no access to a
PARLOG86-Interpreter, so I can't test it.
So I choose this way, to get some help.
If anybody knows the email-adress of G. A. Ringwood, please forward this
article to him/her.

Thank you very much in advance !

----------------------------------------------------
Richard Schmitt
Universitaet Erlangen, Germany


----------------------------------------------------



Sun, 26 Jan 1997 17:16:09 GMT  
 PARLOG Question

Asking for a corrected version of the following fragment

: merge([Item|Stream1],Stream2,[Item,Outstream]) :-
:     merge(Stream1,Stream2,Outstream).
: merge(Stream1,[Item|Stream2],[Item,Outstream]) :-
:         merge(Stream1,Stream2,Outstream).

and offered the following

: I think it should be:

: merge([Item|Stream1],Stream2,Outstream) :-
:     Output = [Item,Output2],
:     merge(Stream1,Stream2,Output2).
: merge(Stream1,[Item|Stream2],Outstream) :-
:     Output = [Item,Output2],
:     merge(Stream1,Stream2,Output2).

: Am I right? I really don't know, because as I have no access to a
: PARLOG86-Interpreter, so I can't test it.

Your version does not correct the problem in the original but adds
some other problems.

Here is a correct version:

merge([Item|Stream1],Stream2,OutStream) :-
    Outstream = [Item|Outstream1]
    merge(Stream1,Stream2,Outstream1).
merge(Stream1,[Item|Stream2],Outstream) :-
    Outstream = [Item|Outstream1]
    merge(Stream1,Stream2,Outstream1).

This assigns the output in the body and uses a `|' to ensure that the
remaining merge stream forms the *tail* of the output stream.

I believe that in PARLOG you can give a mode declaration for merge
along the lines of `merge(-, -, +)' indicating that the first and
second argments are input and the third output. In this case you do
not have to write the assignment in the body but can use a head
literal to define the output e.g.

merge([Item|Stream1],Stream2,[Item|OutStream]) :-
    merge(Stream1,Stream2,Outstream).
merge(Stream1,[Item|Stream2],[Item|Outstream]) :-
    merge(Stream1,Stream2,Outstream).

So the original program is wrong *but* only because it uses a `,' and
not a `|' in the third head argument.

Your version is wrong because i) it replicates the mistake with the
comma ii) you have introduced a mistake when moving the head argument
into a body assignment by changing the assigned variable name from
Outstream to Output - the head argument never gets assigned and the
body variable Output is assigned but not output as a solution.

Andrew Dinn
-----------
there is no map / and a compass / wouldn't help at all



Tue, 28 Jan 1997 18:59:12 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. PARLOG source code

2. free parlog compiler

3. Expose on PARLOG

4. JAM Parlog

5. Request information on PC PARLOG

6. Need Help In Concurrent Prolog / PARLOG

7. references to PARLOG ?

8. PARLOG

9. PARLOG??

10. Parlog++ and OO+LP again

11. Want Parlog++ info

12. Parlog++ and OO+LP

 

 
Powered by phpBB® Forum Software