Skip to content

prolog 'call' not working properly #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NHALX opened this issue Jul 5, 2018 · 7 comments
Closed

prolog 'call' not working properly #59

NHALX opened this issue Jul 5, 2018 · 7 comments

Comments

@NHALX
Copy link

NHALX commented Jul 5, 2018

Below is the output which fails under OS shen but works under PRO. The code generators for OS and Pro compile to the same code for 'test1'. I haven't looked closely at the code produced by test2, but they seem to be identical walls of text. Maybe lazyderef isn't working right?

Shen/OS

(4-)
(prolog? (test3 A B))
Z: (test1 Var2 Var3)
false

Shen/PRO

(4-) (prolog? (test3 A B))
Z: (test1 Var2 Var3)
testX->3: Var2
true

Code

(0-) (defprolog test1
  (mode 1 -) 2 <-- (prolog.trace "test1->2" 2);
  X 3          <-- (prolog.trace "testX->3" X);)
test1

(1-)
(defprolog test2
  A B [test1 A B] <--;)
test2

(2-)
(defprolog test3
  A B <-- (test2 A B Z)
          (prolog.trace "Z" Z)
          (call Z);)
test3

(3-) (defprolog prolog.trace
  Msg X <-- (when (do (output "~A: ~R~%" Msg X) true)); )
prolog.trace

@tizoc
Copy link
Member

tizoc commented Jul 7, 2018

Just tested this and #58 in an older Shen (19.2) to make sure that the bug was not introduced in newer versions (because some changes have been made to the prolog code since), but it was a bug back then too.

This, along with #58 and #56 make me thing that SP has made a bunch of changes to the prolog code.

The prolog part of Shen is probably what I'm least familiar with, I will see if I can figure out #59 and #58 which seem pretty specific, and then ask Mark about #56.

@tizoc
Copy link
Member

tizoc commented Jul 8, 2018

Ok, I was playing with this a bit, and something I noticed is that the generated code invokes call with the variable as is, without doing a deref on it, example:

(defun shen.f1296 (ProcN Cont)
  (let A (shen.newpv ProcN)
    (let B (shen.newpv ProcN)
      (let X (shen.newpv ProcN)
        (do (shen.incinfs)
          (bind X (cons test1 (cons 1 (cons (shen.deref A ProcN) (cons (shen.deref B ProcN) ()))))
                ProcN
                (freeze (call X ProcN Cont))))))))     \\ <---- here

but the definition of call looks like this:

(define call
  [F | X] ProcessN Continuation
  -> (call-help (function (lazyderef F ProcessN)) X ProcessN Continuation)
  _ _ _ -> false)

The generated code passes a prolog variable instead of something with the form [F | X], so the catch-all case gets it and returns false.

Can you tell me thats the generated code for this in SP?

(define something -> (prolog? (is X [test 1 A B]) (call X)))

I get this in the OS version:

(25-) (ps something)
[defun something [] [shen.f1296 [shen.start-new-prolog-process] [freeze true]]]

(26-) (ps shen.f1296)
[defun shen.f1296 [V1299 V1300] [let A [shen.newpv V1299] [let B [shen.newpv V1299] [let X [shen.newpv V1299] [do [shen.incinfs] [bind X [cons test [cons 1 [cons [shen.deref A V1299] [cons [shen.deref B V1299] []]]]] V1299 [freeze [call X V1299 V1300]]]]]]]]

@NHALX
Copy link
Author

NHALX commented Jul 8, 2018

Shen, copyright (C) 2010-2015 Mark Tarver
www.shenlanguage.org, 18
running under Common Lisp, implementation: SBCL
port 2.1 ported by Mark Tarver
commercially licensed to Neal Alexander



(0-) (define something -> (prolog? (is X [test 1 A B]) (call X)))
something

(1-) (ps something)

[defun something [] 
  [let NPP [shen.start-new-prolog-process] 
     [let A [shen.newpv NPP] 
        [let B [shen.newpv NPP] 
           [let X [shen.newpv NPP] 
              [bind X [cons test 
                            [cons 1 [cons [shen.deref A NPP] 
                                          [cons [shen.deref B NPP] []]]]] 
                    NPP 
                    [freeze 
                     [call X NPP 
                           [freeze true]]]]]]]]]

It's basically the same minus the extra function def. Maybe the implementation of call does the dereference in SP.

@tizoc
Copy link
Member

tizoc commented Jul 8, 2018

Yes, thats what I was guessing, but wanted to be sure, thank you.

@tizoc
Copy link
Member

tizoc commented Jul 8, 2018

Ok, it works with a modified call function:

Shen, copyright (C) 2010-2015 Mark Tarver
www.shenlanguage.org, Shen 21
running under Scheme, implementation: chez-scheme
port 0.17 ported by Bruno Deferrari


(0-) (defprolog test1
  (mode 1 -) 2 <-- (prolog.trace "test1->2" 2);
  X 3          <-- (prolog.trace "testX->3" X);)
test1

(1-) (defprolog test2
  A B [test1 A B] <--;)
test2

(2-) 
(defprolog test3
  A B <-- (test2 A B Z)
          (prolog.trace "Z" Z)
          (call Z);)
test3

(3-) 
(defprolog prolog.trace
  Msg X <-- (when (do (output "~A: ~R~%" Msg X) true)); )
prolog.trace

(4-) (prolog? (test3 A B))
Z: (test1 Var2 Var3)
testX->3: Var2
true

@NHALX
Copy link
Author

NHALX commented Jul 8, 2018

Nice job, thanks.

@rkoeninger
Copy link
Member

Fixed by #60

@tizoc if you use the exact phrasing Fixes #XXX in the body of your PR description (not the title, the first comment), GitHub will automatically close the issue when you merge the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants