From: jimka
Subject: KERNEL::CONTROL-STACK-EXHAUSTED
Date: 
Message-ID: <1189205896.907961.313360@g4g2000hsf.googlegroups.com>
I get the following message when i compile the following code in sbcl.
Can anyone give me a hint as to what the problem might be?

Control stack guard page temporarily disabled: proceed with caution

debugger invoked on a SB-KERNEL::CONTROL-STACK-EXHAUSTED in thread
#<THREAD "worker" {1000D35101}>: 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.




(defpackage "3D-TETRIS"
  (:use "COMMON-LISP")
  (:export ))

(in-package :3d-tetris)

(defun set-matrix ( mat value &key row col)
  (setf (aref mat row col) value))

(defun rotate-about-x (theta)
  (let ((new (make-instance 'matrix))
	(c (round (cos theta)))
	(s (round (sin theta))))

    (set-matrix new 1  :row 0 :col 0)
    (set-matrix new c  :row 1 :col 1)
    (set-matrix new (- s) :row 1 :col 2)
    (set-matrix new s  :row 2 :col 1)
    (set-matrix new c  :row 2 :col 2)
    new))

(defun rotate-about-y (theta)
  (let (( new (make-instance 'matrix))
	( c (cos theta))
	( s (sin theta)))

    (set-matrix new c  :row 0 :col 0)
    (set-matrix new s  :row 0 :col 2)
    (set-matrix new 1  :row 1 :col 1)
    (set-matrix new (- s) :row 2 :col 0)
    (set-matrix new c  :row 2 :col 2)
    new))

(defun rotate-about-z ( theta)
  (let (( new (make-instance 'matrix))
	( c (cos theta))
	( s (sin theta)))

    (set-matrix new  c :row 0 :col 0)
    (set-matrix new (- s) :row 0 :col 1)
    (set-matrix new  s :row 1 :col 0)
    (set-matrix new  c :row 1 :col 1)
    (set-matrix new  1 :row 2 :col 2)
    new))


(defun x-coord (point)
  (car point))

(defun y-coord (point)
  (cadr point))

(defun z-coord (point)
  (caddr point))

(defun (setf x-coord) (value point)
  (setf (car point) value))

(defun (setf y-coord) (value point)
  (setf (cadr point) value))

(defun (setf z-coord) (value point)
  (setf (caddr point) value))

(defclass piece ()
  ((name  :initarg :name :accessor name)
   (color :initarg :color :accessor color)
   (points :type 'list :initarg :points :accessor points)
   (rotations :type 'list :accessor rotations)))

(defmacro thrice (var &rest body)
  `(loop for ,var from 0 below 3 ,@body))


;; transform a point in place
(defun apply-transform (pt mat)
  (let ((answer (list 0 0 0)))
    (thrice row
	  do (thrice col
		do (incf (nth row answer)
		      (* (nth col pt)
			 (aref mat row col)))))
    answer))

(defvar *angles* (list 0 (/ pi 2) pi (/ pi -2)))

(defun matrix-multiply-2 (self other)
  (let (( new (make-array '(3 3)
			  :initial-element 0)))
    (thrice i
	    do (thrice j
		       do (set-matrix new
				      (thrice k
					summing  (* (aref self  j k)
						    (aref other k i)))
				:row j
				:col i)))
    new))

(defun matrix-multiply ( mat1 mat2 &rest matrices)
  (cond
    ((null matrices)
     (matrix-multiply-2 mat1 mat2))
    (t
     (matrix-multiply-2 mat1
			(apply #'matrix-multiply mat2 matrices)))))

(defun rotate-3-angle ( alpha beta theta)
  (matrix-multiply (rotate-about-y (- beta))
		   (rotate-about-z (- alpha))
		   (rotate-about-y theta)
		   (rotate-about-z alpha)
		   (rotate-about-y beta)))


(defvar *matricies*
  (let (stack)
    (dolist     (alpha *angles*)
      (format t "alpha=~A~%" alpha)
      (dolist   (beta  *angles*)
	(format t "beta=~A~%" beta)
	(dolist (theta *angles*)
	  (format t "theta=~A~%" theta)
	  (pushnew (rotate-3-angle alpha beta theta) stack
		   :test (lambda (m1 m2)
			   (block testing
			     (thrice row
				(thrice col
				    (unless (eql (aref m1 row col)
						 (aref m2 row col))
				      (return-from testing nil))))
			     (return-from testing t)))))))
    stack))

From: jimka
Subject: Re: KERNEL::CONTROL-STACK-EXHAUSTED
Date: 
Message-ID: <1189207434.622303.111610@k79g2000hse.googlegroups.com>
It seems a bit strange to me. (make-instance 'matrix)  signals an
error,
but (let ((new (make-instance 'matrix))) nil) does not.

CL-USER> (make-instance 'matrix)
; Evaluation aborted
CL-USER> (let ((new (make-instance 'matrix)))
	   nil)
; in: LAMBDA NIL
;     (LET ((NEW (MAKE-INSTANCE 'MATRIX)))
;     NIL)
;
; caught STYLE-WARNING:
;   The variable NEW is defined but never used.
;
; compilation unit finished
;   caught 1 STYLE-WARNING condition
Control stack guard page temporarily disabled: proceed with caution

debugger invoked on a SB-KERNEL::CONTROL-STACK-EXHAUSTED in thread
#<THREAD "repl-thread" {10010910F1}>: 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.
From: Pillsy
Subject: Re: KERNEL::CONTROL-STACK-EXHAUSTED
Date: 
Message-ID: <1189209049.331580.264620@y42g2000hsy.googlegroups.com>
On Sep 7, 7:23 pm, jimka <·····@rdrop.com> wrote:
> It seems a bit strange to me. (make-instance 'matrix)  signals an
> error, but (let ((new (make-instance 'matrix))) nil) does not.

I don't see a DEFCLASS form for the MATRIX class...?

Cheers,
Pillsy
From: Barry Margolin
Subject: Re: KERNEL::CONTROL-STACK-EXHAUSTED
Date: 
Message-ID: <barmar-A9C102.22565607092007@comcast.dca.giganews.com>
In article <························@k79g2000hse.googlegroups.com>,
 jimka <·····@rdrop.com> wrote:

> It seems a bit strange to me. (make-instance 'matrix)  signals an
> error,
> but (let ((new (make-instance 'matrix))) nil) does not.

The compiler may be optimizing the MAKE-INSTANCE away, since it can see 
that the object is never used.

> 
> CL-USER> (make-instance 'matrix)
> ; Evaluation aborted
> CL-USER> (let ((new (make-instance 'matrix)))
> 	   nil)
> ; in: LAMBDA NIL
> ;     (LET ((NEW (MAKE-INSTANCE 'MATRIX)))
> ;     NIL)
> ;
> ; caught STYLE-WARNING:
> ;   The variable NEW is defined but never used.
> ;
> ; compilation unit finished
> ;   caught 1 STYLE-WARNING condition
> Control stack guard page temporarily disabled: proceed with caution
> 
> debugger invoked on a SB-KERNEL::CONTROL-STACK-EXHAUSTED in thread
> #<THREAD "repl-thread" {10010910F1}>: 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.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Juho Snellman
Subject: Re: KERNEL::CONTROL-STACK-EXHAUSTED
Date: 
Message-ID: <slrnfe4v74.eok.jsnell@sbz-30.cs.Helsinki.FI>
Barry Margolin <······@alum.mit.edu> wrote:
> In article <························@k79g2000hse.googlegroups.com>,
>  jimka <·····@rdrop.com> wrote:
>
>> It seems a bit strange to me. (make-instance 'matrix)  signals an
>> error,
>> but (let ((new (make-instance 'matrix))) nil) does not.
>
> The compiler may be optimizing the MAKE-INSTANCE away, since it can see 
> that the object is never used.

That's pretty unlikely. In the general case that optimization would
not be sound, since the user might have defined methods with arbitrary
side effects on generic functions of the MAKE-INSTANCE protocol. Or
worse yet, he might define such methods after the call to
MAKE-INSTANCE is compiled.

Of course the compiler might compile an optimized version first, on
the assumption that no such methods will be added later, and then fall
back to a more conservative version later if the assumption turns out
to be false. But I'm not aware of any CL implementations using this
technique significantly. 

-- 
Juho Snellman
From: Chris Russell
Subject: Re: KERNEL::CONTROL-STACK-EXHAUSTED
Date: 
Message-ID: <1189213875.941594.259250@o80g2000hse.googlegroups.com>
On 8 Sep, 00:23, jimka <·····@rdrop.com> wrote:

> CL-USER> (make-instance 'matrix)
> ; Evaluation aborted
> CL-USER> (let ((new (make-instance 'matrix)))
>            nil)
> ; in: LAMBDA NIL
> ;     (LET ((NEW (MAKE-INSTANCE 'MATRIX)))
> ;     NIL)
> ;
> ; caught STYLE-WARNING:
> ;   The variable NEW is defined but never used.
> ;
> ; compilation unit finished
> ;   caught 1 STYLE-WARNING condition
> Control stack guard page temporarily disabled: proceed with caution

If you scroll down in the debugger, you'll be able to view the stack
and see which functions are forming a recursive loop that's failing to
terminate in time.
From: Pascal Costanza
Subject: Re: KERNEL::CONTROL-STACK-EXHAUSTED
Date: 
Message-ID: <5kf1jlF3b824U1@mid.individual.net>
jimka wrote:
> I get the following message when i compile the following code in sbcl.
> Can anyone give me a hint as to what the problem might be?

As far as I can tell, the code can't possibly work.

You are creating instances of a (non-existing?) matrix class, but access 
their components with aref?


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: jimka
Subject: Re: KERNEL::CONTROL-STACK-EXHAUSTED
Date: 
Message-ID: <1189267956.271914.152420@d55g2000hsg.googlegroups.com>
yes it cannot possibly work, but i'd expect to get an error message
something like: There is no class named MATRIX.
rather than an error telling me i have an infinite loop :-(

most curious.

-jim

On Sep 8, 9:34 am, Pascal Costanza <····@p-cos.net> wrote:
> jimka wrote:
> > I get the following message when i compile the following code in sbcl.
> > Can anyone give me a hint as to what the problem might be?
>
> As far as I can tell, the code can't possibly work.
>
> You are creating instances of a (non-existing?) matrix class, but access
> their components with aref?
>
> Pascal
>
> --
> My website:http://p-cos.net
> Common Lisp Document Repository:http://cdr.eurolisp.org
> Closer to MOP & ContextL:http://common-lisp.net/project/closer/
From: Pascal Costanza
Subject: Re: KERNEL::CONTROL-STACK-EXHAUSTED
Date: 
Message-ID: <5kgi0fF3ji1sU1@mid.individual.net>
jimka wrote:
> yes it cannot possibly work, but i'd expect to get an error message
> something like: There is no class named MATRIX.
> rather than an error telling me i have an infinite loop :-(
> 
> most curious.

OK, I'm on SBCL 1.0.9 on Mac OS X 10.4.10 / PowerPC. When I compile the 
code with compile-file, I don't get any stack trace. I just get an error 
message that you're using thrice incorrectly - search for "thrice row".

Are you trying to compile the file from within SLIME? It could be that 
that causes the problem you're having. SLIME actually wraps the source 
of a file in a (compile nil '(lambda () ...)), because ANSI Common Lisp 
doesn't provide a way to do top-level compiles programmatically. This 
sometimes creates problems when you are (explicitly or implicitly) 
relying on the top-levelness of some constructs (such as macros). I 
vaguely recall having such a problem myself, but that was quite some 
time ago. I rarely use SLIME these days (but that's such coincidence, I 
don't have anything against SLIME).

In general, if the compiler creates weird errors, it is likely that 
there is something wrong with the correct phasing of macro definitions 
or eval-when constructs. So my guess would be that it is indeed the 
incorrect use of thrice which is giving you problems here.

A call of make-instance on an undefined class doesn't give you error 
messages at compile time, because it is "legal" to define the respective 
class only later.


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: jimka
Subject: Re: KERNEL::CONTROL-STACK-EXHAUSTED
Date: 
Message-ID: <1189294493.160171.168390@k79g2000hse.googlegroups.com>
ahhh, yes you are right. if i simply evaluate the code at
the sbcl repl rather than in slime I see the SIMPLE-ERROR and a
complaint
that there is no class named MATRIX rather
than an infinite loop.  it is a little less curious now.

-jim


* (let ((x (make-instance 'matrix))) nil)
; in: LAMBDA NIL
;     (LET ((3D-TETRIS::X (MAKE-INSTANCE '3D-TETRIS::MATRIX)))
;     NIL)
;
; caught STYLE-WARNING:
;   The variable X is defined but never used.
;
; compilation unit finished
;   caught 1 STYLE-WARNING condition

debugger invoked on a SIMPLE-ERROR in thread #<THREAD "initial
thread" {10000048D1}>:
  There is no class named MATRIX.

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

(SB-PCL::FIND-CLASS-FROM-CELL MATRIX NIL T)







On Sep 8, 11:20 pm, Pascal Costanza <····@p-cos.net> wrote:
> jimka wrote:
> > yes it cannot possibly work, but i'd expect to get an error message
> > something like: There is no class named MATRIX.
> > rather than an error telling me i have an infinite loop :-(
>
> > most curious.
>
> OK, I'm on SBCL 1.0.9 on Mac OS X 10.4.10 / PowerPC. When I compile the
> code with compile-file, I don't get any stack trace. I just get an error
> message that you're using thrice incorrectly - search for "thrice row".
>
> Are you trying to compile the file from within SLIME? It could be that
> that causes the problem you're having. SLIME actually wraps the source
> of a file in a (compile nil '(lambda () ...)), because ANSI Common Lisp
> doesn't provide a way to do top-level compiles programmatically. This
> sometimes creates problems when you are (explicitly or implicitly)
> relying on the top-levelness of some constructs (such as macros). I
> vaguely recall having such a problem myself, but that was quite some
> time ago. I rarely use SLIME these days (but that's such coincidence, I
> don't have anything against SLIME).
>
> In general, if the compiler creates weird errors, it is likely that
> there is something wrong with the correct phasing of macro definitions
> or eval-when constructs. So my guess would be that it is indeed the
> incorrect use of thrice which is giving you problems here.
>
> A call of make-instance on an undefined class doesn't give you error
> messages at compile time, because it is "legal" to define the respective
> class only later.
>
> Pascal
>
> --
> My website:http://p-cos.net
> Common Lisp Document Repository:http://cdr.eurolisp.org
> Closer to MOP & ContextL:http://common-lisp.net/project/closer/