Re: Functional syntax

Alan Baljeu <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>

 

>I don't think (but I might be wrong; too much in my head)
>that you didn't answer my question whether you could solve
>./2 being expanded into functional notation in your DSL by
>term/goal expanding it into something else than a ./2
>term.  ./2 expansion happens after all user and other
>system expansion, just before the stuff is compiled into
>VM codes.

I don't remember the question.  To answer, I'm not sure 
how: In calling read/2 on my DSL, I want to apply 
term_expansion to replace my ./2 with something else.  But then how
do I make this NOT happen when program files are loaded?  Also 
I suppose all tests would have to be written with the alternate 
syntax because using . syntax will run into the map system.

>    forall(d(D), writeln(D.x)).
>
>which should compile into
>
>    forall(d(D), (.(D,x,X), writeln(X))).
>
>Worse are things annotated as e.g., 1.  What does this
>mean?  At the moment it is reported as an error.
>
>    maplist(f(D.x), List)
I put some thought into this.  I believe this is the most 
sensible answer:

Meta-calls must be declared for predicates like forall and maplist.
Then the compiler must operate like this:

D.E becomes ".(D, E, X)" and X.  D.E is textually replaced 
by X.  Then you must decide where to put ".(D,E,X)".  Recursively 
up the term structure: If the current term is a meta argument, insert
.(D,E,X) there.  If it is not, keep going up.

Examples:
forall(d(D), writeln(D.x)).  becomes forall(d(D), (.(D,x,X), writeln(X))).

maplist(f(D.x), List) becomes maplist(lambda(Y)\(.(D,x,X), f(X,Y)), List)

[or  maplist('gensymP'(D,x), List). 
 Where 'gensymP'(A,B,Y) :-  .(A,B,X), f(X, Y) ]


You will notice this mapping causes D.x to be evaluated 
N times, but users should expect this and if they care 
rewrite to E = D.x, maplist(f(E), List).

Aside: What's the proper declaration for this:
call_list([]).
call_list([A|B]) :- call(A), call_list(B).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.