Reputation: 1
For my SWI-Prolog Class, I continuously get the following error with these snippets. Is this a problem with my ProLog instance? I immensely appreciate any help.
wordsn/2 to returns first words of the text. It should take two arguments: and the returned text.
%%CONSULT
%Your code here
wordsnopunc(Wordsa) :-
File = 'alice.txt',
open(File, read, Stream),
string_to_list(InputString, CharList), % Convert string to list of characters
replace_punctuation(CharList, ResultCharList), % Replace punctuation with spaces
string_to_list(ProcessedString, ResultCharList), % Convert back to string
split_string(ProcessedString, " ", "", Words). % Split into words by spaces
close(Stream).
Prolog: Warning: /tmp/tmpvqkpw9ac.pl:2:
Prolog: Warning: Singleton variables: [Stream,InputString]
Prolog: Warning: /tmp/tmpvqkpw9ac.pl:2:
Prolog: Warning: Redefined static procedure wordsnopunc/1
Prolog: Warning: Previously defined at /tmp/tmp_fd7iu9n.pl:2
Prolog: Warning: /tmp/tmpvqkpw9ac.pl:9:
Prolog: Warning: Singleton variables: [Stream]
Prolog: ERROR: /tmp/tmpvqkpw9ac.pl:9:
Prolog: ERROR: No permission to modify static procedure `close/1'
wordsn(
5,
["The", "Project", "Gutenberg", "eBook", "of"]
).
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/swi_prolog_kernel/kernel.py", line 140, in do_execute
self._execute(code)
File "/usr/local/lib/python3.8/dist-packages/swi_prolog_kernel/kernel.py", line 100, in _execute
result = self._thread.query(code)
File "/usr/local/lib/python3.8/dist-packages/swiplserver/prologmqi.py", line 682, in query
return self._return_prolog_response()
File "/usr/local/lib/python3.8/dist-packages/swiplserver/prologmqi.py", line 829, in _return_prolog_response
raise PrologError(jsonResult)
swiplserver.prologmqi.PrologError: existence_error(procedure, '/'(wordsn, 2))
Function listmatch/3 that counts how many words in a list match some pattern. The list is the first argument, the pattern is the second, and the result is the third.
%%CONSULT
%Your code here
listmatch([], _, 0) :- !.
listmatch([H|T], Pattern, Count) :-
H = Pattern, !,
listmatch(T, Pattern, TailCount),
Count is TailCount + 1.
listmatch([_|T], Pattern, Count) :-
listmatch(T, Pattern, Count).
Prolog: Warning: /tmp/tmpfhvjompl.pl:2:
Prolog: Warning: Redefined static procedure listmatch/3
Prolog: Warning: Previously defined at /tmp/tmpa23dptf_.pl:4
wordsn(30,Ws), listmatch(Ws,"a|b",9).
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/swi_prolog_kernel/kernel.py", line 140, in do_execute
self._execute(code)
File "/usr/local/lib/python3.8/dist-packages/swi_prolog_kernel/kernel.py", line 100, in _execute
result = self._thread.query(code)
File "/usr/local/lib/python3.8/dist-packages/swiplserver/prologmqi.py", line 682, in query
return self._return_prolog_response()
File "/usr/local/lib/python3.8/dist-packages/swiplserver/prologmqi.py", line 829, in _return_prolog_response
raise PrologError(jsonResult)
swiplserver.prologmqi.PrologError: existence_error(procedure, '/'(wordsn, 2))
Upvotes: 0
Views: 41