0

I have the function getBoundedVars which uses the function boundsInLambda. In the end of it all the box bBox should contain all bounded variables in the expression exp. I'm trying to debug this function and in order to do so I want to print the parameters of boundsInLambda every time the function is being activated but for some reason the values won't show up on the screen. If I put the display operation in getBoundedVars it will print it but those are just the values in the first iteration.

If I run the following :

(getBoundedVars (lambda-simple (x) (lambda-simple (y) (const x))) bx)

when bx is an empty box,

'1 will be printed but the print commands in boundsInLambda will not

here's the code:

(define getBoundedVars 
(lambda (exp bBox)

    (if (atom? exp)
        0 ;; don't put in box
        (if (lambda? (car exp))
            (begin
                (display 1)
                (newline)
            (let ((pBox (make-pBox exp))
                  (lBox (box '()))
                  (bodyExp (make-body exp))
                 )

            (boundsInLambda bodyExp lBox pBox bBox)))
            (begin
                (getBoundedVars (car exp) bBox)
                (getBoundedVars (cdr exp) bBox))))))


(define boundsInLambda
    (lambda (bodyExp lastBox paramBox boundsBox)
        (newline)
        (display `(bodyExp: ,bodyExp))
        (newline)
        (display `(lastBox: ,lastBox))
        (newline)
        (display `(paramBox: ,paramBox))
        (newline)
        (display `(boundsBox: ,boundsBox))
        (newline)


        (if (and (not (null? bodyExp))
                 (list bodyExp)
                 (equal? (car bodyExp) 'seq)
            )
            (map boundsInLambda (cadr bodyExp))


            (let* ( (lists* (filter (lambda (el) (and (not (null? el)) (list? el) (not (equal? (car el) 'const)))) bodyExp))
                    (lists (map (lambda (el) (if (equal? (car el) 'set) (cddr el) el)) lists*))
                    (bounds (filter (lambda (el) (and (member el (unbox lastBox)) (not (member el (unbox paramBox))))) bodyExp))
                    (listsLeft? (> (length lists) 0)) 
                    (anyBounds? (> (length bounds) 0))
                  )

            (if anyBounds?
                (begin
                    (set-box! boundsBox (append (unbox boundsBox) bounds))))

            (if listsLeft?
                        (map 
                            (lambda (lst)

                                (if (lambda? (car lst))

                                    (let* ((newBodyExp (make-body lst))
                                        (newParamBox (make-pBox exp))
                                        (newLastBox (box (append (unbox lastBox) (unbox paramBox))))
                                        )

                                        (boundsInLambda newBodyExp newLastBox newParamBox boundsBox))

                                        (boundsInLambda lst lastBox paramBox boundsBox))) 
                        lists)
                        0))
                    )))



  (define make-pBox
        (lambda (lamExp)
            (if (equal? (car lamExp) 'lambda-simple)
                (box (cadr lamExp))
                (if (equal? (car lamExp) 'lambda-opt)
                    (box (cadr lamExp))
                    (box '())))))

(define make-body
    (lambda (lamExp)
        (if (equal? (car lamExp) 'lambda-opt)
            (cdddr lamExp)
            (cddr lamExp))))

any help would be very much appreciated.

Tamarcuse
  • 53
  • 1
  • 6
  • The code is missing some implementations of `atom?` etc.. Also you have not provided how you called this code to see no output. – Sylwester Jan 05 '17 at 18:00
  • as far as I know atom? is a built in procedure in scheme which mean the exp is an atomic value (number, char etc..) – Tamarcuse Jan 05 '17 at 18:13
  • If you look at the index of the [R6RS report](http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-21.html#node_index_start) its obvious it's not a part of Scheme. `atom` is from the very first lisp and exists in Comon Lisp, not Scheme. Stanadr procedures that might be related are `pair?` and `null?`. `lambda?` isn't defined either. How do you run the code? – Sylwester Jan 05 '17 at 18:34
  • you didn't wrap your `display` and `newline` sequence with `begin` – Nimrod Morag Jan 08 '17 at 17:27

0 Answers0