[R] Porting let* from Common LISP to R

Gabriel Baud-Bovy
Thu, 12 Feb 2004 13:56:49 -0000

In porting some Common LISP code to R, I am trying to found out whether special
care must be taken for the let* function. In Common LISP, "the let* block
is like
let except it is guaranteed to evaluate the initialization of its local
variables in sequentially nested scopes, i.e. it provides an order to the
binding and visibility of preceding variables.".

I have included the recursive Common LISP function in which let* block appears
and a straighforward R port.

Thank you,

Gabriel Baud-Bovy


The let* block appears in the following LISP function:

(defun infer (goal subsitution kb)
   (if(null kb)
     (make-empty-stream)
     (let* ((assertion (rename-variable (car kb)))    ; *********
            (match ([...])))
           (if (equal match 'failed)
              (infer goal substitutions (cdr kb))
              (if (rulep assertion)
                 (combine-streams ([...]) (infer goal substitutions (cdr kb)))
                 (cons-stream match (infer goal substitutions (cdr kb))))))))

A straighforward R-translation would be

infer<-function(goal,subsitution,kb) {
   if(is.null(kb)) make-empty-stream()
   else {
     assertion<-rename-variable(car(kb))
     match<- [...]
     if(match=="failed") infer(goal,substitutions,cdr(kb))
     else  {
        if(is.rule(assertion))
           combine-streams( [...], infer(goal,substitutions,cdr(kb))
        else
           cons-stream(match,infer(goal,substitutions,cdr(kb))
     }
   }
}

I ask this question because I sometimes encounter infinite recursion in
testing my code. I think that the problem might come from differences
between the Common LISP and R evaluation models.

--------------------------------------------------------------------
Gabriel Baud-Bovy
Faculty of Psychology
UHSR University
via Olgettina, 58	tel: (+39) 02 2643 4839
20132 Milan, Italy	fax: (+39) 02 2643 4892