vmtest.scm 836 Bytes
Newer Older
Stefan Israelsson Tampe's avatar
Stefan Israelsson Tampe committed
1 2 3
(use-modules (logic guile-log iso-prolog))
(use-modules (logic guile-log guile-prolog ops))
(use-modules (logic guile-log guile-prolog vm-compiler))
4

5
#;
6
(define-prolog f1 "
7
   f1(N,I,J,S) :- 
Stefan Israelsson Tampe's avatar
Stefan Israelsson Tampe committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
      I < N -> 
        (
          II is I + 1, 
          JJ is J + I, 
          f1(N,II,JJ,S)
        ) ; 
      S=J
  ")

(define-prolog f2 "
   f2(N,S) :-
     recur * lp((I,0),(J,0)),
       (
         I < N ->
           (
             II is I + 1,
             JJ is J + I,
             lp(II,JJ)
           ) ;
         S=J
       ).
")

31
#;
Stefan Israelsson Tampe's avatar
Stefan Israelsson Tampe committed
32 33 34 35 36 37 38 39 40 41 42
(compile-prolog-string "
 f3(N,I,J,S) :-
    I < N -> 
      (
        II is I + 1, 
        JJ is J + I, 
        f3(N,II,JJ,S)
      ) ; 
    S=J
")

43
#;
Stefan Israelsson Tampe's avatar
Stefan Israelsson Tampe committed
44 45 46 47 48 49 50 51 52 53
(define-prolog memb "
   memb(X,L) :-
     recur * lp((LL,L)),
        LL=[A|B],
        (
          A=X;
          lp(B)
        ).
")

54