From: Tamas Papp
Subject: symbol-macrolet question
Date: 
Message-ID: <87lkbv3acq.fsf@pu100877.student.princeton.edu>
I am working with arrays, where in the beginning of the loop I compute
relevant indexes, then fill elements in arrays using other elements.  Eg

(setf (aref a-array a-index) something)
(setf (aref b-array b-index) (foo (aref a-array a-index)))
...

The indexes are not simply 0...n, so using a looping construct like
iterate does not work.  To make the code more easily readable, I
thought I would use symbol macros (never used them before) to name
(aref a-array a-index) to a-value etc.

Why does this toy example not work?  

(let ((deltat (make-array 10))
      (index 7))
  (symbol-macrolet ((deltat (aref deltat index)))
    (setf deltat 8))
  (format t "~A~%" deltat))

I get this in SBCL:

Control stack exhausted (no more space for function call frames).  This is probably due to heavily nested or infinitely recursive function calls, or a tail call that SBCL cannot or has not optimized away.
   [Condition of type SB-KERNEL::CONTROL-STACK-EXHAUSTED]

Restarts:
 0: [ABORT] Return to SLIME's top level.
 1: [TERMINATE-THREAD] Terminate this thread (#<THREAD "worker" {AD685E9}>)

Backtrace:
  0: (SB-KERNEL::CONTROL-STACK-EXHAUSTED-ERROR)
  1: ("foreign function: #x806366C")
  2: ("foreign function: #x80638C8")
  3: ((FLET #:CLEANUP-FUN-989))

Thanks,

Tamas

From: Zach Beane
Subject: Re: symbol-macrolet question
Date: 
Message-ID: <m3fy23aai6.fsf@unnamed.xach.com>
Tamas Papp <······@gmail.com> writes:

> Why does this toy example not work?  
>
> (let ((deltat (make-array 10))
>       (index 7))
>   (symbol-macrolet ((deltat (aref deltat index)))
>     (setf deltat 8))
>   (format t "~A~%" deltat))

The SYMBOL-MACROLET thing should return a form. You might want to use
' or ` to quote (AREF DELTAT INDEX).

Zach
From: Zach Beane
Subject: Re: symbol-macrolet question
Date: 
Message-ID: <m3bqcraa01.fsf@unnamed.xach.com>
Zach Beane <····@xach.com> writes:

> Tamas Papp <······@gmail.com> writes:
>
>> Why does this toy example not work?  
>>
>> (let ((deltat (make-array 10))
>>       (index 7))
>>   (symbol-macrolet ((deltat (aref deltat index)))
>>     (setf deltat 8))
>>   (format t "~A~%" deltat))
>
> The SYMBOL-MACROLET thing should return a form. You might want to use
> ' or ` to quote (AREF DELTAT INDEX).

Oops. Joel Wilsson has the right answer. Sorry about that.

Zach
From: Joel Wilsson
Subject: Re: symbol-macrolet question
Date: 
Message-ID: <1188318790.075373.252880@o80g2000hse.googlegroups.com>
On Aug 28, 6:14 pm, Tamas Papp <······@gmail.com> wrote:
> Why does this toy example not work?
>
> (let ((deltat (make-array 10))
>       (index 7))
>   (symbol-macrolet ((deltat (aref deltat index)))
>     (setf deltat 8))

What happens when you expand the setf?
You get (setf (aref deltat index) 8)

What happens when you expand again?
You get (setf (aref (aref deltat index) index) 8)

What happens when you... right, we're looping,
until we run out of stack space like SBCL.

The easy solution would be something like:
(let ((deltat (make-array 10))
      (index 7))
  (symbol-macrolet ((deltat-s (aref deltat index)))
    (setf deltat-s 8))
  (format t "~A~%" deltat))


Regards,
  Joel