![visual prolog 5.2 visual prolog 5.2](http://docplayer.net/docs-images/59/43726054/images/34-0.png)
Code for TASM 5 Assembler, command-line call for compilation: OK, so here is the Assembly language code: = _apply_func.asm = %This program should produce " result = 60" (sum of ). % converts a predicate to a doubleword/addressįunc2dword(FUNC,DW):- DW = cast(dword,FUNC). % where arg-1 is a predicate-domain, such as "dom_iii"Īfter you compile the Assembly language code, you could create a simple “EasyWin” Visual Prolog project, with the following ines: PREDICATES
![visual prolog 5.2 visual prolog 5.2](http://1.bp.blogspot.com/-ZZsttR6K_QE/Tl61j0l1RsI/AAAAAAAAAF4/Av5za-yDkM0/s1600/visual_prolog.png)
(i,i,i) language c % <- example domain GLOBAL PREDICATESĪpply_func(DWORD,ListDomain) -(i,i) language c However, before you (even begin to) look at the Assembly Language Code, the following simple definitions in Visual Prolog (5.*) are a prerequisite for easier understanding: GLOBAL DOMAINSĭom_iii = determ INTEGER (INTEGER,INTEGER,INTEGER) If you understand Assembly Language and intend to use this code for other (meta-programming) tasks, all you have to do is modify just a couple of lines in the code that follows. The only difference between the way it works for Visual Prolog and the way it might work for another Prolog (or -indeed- ANY programming language, using a ‘C’-calling convention) is the Visual-Prolog-specific structure of a LIST, which in Visual Prolog has a different form than in all other languages. However, this does not exist in Visual Prolog, which sacrifices such “luxuries” for speed (which is the reason I also often use ISO-Prolog compilers, such as LPA-WinProlog and SWI-Prolog).Īnyway… The code you are about to see can be useful more generally, as an example of Prolog meta-programming, implemented in Assembly Language. Now, in ISO-Prolog there is a standard predicate known as “univ”, written as “ =.“, which turns a list like into a predicate call such as PRED(ARG1,ARG2,…).
![visual prolog 5.2 visual prolog 5.2](https://image2.slideserve.com/4653898/visual-prolog-s-basic-program-sections-l.jpg)
here is an Assembly language predicate, that takes as inputs another (external) predicate’s memory-address and a ( Visual Prolog-) argument-list, and calls this (external) predicate, using the (arbitrary-length-) list of N arguments, as arguments of “arity N”:Īpply_func(PRED, ) PRED(Arg1,Arg2,…) They also have an intrinsic fascination in themselves, as general tools for Prolog meta-programming.Į.g. Prolog even further, potentially valuable for a multitude of other purposes. Recently, I discovered some Assembly language techniques to enhance G.I.S. Code modifications could therefore be done very quickly and most mistakes were (semi-)automatically corrected by the interpreter’s own enhanced error-checking capabilities. Prolog produced immediate results, without any need for (often tedious) EXE-file compilation. Prolog for easy immediate experimentation: Coding in G.I.S. A multitude of extra predicates, implemented in pure Assembly language, became available through G.I.S. So, the only way to implement ISO-Prolog functionality in Visual Prologis to extend the “ PIE Interpreter” (and G.I.S. Of course, such attempts are inherently limited by the internal design of Visual Prolog compilers. In Visual Prolog, it is normal to use the functional syntax for relations and choice points are created in the normal way - for example, the goal X = (std::fromTo(1,10))*10 succeeds with bindings X=10, X=20, X=30, X=40, etc.Ever since I started using the Visual Prolog compilers (and the PDC Prolog compilers preceding them) I was fascinated by the possibilities of implementing additional ISO-Prolog functionality in Visual Prologthrough Assembly Language and ‘C’. In the first example, we prevent this using cuts. Note that the <- operator and the functional-style predicate above still behave as relations - it is legal for them to have choice points and perform multiple unification. Multimangle(X,Y) :- Y = mangle(mangle(mangle(X))). For example, in Visual Prolog: mangle(X) = Y :- Y = ((X*5)+2). However, some modern Prologs go further and offer a custom syntax for this type of predicate. We can now write: multimangle(X,Y) :- X <- mangle(mangle(mangle(Y))). % If it's not a compound, just use is directly , % Rebuild a compound with the evaluated arguments R2 <- X2, % Recurse to evaluate the argumentsĮxpr =. % To make the new operator compatible with is.Ĭompound(X), % If the input is a compound/function % Define our function in terms of the infix operator - note the cut to avoid In most Prologs, it is possible to avoid this by writing an alternate infix operator to use in place of is which expands expressions including the alternative function.
![visual prolog 5.2 visual prolog 5.2](https://thumbs.slideserve.com/1_4653898.jpg)
multimangle(X,Y) :- mangle(X,A), mangle(A,B), mangle(B,Y). This can create the difficulty that if a function-style predicate is called multiple times, it is necessary to "daisy chain" temporary variables. Traditionally in Prolog, "functions" (with one output and bound inputs) were written as regular predicates: mangle(X,Y) :- Y is (X*5)+2.