Added EmacsConfigurationAndHelp directory
[temp.git] / site-lisp / clisp-indent.lisp
blob02af767c87719f929c8b24db9681420912e142b9
1 ;; Sample Lisp code, used as a test for clisp-indent.el
2 ;; Contains at least one sample form for every special form or macro.
3 ;; The list is sorted by exporting package.
5 (and (cond1) (cond2)
6 (cond3)
7 (cond4))
9 (and
10 (cond1) (cond2)
11 (cond3)
12 (cond4))
14 (appease-cerrors
15 (form1)
16 (form2))
18 (assert (form1)
19 "error")
21 (block nil
22 (form1)
23 (form2))
25 (block
26 nil
27 (form1)
28 (form2))
30 (case foo
31 ((T)
32 (form1)
33 (form2)))
35 (catch 'foo
36 (form1)
37 (form2))
39 (ccase foo
40 ((T)
41 (form1)
42 (form2)))
44 (check-type x integer
45 "error")
47 (compiler-let
48 ((*load-pathname* nil))
49 (form1))
51 (cond
52 ((cond1)
53 (form1)
54 (form2)
55 (form3)))
57 (cond ((cond1)
58 (form1)
59 (form2)
60 (form3)))
62 (ctypecase x
63 (integer
64 (isqrt x)))
66 (decf
67 (aref a i)
68 (aref b i))
70 (declaim
71 (optimize (safety 3)
72 (speed 1)))
74 (declare
75 (integer x))
77 (defclass fundamental-stream
78 (stream clos:standard-object
80 (($open :type boolean :initform t) ; whether the stream is open
81 ($reval :type boolean :initform nil)) ; whether read-eval is allowed
82 (:metaclass standard-class))
84 (defconstant pi
85 3.14
86 "Archimedes")
88 (defgeneric foobar (x y)
89 "foo goes bar")
91 (define-condition arithmetic-error (error)
92 (($operation :initarg :operation :reader arithmetic-error-operation)
93 ($operands :initarg :operands :reader arithmetic-error-operands)))
95 (define-modify-macro decf (x)
97 "decrement")
99 (define-modify-macro decf (x) -
100 "decrement")
102 (define-setf-expander subseq (seq start end)
103 (compute-expansion))
105 (define-setf-method subseq (seq start end)
106 (compute-expansion))
108 (define-symbol-macro *ansi*
109 (get-ansi))
111 (definternational date-format
112 (t ENGLISH))
114 (deflanguage ENGLISH)
116 (deflocalized date-format ENGLISH
117 "~1{~5@*~D-~4@*~2,'0D-~3@*~2,'0D ~2@*~2,'0D:~1@*~2,'0D:~0@*~2,'0D~:}")
119 (defmacro incf (place &optional (delta '1))
120 `(setf ,place (+ ,place ,delta)))
122 (defmethod foo ((x integer)
124 (z t))
125 (bar x y z))
127 (defpackage regexp
128 (:nicknames re)
129 (:documentation
130 "POSIX Regular Expressions - matching, compiling, executing.")
131 (:use lisp ffi)
132 (:export match match-start match-end match-string regexp-quote
133 regexp-compile regexp-exec regexp-split with-loop-split))
135 (defparameter pi
136 3.14
137 "Archimedes")
139 (defsetf nth SYSTEM::%SETNTH
140 "set nth element")
142 (defsetf aref (array &rest indices) (value)
143 `(SYSTEM::STORE ,array ,@indices ,value))
145 (defsetf aref (array &rest indices)
146 (value)
147 `(SYSTEM::STORE ,array ,@indices ,value))
149 (defstruct (control-string-directive
150 (:copier nil)
151 (:conc-name "CSD-")
152 (:predicate nil)
153 (:constructor make-csd ()))
154 (type 0 :type fixnum)
155 (cs-index 0 :type fixnum)
156 (parm-list nil :type list)
157 (v-or-#-p nil :type symbol)
158 (colon-p nil :type symbol)
159 (atsign-p nil :type symbol)
160 (data nil)
161 (clause-chain nil))
163 (deftype designator (thing)
164 (cond ((symbolp thing)
165 ...)))
167 (defun foo
168 (&optional x
169 &key y)
171 (defvar pi
172 3.14
173 "Archimedes")
175 (destructuring-bind (&optional x
176 &rest y)
177 (foobar)
178 (form1)
179 (form2))
181 (deutsch
182 "Beispiel"
183 english
184 "Sample")
186 (do ((x 1 (1+ x))
187 (y (init-y)
188 (inc y)))
189 ((endp l))
190 (form1))
192 (do* ((x 1 (1+ x))
193 (y (init-y)
194 (inc y)))
195 ((endp l))
196 (form1))
198 (do-all-symbols (s (find-package "NAME")
199 nil)
200 (foobar))
202 (do-external-symbols (s (find-package "NAME")
203 nil)
204 (foobar))
206 (do-symbols (s)
207 (foobar))
209 (dohash (key val)
210 (get-hash-table)
211 (form1)
212 (form2))
214 (dolist (x
215 (list)
216 nil)
217 (form1))
219 (doseq (x
220 (list)
221 nil)
222 (form1))
224 (dotimes (x
225 (count)
226 nil)
227 (form1))
229 (ecase foo
230 ((T)
231 (form1)
232 (form2)))
234 (english
235 "Sample"
236 deutsch
237 "Beispiel")
239 (etypecase (form1)
240 (integer
241 (form2) (form3)
242 (form3)))
244 (eval-when
245 (compile)
246 (do-something))
248 (exit-on-error
249 (form1))
251 (flet ((mark-used
252 (blockname
253 &optional x
254 &key y)
255 (setf (get blockname 'used) t)
256 (do ((L1 *format-uwps* (cdr L1))
257 (L2 (get blockname 'uwps)))
258 ((eq L1 L2))
259 (setf (car L1) 'T))
260 blockname))
261 (mark-used nil))
263 (formatter
264 "error: ~S")
266 (francais
267 "exemple"
268 english
269 "Sample"
270 deutsch
271 "Beispiel")
273 (function
274 random)
276 (function (lambda (x y)
277 (+ x y)))
279 (function
280 (lambda (x y)
281 (+ x y)))
283 (function plus (lambda (x y)
284 (+ x y)))
286 (function plus
287 (lambda (x y)
288 (+ x y)))
290 (function
291 plus
292 (lambda (x y)
293 (+ x y)))
295 (generic-flet
296 ((dump (x)
297 (:method ((x character))
298 (format t "~C" x))
299 (:method ((x integer))
300 (format t "~D" x))))
301 (dump obj))
303 (generic-function (x)
304 (:method ((x character))
305 (format t "~C" x))
306 (:method ((x integer))
307 (format t "~D" x)))
309 (generic-labels ((fib (x)
310 (:method ((x (eql 0)))
312 (:method ((x (eql 1)))
314 (:method ((x integer))
315 (if (minusp x)
316 (- (fib (+ x 2)) (fib (+ x 1)))
317 (+ (fib (- x 2)) (fib (- x 1)))))))
318 (fib n))
321 nil)
323 (handler-bind
324 ((simple-error
325 #'(lambda (c) (throw 'exit (values nil c))))
326 (error
327 #'(lambda (c) (throw 'exit (values nil c)))))
328 (form1))
330 (handler-case
331 (push-object (part-ref object index) index)
332 (part-ref-error ()
333 (format t "~D does not refer to a selectable part." index))
334 (:no-error (&optional x
335 &key y)
336 (f x y)))
338 (if (minusp x)
339 (- (fib (+ x 2)) (fib (+ x 1)))
340 (+ (fib (- x 2)) (fib (- x 1))))
342 (ignore-errors
343 (/ x y))
345 (in-package "FOO"
346 :use '("BAR"))
348 (in-package
349 "FOO"
350 :use '("BAR"))
352 (incf
353 (aref a i)
354 (aref b i))
356 (labels ((mark-used
357 (blockname
358 &optional x
359 &key y)
360 (setf (get blockname 'used) t)
361 (do ((L1 *format-uwps* (cdr L1))
362 (L2 (get blockname 'uwps)))
363 ((eq L1 L2))
364 (setf (car L1) 'T))
365 blockname))
366 (mark-used nil))
368 (lambda (x y)
369 (+ x y))
371 (let ((x (i-x))
373 (long-init-y)))
374 (foobar))
376 (let* ((x (i-x))
378 (long-init-y)))
379 (foobar))
382 (load-time-value
383 (foo)
386 (locally
387 (declare (compile))
388 (foo))
390 (loop
391 (incf x)
392 (return))
394 (loop-finish)
396 (macrolet ((Monat->Jahrtag (Monat) ; 0 <= Monat < 12, 0=März,...,11=Februar
397 `(svref '#(0 31 61 92 122 153 184 214 245 275 306 337) ,Monat)))
398 (form1))
400 (muffle-cerrors
401 (form1))
403 (multiple-value-bind (x y)
404 (floor a b)
405 (values y x))
407 (multiple-value-call #'%expand-cons (rest form)
408 (second form) nil
409 (%expand-list (cddr form))
411 (multiple-value-list
412 (floor a b))
414 (multiple-value-prog1
415 (floor a b)
416 (foobar))
418 (multiple-value-setq
419 (SM1 SM2 SM3 SM4 SM5)
420 (get-setf-method (car form)))
422 (nth-value 1
423 (floor a b))
425 (or (cond1) (cond2)
426 (cond3)
427 (cond4))
430 (cond1) (cond2)
431 (cond3)
432 (cond4))
434 (pop
435 (form1))
437 (print-unreadable-object (class stream :type t)
438 (write (class-classname class) :stream stream))
440 (prog (a b
441 c d)
442 retry
443 (multiple-value-setq (c d)
444 (floor a b))
445 (if (zerop d)
446 (return))
447 (go retry))
449 (prog* (a b
450 c d)
451 retry
452 (multiple-value-setq (c d)
453 (floor a b))
454 (if (zerop d)
455 (return))
456 (go retry))
458 (prog1
459 (form1)
460 (form2))
462 (prog2
463 (form1)
464 (form2)
465 (form3))
467 (progn (form1)
468 (form2))
470 (progn
471 (form1)
472 (form2))
474 (progv
475 (vars)
476 (vals)
477 (form1)
478 (form2))
480 (progv (vars) (vals)
481 (form1)
482 (form2))
484 (psetf a (get-a)
485 b (get-b))
487 (psetf a
488 (get-a)
490 (get-b))
492 (psetq a (get-a)
493 b (get-b))
495 (psetq a
496 (get-a)
498 (get-b))
500 (push (form1)
501 (form2))
503 (push
504 (form1)
505 (form2))
507 (pushnew (form1)
508 (form2))
510 (pushnew
511 (form1)
512 (form2))
514 (quote
515 #(a b c))
517 (remf 'x
520 (restart-bind ((nil *fun1*
521 :interactive-function *fun2*
522 :report-function *fun3*
523 :test-function *fun4*))
524 (form1)
525 (form2))
527 (restart-bind
528 ((nil *fun1*
529 :interactive-function *fun2*
530 :report-function *fun3*
531 :test-function *fun4*))
532 (form1)
533 (form2))
535 (restart-case
536 (invoke-debugger condition)
537 (continue (&optional x
538 &aux y)
539 (form1)
540 (form2)))
542 (return
543 (form1))
545 (return-from
547 (form1))
549 (rotatef (aref x i)
550 (aref y i))
552 (rotatef
553 (aref x i)
554 (aref y i))
556 (setf a (get-a)
557 b (get-b))
559 (setf a
560 (get-a)
562 (get-b))
564 (setq a (get-a)
565 b (get-b))
567 (setq a
568 (get-a)
570 (get-b))
572 (shiftf (aref x i)
573 (aref y i)
574 (aref z i))
576 (shiftf
577 (aref x i)
578 (aref y i)
579 (aref z i))
581 (space
582 (form1))
584 (step
585 (form1))
587 (symbol-macrolet
588 ((x (slot-value obj 'x))
590 (slot-value obj 'y)))
591 (form1))
593 (symbol-macrolet ((x (slot-value obj 'x))
595 (slot-value obj 'y)))
596 (form1))
598 (tagbody
599 retry
600 (multiple-value-setq (c d)
601 (floor a b))
602 (if (zerop d)
603 (return))
604 (go retry))
606 (the integer
607 (form1))
609 (the-environment)
611 (throw
612 'exit
613 (form1))
615 (time
616 (form1))
618 (trace foo
619 bar)
621 (trace
623 bar)
625 (typecase (form1)
626 (integer
627 (form2) (form3)
628 (form3)))
630 (unless
631 (cond1)
632 (form1)
633 (form2))
635 (untrace foo
636 bar)
638 (untrace
640 bar)
642 (unwind-protect
643 (foo)
644 (close s))
646 (when
647 (cond1)
648 (form1)
649 (form2))
651 (with-accessors ((x1 thing-x) (y1 thing-y)
652 (z1 thing-z))
653 thing1
654 (form1))
656 (with-condition-restarts
657 (conds)
658 (restarts)
659 (form1))
661 (with-hash-table-iterator
662 (name table)
663 (form1))
665 (with-hash-table-iterator (name table)
666 (form1))
668 (with-input-from-string
669 (x s :start 3)
670 (form1))
672 (with-keyboard
673 (form1))
675 (with-open-file (s "foobar"
676 :direction :input)
677 (form1))
679 (with-open-stream (s stream)
680 (form1))
682 (with-output-to-printer (s
683 :external-format charset:iso-8859-1)
684 (form1))
686 (with-output-to-string (s str
687 :element-type 'character)
688 (form1))
690 (with-package-iterator (name pack)
691 (form1))
693 (with-restarts
694 ((continue (&optional x
695 &aux y)
696 (form1)
697 (form2)))
698 (invoke-debugger condition))
700 (with-simple-restart
701 (x error
702 "error")
703 (form1))
705 (with-slots ((x1 x) (y1 y)
706 (z1 z))
707 thing1
708 (form1))
710 (with-standard-io-syntax
711 (form1))
713 (without-floating-point-underflow
714 (expt 10 x))
716 ;; Package SYSTEM
717 constant-eql
718 defformat-simple
719 ds-slot-default
720 ds-slot-initer
721 ds-slot-offset
722 ds-slot-readonly
723 ds-slot-type
724 formatter-bind-args
725 formatter-bind-terminator
726 formatter-bind-terminators
727 macro-expander
728 memq
729 multiple-value-setf
732 ;; Package FFI
734 bitsizeof
735 c-lines
736 cast
737 def-c-call-in
738 def-c-call-out
739 def-c-enum
740 def-c-struct
741 def-c-type
742 def-c-var
743 def-call-in
744 def-call-out
745 deref
746 element
747 sizeof
748 slot
749 typeof
751 ;; Package SCREEN
753 with-window