Odd problem

Started by techdir0, August 04, 2011, 04:41:40 PM

Previous topic - Next topic

techdir0

Hi



I'm not sure how or where to ask this, so here goes.

I'm running 10.3.0 0n Windows XP.  I've converted a program (600 lines) from Common Lisp, and now I have a very odd problem.



The program is a network interpreter, and runs recursively: it works correctly BUT only if I debug through the entire program, hitting 's' several scores of times.    If I try to run the program directly from the REPL, it produces a different result entirely!   There is no error message produced in either case, and I cannot see how to cut down the code to either locate the problem, or post a proper question here.



Anyone got a suggestion?



What's the real difference from running in DEBUG?

cormullion

#1
Sounnds odd. Can you post some cut-down version that exhibits the problem.

techdir0

#2
Well, I would dearly like to, as this has me thoroughly confused.



But I cannot get the program down below 160 lines - which is probably too much to send up to the board?

cormullion

#3
Pastebin? Or is that just for hackorzzx? :)

techdir0

#4
I chopped out some more - just hope this does not upset the board (or you guys reading it).

In a file ODD.PL



(define-macro (iparse _sent)
   (setq parses nul)
   (setq stack nul)
   (setq jumpflag nil)
   (setq sentence _sent)
   (setq state 's)
   (setq star (first sentence))
   (atn state sentence)
   (and parses true ) )

(define (pushlex)            
   (push (list star sentence) *lexenvironment) )
 
(define (poplex)            
   (map set '(star sentence) (pop *lexenvironment)) )
   
(define (atn state sentence)
   (let (arcs result (savealist alist))
      (cond ((null? (setq arcs (first (rest (assoc state network)))))
                     nil ))
      (catch
      (while true
         (cond ((setq result (evalarc (first arcs) alist))
                (throw result))
               ((setq arcs (rest arcs)) (setq alist savealist))
               (true  (throw nil)))))))      
                     
 (define (evalarc arc alist)
     (let ((type (arc 0))        
          (head (arc 1))
          (test (arc 2))
          (actions (3 arc)))  
    (cond ((null? (eval test)) nil)
          ((= type 'pop)  (evall actions)
                          (popatn (eval head)))
          ((null? star) nil)
          ((= type 'wrd)  (and (= star head)
                               (evall actions)))
          (else (println "bad arc: " arc) nil) )))                                                                                                                  
               
(define (evall lis)
   (when lis
      (eval (cons 'begin lis)) ))      
   
(define-macro (to _state)
; effect transition to state _state.  
; advance input unless jumpflag is set
; fail if there are no more words in input  
   (cond (jumpflag  (setq jumpflag nil)
                    (pushlex)
                    (setq star (first sentence))
                    (cond ((atn _state sentence)   )  
                          (else (poplex)  nil) ))
         (sentence  (pushlex)
                    (setq star (first (rest sentence)))  ; could we not reverse/simplify these 2 lines?
                    (setq sentence (rest sentence))
                    (cond ((atn _state sentence)   )  
                          (else (poplex)  nil) ))
         (else      (println " blocked : out of words")
                    nil )))                

(define (popatn value)
; pops from a sub-network
    (cond  (stack    ;;; so from earlier push
                 (let ((save star)
                       (savestack stack)
                       (savealist alist)
                       (continuation (rest (first stack))) )
                 (setq alist (append liftlist (first (first stack))))      
                 (setq stack (rest stack))
                 (setq star value)
                 (setq sendlist nul)
                 (setq jumpflag true)
                 (cond ((evall continuation)    )
                       (else (setq star save)
                             (setq stack savestack)
                             (setq alist savealist)
                             nil ) )))
          (sentence (println "pop blocked - unused words")
                    nil)
          (holdlist (println  "pop blocked - non-empty hold list")
                    nil)  
          (else     ;;; final pop                                          
                 (setq parses (cons value parses))
                 true ) ))
   
(define (pushatn state actions)
   ;; STUB
   )
               
(setq network '(                             ;; GRAMMAR 0
   (s ( (wrd grasp true (to s2)) ))
   
   (s2 ( (pop 'success true (println 'OK)) ))
   
))      
       
(set 'dictionary '(                          ;; LEXICON 0
   (grasp  v  () (trans1) )
   (grasp  n  () (reach)  )
 ))  

(define (dict-entry _star _head)                    ; return entry if present, or nil
   (find-all (list _star _head '*) dictionary) )
;; Needs to be like this because we are finding more than one word  with
;; same value, but different category, so will be able to add semantics  

     
(setq nul '())
(constant 'else true)
(setq alist nul
     *lexenvironment nul)
     


I know the style/layout are rubbish - I'm still not very used to (new)Lisp ..



The problem can be seen if you:



(load "odd.pl")
(debug (iparse (grasp)))


the result - after hitting N or S a lot of times - is 'true'; which it should be.



But

(load "odd.pl")
(iparse (grasp))


produces an error.  I am quite ready to believe the error is my fault - but why does it work when I trace the program, trying to fix it???

cormullion

#5
deleted reply - was doing the wrong thing...

cormullion

#6
Is this line right?


(let (arcs result (savealist alist))

Lutz

#7
'debug' used on a function containing 'catch' will mask an error occurring inside a function called from inside 'catch', which then will return 'nil', even if 'catch' was used without an catching symbol.



Put a '(trace nil)' before the 'catch' statement and you will see the error while using the debugger.

techdir0

#8
Thanks both - I thought I was going mad!



I understand how the debugger handled things - and am/was ready to own up to the original error on my part.



I more often use 'local', so I guess I have left bits of the wrong syntax in the 'let' expression.



Thanks for the help.