arthwang / vsc-prolog

A VS Code extension that provides language support for prolog
MIT License
97 stars 22 forks source link

source_sink `filename' does not exist- but in Terminal usable #44

Open Zweiviertelgott opened 5 years ago

Zweiviertelgott commented 5 years ago

Hey, first of all: I love this whole project! Thank you very much!

I'm studying IT in Germany and started a logic-programming-course with the desire to get Prolog to work in VSC for this. I am fairly new to VSC as to Prolog, so please bear with me. Now I encountered a couple of problems and one is the following:

I got this file "familie.pl" (copy at the end of this post) and I am supposed to consult it and work with it. I put my own file into the same folder and used

:- consult(familie). ( :- consult('familie.pl'). and :-[familie] do not seem to work at all, which is also confusing me)

and I can work with it in the terminal:

?- mutter_von(marie,X). X = hans ; X = helga.

But under problems I see X source_sink `familie' does not exist and ! Goal (directive) failed: user:consult(familie)

And If I try to use :- listing(mutter_von). in my own file, I get the problem-message X toplevel: procedure `mutter_von' does not exist (DWIM could not correct goal) ! Goal (directive) failed: user:listing(mutter_von)

I would be glad for any help and/or advice in any way or form! :)

% START OF FILE familie.pl :- dynamic mutter_von/2, vater_von/2. % ermoeglicht dynamische Veraenderung % :- multifile mutter_von/2, vater_von/2. % ermoeglicht verteilte Definition in mehreren Files

% mutter_von( Mutter , Kind ). % 'Mutter' und 'Kind' sind Argumentpositionen, % so dass 'Mutter' die Mutter von 'Kind' ist.

mutter_von( marie , hans ). mutter_von( marie , helga ). mutter_von( julia , otto ). mutter_von( barbara , klaus ). mutter_von( barbara , andrea ). mutter_von( charlotte , barbara ). mutter_von( charlotte , magdalena ).

% vater_von( Vater , Kind ). % 'Vater' und 'Kind' sind Argumentpositionen, % so dass 'Vater' die Vater von 'Kind' ist.

vater_von( otto , hans ). vater_von( otto , helga ). vater_von( gerd , otto ). vater_von( johannes , klaus ). vater_von( johannes , andrea). vater_von( walter , barbara ). vater_von( walter , magdalena ).

% END OF FILE familie.pl

arthwang commented 5 years ago

Vierachtelgott notifications@github.com 于2019年10月24日周四 下午5:36写道:

Hey, first of all: I love this whole project! Thank you very much!

I'm studying IT in Germany and started a logic-programming-course with the desire to get Prolog to work in VSC for this. I am fairly new to VSC as to Prolog, so please bear with me. Now I encountered a couple of problems and one is the following:

I got this file "familie.pl" (copy at the end of this post) and I am supposed to consult it and work with it. I put my own file into the same folder and used

:- consult(familie). ( :- consult('familie.pl'). and :-[familie] do not seem to work at all, which is also confusing me)

Where did you type “:- consult(familie)”? In familie.pl file? NEVER consult itself in a prolog file that will result in infinite loading!!!

and I can work with it in the terminal:

?- mutter_von(marie,X). X = hans ; X = helga.

But under problems I see X source_sink `familie' does not exist and ! Goal (directive) failed: user:consult(familie)

And If I try to use :- listing(mutter_von).

You have to put this line after “mutter_von/2” facts in the file familie.pl .

in my own file, I get the problem-message X toplevel: procedure `mutter_von' does not exist (DWIM could not correct goal) ! Goal (directive) failed: user:listing(mutter_von)

I would be glad for any help and/or advice in any way or form! :)

% START OF FILE familie.pl :- dynamic mutter_von/2, vater_von/2. % ermoeglicht dynamische Veraenderung % :- multifile mutter_von/2, vater_von/2. % ermoeglicht verteilte Definition in mehreren Files

% mutter_von( Mutter , Kind ). % 'Mutter' und 'Kind' sind Argumentpositionen, % so dass 'Mutter' die Mutter von 'Kind' ist.

mutter_von( marie , hans ). mutter_von( marie , helga ). mutter_von( julia , otto ). mutter_von( barbara , klaus ). mutter_von( barbara , andrea ). mutter_von( charlotte , barbara ). mutter_von( charlotte , magdalena ).

:- listing(mutter_von). % It works since mutter_von/2 has been loaded

% vater_von( Vater , Kind ). % 'Vater' und 'Kind' sind Argumentpositionen, % so dass 'Vater' die Vater von 'Kind' ist.

vater_von( otto , hans ). vater_von( otto , helga ). vater_von( gerd , otto ). vater_von( johannes , klaus ). vater_von( johannes , andrea). vater_von( walter , barbara ). vater_von( walter , magdalena ).

% END OF FILE familie.pl

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/arthwang/vsc-prolog/issues/44?email_source=notifications&email_token=AB6ZJMVUESB7LPQCOC53UBLQQFUBNA5CNFSM4JERNPI2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HUB3GNA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6ZJMWJXPH7ZQMRIRWVM4LQQFUBNANCNFSM4JERNPIQ .

Zweiviertelgott commented 5 years ago

Sorry, I should have been more precise! I have 2 files: The above shown "familie.pl" and my own "assignment_01.pl"

In my own file "assignment_01.pl" I wrote the line ":- consult(familie)." to be able to work with all the predicates from the familie.pl file. The idea was to not change anything in "familie.pl" directly, but only access it from the outside.

In the end I would like my own file "assignment_01.pl" to look something like this:

% START OF assignment_01.pl % :- consult(familie).

:- listing(mutter_von). %To get an overview of every "mutter_von"-relation

:- vater_von(Z, barbara). %To show the name of barbaras father

mutter_von(charlotte,Z):- %To show the grand-children of charlotte mutter_von(Z, Y), vater_von(Z, X).

% END OF assignment_01.pl %

Thank you for your time and your help!

arthwang commented 5 years ago

No problem if these 2 files locate in the same folder except that some ‘Singleton variables’ warnings.

Maybe what your assignment means likes this:

% START OF assignment_01.pl %
:- consult(familie).

:- listing(mutter_von). %To get an overview of every "mutter_von"-relation

father_of_barbara :-
  vater_von(Z, barbara),
  writeln('father of barbara':Z).

grandchild_of_charlotte(X) :-
  mutter_von(charlotte,Z),
  ( mutter_von(Z, X)
  ;
    vater_von(Z, X)
  ).

start :-
  father_of_barbara,
  findall(X, grandchild_of_charlotte(X), AllGChildren),
  writeln('all grand-children of charlotte':AllGChildren).

:- start.

% END OF assignment_01.pl %

The result on my MacBook Pro:

Welcome to SWI-Prolog (threaded, 64 bits, version 8.1.9)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- ['assignment_01.pl'].
:- dynamic mutter_von/2.

mutter_von(marie, hans).
mutter_von(marie, helga).
mutter_von(julia, otto).
mutter_von(barbara, klaus).
mutter_von(barbara, andrea).
mutter_von(charlotte, barbara).
mutter_von(charlotte, magdalena).

father of barbara:walter
all grand-children of charlotte:[klaus,andrea]
true.

?-

BTW, write me to rthrwang@gmail.com if you want to consult prolog rather than report VSC-Prolog issues.

Vierachtelgott notifications@github.com 于2019年10月25日周五 下午12:53写道:

Sorry, I should have been more precise! I have 2 files: The above shown "familie.pl" and my own "assignment_01.pl"

In my own file "assignment_01.pl" I wrote the line ":- consult(familie)." to be able to work with all the predicates from the familie.pl file. The idea was to not change anything in "familie.pl" directly, but only access it from the outside.

In the end I would like my own file "assignment_01.pl" to look something like this:

% START OF assignment_01.pl % :- consult(familie).

:- listing(mutter_von). %To get an overview of every "mutter_von"-relation

:- vater_von(Z, barbara). %To show the name of barbaras father

Z is singleton here.

mutter_von(charlotte,Z):- %To show the grand-children of charlotte mutter_von(Z, Y), vater_von(Z, X).

% END OF assignment_01.pl %

Thank you for your time and your help!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/arthwang/vsc-prolog/issues/44?email_source=notifications&email_token=AB6ZJMSAS25W2NZ7AMBXHMTQQJ3VLA5CNFSM4JERNPI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECHFT2Y#issuecomment-546200043, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6ZJMWEU3JQ3CVYK2QX2QDQQJ3VLANCNFSM4JERNPIQ .