[R] Porting let* from Common LISP to R

Gabriel Baud-Bovy baud-bovy.gabriel at hsr.it
Thu Feb 12 14:56:49 CET 2004

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)
     (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 {
     match<- [...]
     if(match=="failed") infer(goal,substitutions,cdr(kb))
     else  {
           combine-streams( [...], 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

More information about the R-help mailing list