A FFI for evaluable functions

Liste des GroupesRevenir à cl prolog 
Sujet : A FFI for evaluable functions
De : janburse (at) *nospam* fastmail.fm (Mild Shock)
Groupes : comp.lang.prolog
Date : 09. Oct 2024, 23:14:49
Autres entêtes
Message-ID : <ve6v8n$7df2$1@solani.org>
References : 1 2
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.19
The implementation to allow native libraries to register
new evaluable functions is the same as how predicates
are consulted. Take these two files:
$ cat > foo.p
test :- hello.
$ cat > bar.p
hello :- write('hello'), nl.
If I consult foo.p before bar.p there is a forward reference.
But if I ultimately consult bar.p the forward reference is
resolved. How does a Prolog system do that?
$ target/release/scryer-prolog
?- ['foo.p'].
    true.
?- test.
    error(existence_error(procedure,hello/0),hello/0).
?- ['bar.p'].
    true.
?- test.
hello
    true.
Now enhance is/2, etc... so that it uses the same resultion
meachanism, but only for the evaluable function namespace,
and provide a FFI where one can register evaluable functions,
in the evaluable function namespace, eh voila you are done,
makeing your Prolog extensible. Allowing to register evaluable
functions like gdc/2, popcount/1, etc.. outside of the core.
Mild Shock schrieb:
The new multilingual strings are also an exercise in
Novacore. There were a few issues that needed novel
Prolog solutions, to make a Novacore solution.
 One problem was I didn't want to use library(format)
and format/3 to format multilingual strings when
generating error messages. This addresses more
 the later multilingual strings processing than the
multilingual strings store itself. So how resolve this
paradox? Here is my take, a mini format/3 boostraped
 from the Dogelog Player specific atom_split/3:
 % sys_inter_polate(+Stream, +Atom, +List)
sys_inter_polate(Stream, Template, Args) :-
    atom_split(Template, '~', [Head|Tail]),
    put_atom(Stream, Head),
    sys_zipper_output(Args, Tail, Stream).
 % sys_zipper_output(+List, +List, +Stream)
sys_zipper_output([Arg|Args], [Head|Tail], Stream) :-
    writeq(Stream, Arg),
    put_atom(Stream, Head),
    sys_zipper_output(Args, Tail, Stream).
sys_zipper_output([], [], _).
 It only understands format specifier '~', but is sufficient:
 /* German Text */
strings('syntax_error.singleton_var', de, 'Alleinstehende Variable(n) ~, anonyme Variable(n) (_) benutzen.').
 /* English and Fallback Text */
strings('syntax_error.singleton_var', '', 'Singleton variable(s) ~, use anonymous variable(s) (_).').
 LoL
 

Date Sujet#  Auteur
9 Oct 24 * A FFI for evaluable functions7Mild Shock
9 Oct 24 +* Name resolution is a blackbox (Re: A FFI for evaluable functions)5Mild Shock
9 Oct 24 i`* plonk in discourse (Was: The issue with free speech)4Mild Shock
14 Oct 24 i `* When do two Prolog terms marry? (Was: The issue with free speech)3Mild Shock
14 Oct 24 i  +- Re: When do two Prolog terms marry? (Was: The issue with free speech)1Mild Shock
15 Oct 24 i  `- native implementation of variant/2 can be fast (Was: When do two Prolog terms marry?)1Mild Shock
3 Nov 24 `- KISS principle pays off (Was: A FFI for evaluable functions)1Mild Shock

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal