On May 24, 12:17 am,
ulr...@mips.complang.tuwien.ac.at (Ulrich
Neumerkel) wrote:
>
pico...@alice.it writes:
> >P.S.: I also would like to know why having a variable as functor is not accepted in ISO Prolog, where the
> >same can be accomplished via call/n or (=..)/2. If I remember correctly, it is currently possible to support this via
> >set_prolog_flag/2, but it would be nice to have that behavior in the standard. Any good reason against it?
>
> Please note that call/N and (=..)/2 do not accomplish the same!
> call/N permits to use some functor that gets further arguments
> (called a continuation) whereas (=..)/2 (alone) restricts
> the continuation to a fixed arity, most often zero.
>
> You find frequently:
>
> ... Goal =.., [F,A,B], Goal, ...
>
> which limits F to be an atom. Instead,
>
> ... call(F,A,B), ...
>
> offers the full generality. Like in:
>
> call(functor(F,c), 0).
> Succeeds, unifying F with c.
>
> call(call(call(atom_concat, pro), log), Atom).
> Succeeds, unifying Atom with prolog.
>
> Examples from 8.15.4.4,
http://www.complang.tuwien.ac.at/ulrich/iso-prolog/dtc2#call
>
> In any case call/N gives you the higher-order functionality necessary
> for higher-order programming. In (older) systems that support only
> call/1 but not call/2..call/8, it can be trivially added by adding
> rules for call/2 up to call/8 - thus showing that "there is no magic
> involved".
>
> Notations like F(A,B) open up a can of worms and magic that need to be
> defined. Like the precise translation of this construct. Must F be an
> atom? etc.
>
Native Unify can handle High Order programming
over a finite domain of pre-defined functors.
It just takes 1 line per definition or each functor.
Variable substitution to emulate lambda graph reduction is a bit like
using GOTO Statements. That Level of operability is handled (BY JMP
#FF00) already!
Same with PROLOG, you HAVE a variable binding system already (BOTH
WAYS - much more advanced than one way variable instantiation).
If you need a speed improvement just Flag
[ 1 way GOAL->HEAD binding only! ]
that will do CALL functions easily!
-----------------
The PROBLEMS you are trying to solve stem from 2nd Order Logic but it
is simply PARAMETER REFERENCING! i.e. white box inspection of
formulas.
2.O.L. is intended for writing AXIOMS not THEOREMS (the code..)
That's why AXIOMS tend to CHEAT a little with the Syntax!
2OL
for all predicates p...
A(X) A(i) phi(... X ...) phi2(... Xi... )
It changes from 1.O.L. parameter number indexing (count the commas) to
variable 'NAME' referencing. Most Logicians don't seem to notice
they are defining a simpler class of theorems than their definitions
in 2.O.L. themselves.
-------------------------------
This can all be avoided in Native Prolog though.
You define CLASSES of operands.
e.g. in SET THEORY the 1 class is 'e'.
nat(0).
nat(s(X)) :- nat(X).
even(0).
even(s(s(X))) :- even(X).
odd(s(0)).
odd(s(s(X))) :- odd(X).
Pardon the primitive level of primitive functors here!
Then you define the CLASS.
e( A , nats ) :- nat(A).
e( A , evens ) :- even(A).
e( A , odds ) :- odd(A).
SETS = Plural (Simple no?)
--------------
This is the STARGATE!
From here you can do Hi Level (set at a time)
programs using the CLASS of names.
?- intersect( nats , odds )
will search through 0, s(0)
and output YES!
USE:
intersect(S,T) :- e(A,S),e(A,t).
---------------
The Key here is, though you can't see it in this example
is the internal referencing of nat(X) and odd(X) as
to WHICH PARAMETER *POSITION* are we using when we
refer to ... functor odd().
That's all pre-specified!
In 2.O.L. Axioms have to Declare By Name the internal parameter
positions when they QUALIFY OVER ALL THEOREMS. e.g "P" in f(..P..)
===============
Now returning to my ARITHMETIC example.
instead of
?- X ( 1 , 2 , 3 )
use:
arith( add , A , B , C ) ) :- ...
arith( sub , A , B , C ) ) :- ...
arith( div , A , B , C ) ) :- ...
now you can call over a variable 'functor'.
?- arith( X , 1 , 2 , 3 )
X = add
------------------------
This doesn't look as *Expressive* as Lambda abstractions but it works
extremely well.
arith( add , A , B , C ) ) :- C is A + B.
arith( sub , A , B , C ) ) :- C is A - B.
arith( div , A , B , C ) ) :- C is A / B.
1 LINE DEFINITION for each function.
-----------------------------------
INTO A CLASS FUNCTOR
--------------------
If you need to REFERENCE a different parameter in 2.O.L.
then you add a new CLASS member for each parameter position needed.
********
The Process is actually a little more involved...
class( ARG , EXPRESSION ) :- functor(..,...,..., ARG , ... ).
where EXPRESSION is a string of functors you define.
*********
?- arith( X , 1 , 2 , 3 )
X = add
WHAT MAKES 3 FROM 1 & 2 ?
PROLOG> ADD!
Try doing that in C!
----------
Herc
--
www.BLOCKPROLOG.com
the debugging years...