Showing posts with label SWI-Prolog. Show all posts
Showing posts with label SWI-Prolog. Show all posts

Saturday, October 29, 2016

macOS Sierra: SWI-Prolog: Hello, World!

Command:

$ cat helloworld.swi


Result:

main :-
write('Hello, World!\n').


Command:

$ swipl


Result:

Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.2.3)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).


Command:

?- ['helloworld.swi'].


Result:

true.


Command:

?- main.


Result:

Hello, World!
true.

macOS Sierra: SWI-Prog: Trying Read-Eval-Print loop (REPL)

Command:

$ swipl


Result:

Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.2.3)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).


Command:

?- [user].

|: p(X) :- q(X).
|: q(a).
Ctrl-D

Result:

|: true.


Command:

?- p(a).


Result:

true.


Command:

?- listing.


Result:

:- dynamic expand_answer/2.
:- multifile expand_answer/2.

expand_answer(A, B) :-
toplevel_variables:expand_answer(A, B).

:- dynamic expand_query/4.
:- multifile expand_query/4.

expand_query(A, B, C, D) :-
toplevel_variables:expand_query(A, B, C, D).

:- multifile prolog_list_goal/1.


:- dynamic prolog_event_hook/1.
:- multifile prolog_event_hook/1.


:- dynamic exception/3.
:- multifile exception/3.


:- dynamic file_search_path/2.
:- multifile file_search_path/2.

file_search_path(library, A) :-
library_directory(A).
file_search_path(swi, A) :-
system:current_prolog_flag(home, A).
file_search_path(foreign, swi(B)) :-
    system:
    (   current_prolog_flag(arch, A),
atom_concat('lib/', A, B)
    ).
file_search_path(foreign, swi(A)) :-
    system:
    (   (   current_prolog_flag(windows, true)
->  A=bin
;   A=lib
)
    ).
file_search_path(path, C) :-
    system:
    (   getenv('PATH', A),
(   current_prolog_flag(windows, true)
->  atomic_list_concat(B, ;, A)
;   atomic_list_concat(B, :, A)
),
'$member'(C, B),
'$no-null-bytes'(C)
    ).
file_search_path(user_profile, app_preferences('.')).
file_search_path(app_data, A) :-
'$toplevel':catch(expand_file_name('~/lib/swipl', [A]), _, fail).
file_search_path(app_preferences, A) :-
'$toplevel':catch(expand_file_name(~, [A]), _, fail).
file_search_path(autoload, library('.')).
file_search_path(pack, app_data(pack)).
file_search_path(pack, swi(pack)).
file_search_path(library, A) :-
'$pack':pack_dir(_, prolog, A).
file_search_path(foreign, A) :-
'$pack':pack_dir(_, foreign, A).

:- thread_local thread_message_hook/3.
:- dynamic thread_message_hook/3.
:- volatile thread_message_hook/3.


:- dynamic portray/1.
:- multifile portray/1.


:- dynamic prolog_file_type/2.
:- multifile prolog_file_type/2.

prolog_file_type(pl, prolog).
prolog_file_type(prolog, prolog).
prolog_file_type(qlf, prolog).
prolog_file_type(qlf, qlf).
prolog_file_type(A, executable) :-
system:current_prolog_flag(shared_object_extension, A).

:- dynamic prolog_load_file/2.
:- multifile prolog_load_file/2.


:- multifile message_property/2.


:- dynamic library_directory/1.
:- multifile library_directory/1.

library_directory(B) :-
    '$parms':
    (   cached_library_directory(local, A=lib, A),
B=A
    ).
library_directory(B) :-
    '$parms':
    (   cached_library_directory(user,
expand_file_name('~/lib/prolog', [A]),
A),
B=A
    ).
library_directory(B) :-
    '$parms':
    (   cached_library_directory(system,
absolute_file_name(swi(library), A),
A),
B=A
    ).
library_directory(B) :-
    '$parms':
    (   cached_library_directory(clp,
absolute_file_name(swi('library/clp'), A),
A),
B=A
    ).

:- dynamic resource/3.
:- multifile resource/3.


:- dynamic message_hook/3.
:- multifile message_hook/3.

true.


macOS Sierra: Installing SWI-Prolog

Command:

$ brew install swi-prolog


Result:

==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core, homebrew/python).
==> Updated Formulae
flow                           homebrew/python/pyrit          sbt ✔

==> Downloading https://homebrew.bintray.com/bottles/swi-prolog-7.2.3_1.sierra.bottle.tar.g
######################################################################## 100.0%
==> Pouring swi-prolog-7.2.3_1.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/swi-prolog/7.2.3_1: 801 files, 17.6M