52ce80781548777a0e77c168272c9c44c8bc1167
[software/python-on-guile.git] / modules / language / python / exceptions.scm
1 (define-module (language python exceptions)
2 #:use-module (oop pf-objects)
3 #:use-module (oop goops)
4 #:export (StopIteration GeneratorExit RuntimeError
5 Exception))
6
7 (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))
8
9 (define StopIteration 'StopIteration)
10 (define GeneratorExit 'GeneratorExit)
11 (define RuntimeError 'RuntimeError)
12
13 (define-python-class Exception ()
14 (define __init__
15 (case-lambda
16 ((self)
17 (values))
18 ((self str)
19 (set self 'str str))))
20
21 (define __repr__
22 (lambda (self . l)
23 (define port (if (pair? l) (car l) #f))
24 (aif it (ref self 'str)
25 (format port "<~s: ~a>"
26 (ref self '__name__) it)
27 (format port "<~s>"
28 (ref self '__name__))))))
29
30
31
32
33