0.8.9.12:
[sbcl.git] / tests / dynamic-extent.impure.lisp
1 ;;;; tests that dynamic-extent functionality works.
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;; 
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
13
14 ;;; &REST lists
15 (defmacro defun-with-dx (name arglist &body body)
16   `(locally
17      (declare (optimize sb-c::stack-allocate-dynamic-extent))
18      (defun ,name ,arglist
19        ,@body)))
20
21 (defun-with-dx dxlength (&rest rest)
22   (declare (dynamic-extent rest))
23   (length rest))
24
25 (assert (= (dxlength 1 2 3) 3))
26 (assert (= (dxlength t t t t t t) 6))
27 (assert (= (dxlength) 0))
28
29 (defun callee (list)
30   (destructuring-bind (a b c d e f &rest g) list
31     (+ a b c d e f (length g))))
32
33 (defun-with-dx dxcaller (&rest rest)
34   (declare (dynamic-extent rest))
35   (callee rest))
36
37 (assert (= (dxcaller 1 2 3 4 5 6 7) 22))
38 \f
39 (sb-ext:quit :unix-status 104)