Skip / Skip Custom Prolog

I am developing under SWI-Prolog, but my goal is Erlog ​​( https://github.com/rvirding/erlog ). I need a way to use custom Prolog syntax. Is there a way to write a prologue that will be ignored by the SWI compiler, i.e. Make it invisible.

Here is an example of what it looks like:

do_stuff(G,Amt) :- ecall(erlog_demo:efunc('Elixir.Blah':stuff({G,Amt})).

I was wondering if there is a way for SWI to skip this, and I have another declaration that does nothing.

do_stuff(_,_).

One option is to comment it out and then use the parser to remove the comment before running it in Erlog, but that seems cumbersome.

Any other ideas.

======

is_dialect(swi) :- catch(current_prolog_flag(dialect, swi), _, fail).
:- if(is_dialect(swi)).
    do_stuff(_,_).
:- else.
   do_stuff(G,Amt) :- ecall(erlog_demo:efunc('Elixir.Blah':stuff({G,Amt})).
:- endif.

Syntax error: expected statement

+4
3

,

:- if(swi).

 gen_hash_lin_probe(Key, HashTable, Value) :-
    arg(_, HashTable, E),
    nonvar(E),
    E = Key-Value.

:- elif(yap).

 gen_hash_lin_probe(Key, HashTable, Value) :-
    HashTable =.. [htlp|Args],
    nth1(_, Args, E),
    nonvar(E),
    E = Key-Value.

:- endif.

swi/0 yap/0 (prolog_impl)

:- module(prolog_impl, [swi/0, yap/0, prolog_impl/1]).

swi :- prolog_impl(swi).
yap :- prolog_impl(yap).

prolog_impl(K) :-
    F =.. [K,_,_,_,_],
    current_prolog_flag(version_data, F).
+3

, , @Capelli answer .

. ...

  • .

    :- if(true).       p(3).
    :- elif(false).    p(4+3).
    :- endif. 
    
  • , "else" .
    ... ?

    :- if(true).       p(3).
    :- elif(false).    p (4);;[ p())
    :- endif.
    

    ! Upon (re-)loading, we get: ⚠ Syntax error: Operator expected

    TIL, elif endif . .

  • - , , , : "[...] Prolog [...], [...] make [...]"

    " " , ( ):

    :- op(500,xfx,=>).
    
    :- if(true).       p(2).
    :- elif(false).    p(3 => 3).
    :- endif.
    

    :

    :- if(true).       p(2).
    :- elif(false).    :- op(500,xfx,=>).   % is moving the `op/3` here ok?
                       p(3 => 3).
    :- endif.
    

    ! Upon (re-)loading, we get: ⚠ Unterminated conditional compilation from [...]


! , end_of_file, Prolog end_of_file.

:

% snip_at_end.pl
xxx1.

xxx2.

end_of_file.

xxx3.

:- op (500, xfx,eat).       % broken syntax (pt.1)
1 ]][[ v                    % broken syntax (pt.2)

SICStus Prolog:

$ sicstus
SICStus 4.3.2 (x86_64-linux-glibc2.12): Fri May  8 01:05:09 PDT 2015
[... License information ...]
| ?- compile(snip_at_end).
% compiling /home/stefan/prolog/snip_at_end.pl...
% compiled /home/stefan/prolog/snip_at_end.pl in module user, 40 msec 400672 bytes
yes
| ?- xxx1.
yes
| ?- xxx2.
yes
| ?- xxx3.
! Existence error in user:xxx3/0
! procedure user:xxx3/0 does not exist
! goal:  user:xxx3

, ! , :)

+3

"else" .

do_stuff(G,Amt) :- ecall(erlog_demo:efunc('Elixir.Blah':stuff({G,Amt})).  % BAD
do_stuff(G,Amt) :- ecall(erlog_demo:efunc('Elixir.Blah':stuff({G,Amt}))). % OK!

. . (, ), .

, !

+3

Source: https://habr.com/ru/post/1611116/


All Articles