hurd-cl-compat.scm 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. (define-module (hurd-cl-compat)
  2. ;; Common Lisp functions, syntax and variables
  3. #:export (in-package defvar defconstant
  4. defgeneric defun
  5. defmethod defmacro
  6. defclass
  7. setf
  8. t
  9. progn
  10. (eval-when/common-lisp . eval-when)
  11. (case/common-lisp . case)
  12. (reduce/common-lisp . reduce)
  13. (concatenate/common-lisp . concatenate)
  14. mapcar
  15. flet
  16. nil
  17. declare
  18. loop
  19. boole
  20. multiple-value-bind
  21. destructuring-bind
  22. check-type
  23. ;; Some predicates
  24. typep
  25. ;; Common Lisp bitwise functions (also see #:re-export)
  26. boole-1
  27. boole-2
  28. boole-andc1
  29. boole-andc2
  30. boole-c1
  31. boole-c2
  32. boole-clr
  33. boole-nor
  34. boole-orc1
  35. boole-orc2
  36. boole-set
  37. ;; List manipulation
  38. pushnew
  39. remove-if
  40. ;; Hash table operations
  41. gethash
  42. ;; Conditions
  43. warning style-warning define-condition
  44. ;; Not Common Lisp, but still useful
  45. define-report
  46. syntax-map syntax-car
  47. syntax-cdr syntax-cadr
  48. list-syntax->syntax-list
  49. loop*
  50. case/scheme) ; <-- XXX case/common-lisp should suffice
  51. ;; Predicates and comparison operators?
  52. #:re-export ((null? . null)
  53. (zero? . zerop)
  54. (number? . numberp)
  55. (symbol? . symbolp)
  56. (string? . stringp)
  57. (char? . charp)
  58. (eq? . eq)
  59. (eqv? . eql)
  60. (positive? . plusp) ; > 0
  61. ;; CL has equal and equalp,
  62. ;; where (equal 3 3.0) but not (equalp 3 3.0).
  63. ;; Let's silently use the latter behaviour and
  64. ;; hope nothhing notices. Likewise for eql.
  65. (equal? . equal)
  66. (equal? . equalp)
  67. ;; Bitwise operations
  68. (bitwise-ior . boole-ior)
  69. (bitwise-and . boole-and)
  70. (bitwise-xor . boole-xor)
  71. ;; Hash-Table operations
  72. (rnrs:make-eqv-hashtable . make-hashtable))
  73. #:replace (defmacro
  74. (eval-when/common-lisp . eval-when)
  75. (case/common-lisp . case)
  76. (concatenate/common-lisp . concatenate)
  77. reduce)
  78. #:use-module ((rnrs base) #:select (assert))
  79. #:use-module (oop goops)
  80. #:use-module (srfi srfi-1)
  81. ;; Procedural interface to (rnrs conditions)
  82. #:use-module ((srfi srfi-35) #:prefix srfi:)
  83. #:use-module ((rnrs hashtables) #:prefix rnrs:)
  84. #:use-module (rnrs arithmetic fixnums)
  85. #:use-module (rnrs arithmetic bitwise)
  86. #:use-module (ice-9 receive)
  87. #:use-module (rnrs conditions))
  88. ;; Common Lisp -- Scheme compatibility,
  89. ;; fudging over many details.
  90. ;; XXX recognise foreign-enum, foreign-type, ...
  91. (define-syntax typep
  92. (lambda (s)
  93. (syntax-case s (quote integer fixnum character string)
  94. ((_ object 'integer) #'(integer? object))
  95. ((_ object 'fixnum) #'(fixnum? object))
  96. ((_ object 'character) #'(character? object))
  97. ((_ object 'string) #'(string? object))
  98. (_ #'(XXX-implement #{perhaps a hash table for clos goops!}#)))))
  99. ;; Hash tables
  100. (define gethash
  101. (let ((v (cons #nil #nil)))
  102. ;; ^ not seen, merely an unique object to determine the hash table
  103. ;; does not have a certain key!
  104. (make-procedure-with-setter
  105. (lambda* (key hash-table #:optional (default #nil))
  106. (receive (result)
  107. (rnrs:hashtable-ref hash-table v)
  108. (if (eq? result v)
  109. (values default #nil)
  110. (values result #true))))
  111. (case-lambda
  112. ((key hash-table new-value)
  113. (hash-table-set! hash-table key new-value)
  114. (values))
  115. ((key hash-table default new-value)
  116. (hash-table-set! hash-table key new-value)
  117. (values))))))
  118. ;; Boolean. See
  119. ;; https://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/index-seo.php/ACL2____BOOLE_42
  120. (define (boole-1 x y)
  121. (assert (exact-integer? x))
  122. (assert (exact-integer? y))
  123. x)
  124. (define (boole-2 x y)
  125. (assert (exact-integer? x))
  126. (assert (exact-integer? y))
  127. x)
  128. (define (boole-andc2 x y)
  129. (bitwise-and x (bitwise-not y)))
  130. (define (boole-andc1 x y)
  131. (bitwise-and (bitwise-not x) y))
  132. (define (boole-c1 x y)
  133. (assert (exact-integer? x))
  134. (assert (exact-integer? y))
  135. (bitwise-not x))
  136. (define (boole-c2 x y)
  137. (assert (exact-integer? x))
  138. (assert (exact-integer? y))
  139. (bitwise-not y))
  140. (define (boole-clr x y)
  141. (assert (exact-integer? x))
  142. (assert (exact-integer? y))
  143. 0)
  144. (define (boole-set x y)
  145. (assert (exact-integer? x))
  146. (assert (exact-integer? y))
  147. -1)
  148. (define (boole-nor x y)
  149. (bitwise-not (bitwise-ior x y)))
  150. (define (boole-orc1 x y)
  151. (bitwise-ior (bitwise-not x) y))
  152. (define (boole-orc2 x y)
  153. (bitwise-ior x (bitwise-not y)))
  154. (define-syntax-rule (pushnew item var)
  155. (let ((old var)
  156. (val item))
  157. (if (memq val old)
  158. old
  159. (begin (set! var (cons item old))
  160. old))))
  161. (define* (remove-if test sequence)
  162. (if (vector? sequence)
  163. (list->vector (remove-if test (vector->list sequence)))
  164. (filter (negate test) sequence)))
  165. ;; Warning: syntax cannot (currently) be re-exported!
  166. ;; If you try, you'll end up with "Wrong type to apply: #<syntax-transformer case/scheme>".
  167. (define nil #nil)
  168. (define* (reduce/common-lisp proc ls #:key initial-value)
  169. (reduce proc initial-value ls))
  170. (define (concatenate/common-lisp type . stuff)
  171. (case type
  172. ((string) (apply string-append stuff))))
  173. (define-syntax declare
  174. (syntax-rules (type fixnum ignore)
  175. ((_ (type fixnum x ...))
  176. (begin
  177. (assert (fixnum? x))
  178. ...))
  179. ((_ (ignore stuff))
  180. (begin))))
  181. (define-syntax type-exp-predicate
  182. (lambda (s)
  183. (syntax-case s (and not null symbol)
  184. ((_ symbol) #'symbol?)
  185. ((_ (and x y))
  186. #'(lambda (z) (and ((type-exp-predicate x) z)
  187. ((type-exp-predicate y) z))))
  188. ((_ (not x))
  189. #'(lambda (z) (not ((type-exp-predicate x) z))))
  190. ((_ null) null?)
  191. ;; XXX why won't ((_ symbol) #'symbol?) work?
  192. ((_ rest) (eq? (syntax->datum #'rest) 'symbol)
  193. #'(lambda (x)
  194. (or (symbol? x)
  195. ;; Common Lisp symbols starting with : are mapped to Scheme keyword objects.
  196. (keyword? x))))
  197. ;; XXX likewise
  198. ((_ rest) (eq? (syntax->datum #'rest) 'null)
  199. #'null?))))
  200. (define-syntax-rule (check-type var type-exp)
  201. (assert ((type-exp-predicate type-exp) var)))
  202. (define-syntax eval-when/common-lisp
  203. (lambda (s)
  204. (define (eval-when-cl->scheme s)
  205. (syntax-case s (compile load eval expand)
  206. (#:compile-toplevel #'compile)
  207. (compile #'compile)
  208. (#:load-toplevel #'load)
  209. (load #'load)
  210. (#:execute #'eval)
  211. (eval #'eval)
  212. (expand #'expand)))
  213. (syntax-case s ()
  214. ((_ x exp exp* ...)
  215. #`(eval-when
  216. #,(map eval-when-cl->scheme
  217. (list-syntax->syntax-list #'x))
  218. exp exp* ...)))))
  219. (define-syntax case/common-lisp
  220. (syntax-rules (otherwise)
  221. ((_ what (otherwise stuff ...)) (begin stuff ...))
  222. ((_ what (x y))
  223. ;; XXX what does Common Lisp prescribe
  224. ;; in case there is no match?
  225. (case what
  226. ((x) y)))
  227. ((_ what (x y) . rest)
  228. (let ((save what))
  229. (if (eq? save 'x)
  230. y
  231. (case/common-lisp save . rest))))))
  232. ;; TODO
  233. (define (boole x y z)
  234. 0 ; <-- due to reasons, needs to be removed later
  235. #;(error "todo, implement!/4" x y))
  236. (define boole-ior 'todo)
  237. (define boole-and 'todo)
  238. (define-syntax setf
  239. (syntax-rules ()
  240. ((_ var value)
  241. (set! var value))
  242. ((_ var value var* value* . rest)
  243. (begin
  244. (set! var value)
  245. (setf var* value* . rest)))))
  246. (define-syntax-rule (progn x x* ...)
  247. (begin x x* ...))
  248. (define-syntax-rule (flet ((proc args exp) ...)
  249. exp^ exp^* ...)
  250. (let ((proc (lambda args exp)) ...)
  251. exp^ exp^* ...))
  252. (define t #t)
  253. (define-syntax loop*
  254. (syntax-rules ()
  255. ((_ (((x ...) #:in x^) . etc) #:do . rest)
  256. (for-each
  257. (lambda (obj)
  258. (apply (lambda (x ...)
  259. (loop* etc #:do . rest)) obj))
  260. x^))
  261. ((_ ((x #:in x^) . etc) #:do . rest)
  262. (for-each
  263. (lambda (x)
  264. (loop* etc #:do . rest))
  265. x^))
  266. ((_ ((i #:from a #:below b))
  267. #:collect exp)
  268. (let ((from a) (to/exclusive b))
  269. (let loop ((i from))
  270. (if (< i to/exclusive)
  271. (cons exp (loop (1+ i)))
  272. #nil))))
  273. ((_ () #:do . rest)
  274. (begin . rest))
  275. ((_ ((x #:in x^)) #:sum exp)
  276. (let loop ((total 0) (todo x^))
  277. (if (null? todo)
  278. total
  279. (loop (+ total (let ((x (car todo))) exp))
  280. (cdr todo)))))
  281. ((_ #:until stop?
  282. #:collect expression)
  283. (let loop ()
  284. (if stop?
  285. '()
  286. (let ((e expression))
  287. (cons e (loop))))))
  288. ((_ #:until stop?
  289. #:do stuff
  290. #:finally (#:return tail-position))
  291. (let loop ()
  292. (if stop?
  293. tail-position
  294. (loop))))))
  295. (define-syntax loop
  296. (syntax-rules (for in do collect from below while until finally return)
  297. ((_ for i from a below b collect exp)
  298. (loop* ((i #:from a #:below b)) #:collect exp))
  299. ((_ for x in list do stuff)
  300. (loop* ((x #:in list)) #:do stuff))
  301. ((_ until stop? collect stuff)
  302. (loop* #:until stop? #:collect stuff))
  303. ((_ until stop? do stuff finally (return tail-position))
  304. (loop* #:until stop? #:do stuff #:finally (#:return tail-position)))))
  305. ;; We ignore the variable / function
  306. ;; distinction.
  307. (define-syntax defvar
  308. (syntax-rules ()
  309. ((_ name)
  310. (define name))
  311. ((_ name value)
  312. (define name value))
  313. ((_ name value documentation)
  314. (define name value))))
  315. (define-syntax defconstant
  316. (syntax-rules ()
  317. ((_ name value)
  318. (define-syntax name (identifier-syntax value)))
  319. ((_ name value doc)
  320. (define-syntax name (identifier-syntax value)))))
  321. (define (syntax-cadr s)
  322. "Like cadr, but for syntax"
  323. (syntax-case s ()
  324. ((_ . (x . y)) #'x)))
  325. (define (syntax-car s)
  326. "Like car, but for syntax"
  327. (syntax-case s ()
  328. ((x . y) #'x)))
  329. (define (syntax-cdr s)
  330. "Like cdr, but for syntax"
  331. (syntax-case s ()
  332. ((x . y) #'y)))
  333. (define (syntax-map proc s)
  334. "Like map, but for syntax"
  335. (syntax-case s ()
  336. (() #'())
  337. ((x . rest) (cons (proc #'x) (syntax-map proc #'rest)))))
  338. ;; Dotted lists are allowed, in which case the component
  339. ;; after the dot is preserved. (But currently only if
  340. ;; what's after the dot, is an identifier, to avoid silently
  341. ;; introducing bugs.)
  342. (define (list-syntax->syntax-list s)
  343. (syntax-case s ()
  344. (() '())
  345. ((x . rest) (cons #'x (list-syntax->syntax-list #'rest)))
  346. (x (identifier? #'x) #'x)))
  347. (define (syntax->maybe-keyword s)
  348. (let ((d (syntax->datum s)))
  349. (if (keyword? d)
  350. d
  351. s)))
  352. (define-syntax-rule (defgeneric name (arg ...) . extra)
  353. (define-generic name))
  354. (define-syntax destructuring-bind
  355. (lambda (s)
  356. (syntax-case s ()
  357. ((_ () exp exp* exp** ...)
  358. #'(apply (lambda () exp* exp** ...) exp))
  359. ((_ rest exp exp* exp** ...)
  360. (identifier? #'rest)
  361. #'(let ((rest exp)) exp* exp** ...))
  362. ((_ (x . rest) exp exp* exp** ...)
  363. (identifier? #'x)
  364. #'(let* ((args exp))
  365. (destructuring-bind rest (cdr args) exp* exp** ...))))))
  366. (define-syntax-rule (multiple-value-bind args exp exp* ...)
  367. (receive args exp exp* ...))
  368. ;; Specialises in the first argument
  369. (eval-when (load compile eval)
  370. (define (cl->schemy-lambda*-list syntax-list)
  371. (syntax-case syntax-list (&key &optional &rest &body)
  372. (() #'())
  373. ((&key . tail)
  374. #`(#:key . #,(cl->schemy-lambda*-list #'tail)))
  375. ((&optional . tail)
  376. #`(#:optional . #,(cl->schemy-lambda*-list #'tail)))
  377. ((&rest r)
  378. #`(#:rest r))
  379. ;; XXX this is used in defmacro forms sometimes
  380. ;; instead of &rest. Does it mean the same thing?
  381. ((&body r)
  382. #`(#:rest r))
  383. ((something . tail)
  384. #`(something . #,(cl->schemy-lambda*-list #'tail)))
  385. (rest (identifier? #'rest) #'rest))))
  386. (define-syntax defun
  387. (lambda (s)
  388. (syntax-case s ()
  389. ((_ name args exp exp* ...)
  390. (with-syntax ((binders (cl->schemy-lambda*-list #'args)))
  391. #'(define* (name . binders)
  392. exp exp* ...))))))
  393. ;; Guile's (oop goops) does not support keyword argument methods.
  394. ;; Emulate it with rest arguments. (defmethod)
  395. (define (split-keyword-arguments argument-list)
  396. "Split @var{argument-list} into a syntax list of positional arguments
  397. and a syntax list of keyword arguments."
  398. (syntax-case argument-list (&key &rest &optional &body)
  399. (() (values #'() #'()))
  400. ((&key . stuff) (values #'() argument-list))
  401. ((&rest . stuff) (values #'() argument-list))
  402. ((&body . stuff) (values #'() argument-list))
  403. ((x . more)
  404. (receive (positional keywordial)
  405. (split-keyword-arguments #'more)
  406. (values #`(x . #,positional)
  407. keywordial)))))
  408. (define-syntax defmethod
  409. (lambda (s)
  410. (syntax-case s (setf)
  411. ((_ (setf accessor) . rest)
  412. #'(defmethod (setter accessor) . rest))
  413. ;; XXX these aren't exact matches to CLOS object system.
  414. ;; 1. only the most specific around-method should be called.
  415. ;; 3. the after methods should be called from least specific
  416. ;; to most specific.
  417. ((_ name #:after args . rest)
  418. #'(defmethod name args
  419. (next-method)
  420. . rest))
  421. ((_ name #:before args . rest)
  422. #'(defmethod name args
  423. (begin . rest)
  424. (next-method)))
  425. ((_ name #:around args . rest)
  426. #'(defmethod name args . rest))
  427. ((_ name ((first (eql obj)) . rest) exp exp* ...)
  428. ;; XXX for some reason including eql in the literal
  429. ;; list won't work
  430. (eq? 'eql (syntax->datum #'eql))
  431. #'(define-method (name first . rest)
  432. (if (eq? first obj)
  433. (begin exp exp* ...)
  434. (next-method))))
  435. ((_ name arguments exp exp* ...)
  436. (receive (positional keywordial)
  437. (split-keyword-arguments #'arguments)
  438. (syntax-case keywordial ()
  439. (()
  440. ;; No keyword arguments --> trivial
  441. #`(define-method (name . arguments) exp exp* ...))
  442. ((x . y)
  443. ;; Some keyword arguments --> rest argument
  444. (with-syntax ((binders (cl->schemy-lambda*-list keywordial)))
  445. #`(define-method (name #,@positional . rest*)
  446. (apply (lambda* binders exp exp* ...)
  447. rest*))))))))))
  448. ;; Like defmacro, but with define instead of define-syntax.
  449. ;; Also don't eat the first component.
  450. (define-syntax defnotmacro
  451. (lambda (s)
  452. (syntax-case s ()
  453. ((_ name kw-args exp exp* ...)
  454. (with-syntax ((binders (cl->schemy-lambda*-list #'kw-args)))
  455. #`(define (name s*)
  456. (apply (lambda* binders exp exp* ...)
  457. ;; XXX maybe too many arguments are converted
  458. (map syntax->maybe-keyword
  459. (list-syntax->syntax-list s*)))))))))
  460. (define-syntax defmacro
  461. (lambda (s)
  462. (syntax-case s ()
  463. ((_ name kw-args exp exp* ...)
  464. (with-syntax ((binders (cl->schemy-lambda*-list #'kw-args)))
  465. #`(define-syntax name
  466. (lambda (s*)
  467. (defnotmacro proc kw-args exp exp* ...)
  468. (syntax-case s* ()
  469. ((_ . rest) (proc #'rest))))))))))
  470. (define (mapcar proc . lists)
  471. (if (any null? lists)
  472. #nil
  473. (let* ((heads (map car lists))
  474. (tails (map cdr lists))
  475. (first (apply proc heads)))
  476. (cons first (apply mapcar proc tails)))))
  477. (defnotmacro clos-field-syntax->goops (ptr &key
  478. initform
  479. initarg accessor
  480. reader
  481. documentation)
  482. #`(#,ptr #:init-keyword #,initarg
  483. #,@(if accessor #`(#:accessor #,accessor) #'())
  484. #,@(if initform #`(#:init-form #,initform) #'())
  485. #,@(if reader #`(#:getter #,reader) #'())
  486. #:documentation #,documentation))
  487. (define-syntax defclass
  488. (lambda (s)
  489. (syntax-case s ()
  490. ((_ name supers
  491. fields
  492. . unsupported-cl-stuff)
  493. #`(define-class name supers
  494. #,@(syntax-map clos-field-syntax->goops #'fields))))))
  495. ;; Conditions
  496. (define-generic report)
  497. (define-generic make-cl-condition)
  498. (define-syntax-rule (define-report ((condition &type) stream) exp exp* ...)
  499. (define-method (report condition stream)
  500. (if ((condition-predicate &type) condition)
  501. (begin exp exp* ...)
  502. (next-method))))
  503. (defnotmacro define-cl-condition-field-accessors (type name &key
  504. initarg
  505. initform
  506. accessor
  507. reader
  508. documentation)
  509. #`(begin
  510. ;; TODO other fields
  511. #,@(if reader
  512. #`((define (reader c)
  513. (assert (srfi:condition-has-type? c #,type))
  514. (srfi:condition-ref c '#,name)))
  515. #'())))
  516. (define-syntax cl->srfi-initargs
  517. (lambda (s)
  518. ;; A list ((field-A . #:the-initarg) ...),
  519. ;; where FWIW field-A is a syntax (it will be quoted,
  520. ;; not bound to a variable.)
  521. (define (cl-field->cl-field-names+initargs cl)
  522. (syntax-case cl ()
  523. ((field-name . rest)
  524. (let loop ((rest #'rest))
  525. (syntax-case rest ()
  526. ((#:initform form . rest)
  527. (format (current-warning-port)
  528. "initforms for conditions are unsupported (field: ~a)~%"
  529. (syntax->datum #'field-name))
  530. (loop #'rest))
  531. ((#:accessor form . rest)
  532. (format (current-warning-port)
  533. "accessors for conditions are unsupported (field: ~a)~%"
  534. (syntax->datum #'field-name))
  535. (loop #'rest))
  536. ((#:initarg ia . rest)
  537. (keyword? (syntax->datum #'ia))
  538. #`((field-name . #,(datum->syntax #'ia
  539. (keyword->symbol
  540. (syntax->datum #'ia))))
  541. . #,(loop #'rest)))
  542. ((other r . rest)
  543. (memq (syntax->datum #'rest) '(#:reader #:documentation))
  544. (loop #'rest)))))))
  545. (define (names+initargs->argument-names names)
  546. (syntax-map syntax-cdr names))
  547. (define (names+initargs->srfi-list names+initargs)
  548. (syntax-case names+initargs ()
  549. (() #'())
  550. ;; XXX verify this #:initarg for?
  551. (((name . initarg) . rest)
  552. #`(name ,initarg . #,(names+initargs->srfi-list #'rest)))))
  553. (syntax-case s ()
  554. ((_ fields arguments)
  555. (let* ((names+initargs
  556. (syntax-map cl-field->cl-field-names+initargs #'fields))
  557. (argument-names (names+initargs->argument-names names+initargs))
  558. (srfi-list (names+initargs->srfi-list names+initargs)))
  559. #`(apply (lambda* (#:key . #,argument-names)
  560. `#,srfi-list)
  561. arguments))))))
  562. (define-syntax srfi-ify-supertype
  563. (lambda (s)
  564. ;; TODO: adding error to the literal
  565. ;; list doesn't work.
  566. (syntax-case s ()
  567. ((_ name)
  568. (case (syntax->datum #'name)
  569. ((error) #'&error)
  570. (else #'name))))))
  571. (define-syntax define-condition
  572. (lambda (s)
  573. (syntax-case s ()
  574. ((_ type (supertype)
  575. ((field-key . r) ...)
  576. . rest)
  577. #`(begin
  578. (define type
  579. (srfi:make-condition-type 'type
  580. (srfi-ify-supertype supertype)
  581. '(field-key ...)))
  582. ;; TODO investigate
  583. ;; (define-cl-condition-field-accessors field-key . r)
  584. ;; ...
  585. (define-method (make-cl-condition typ . rest*)
  586. (if (eq? typ 'type)
  587. (apply srfi:make-condition typ
  588. (cl->srfi-initargs ((field-key . r) ...) rest*))
  589. (next-method)))
  590. ;; TODO: rest argument
  591. )))))
  592. (define warning &warning)
  593. (define-condition style-warning (warning) ())
  594. ;; Some mess to figure out later.
  595. #|
  596. (import (system foreign) int)
  597. ;; First, define some basic syntax forms.
  598. ;; TODO: ignored forms
  599. (define-syntax-rule (in-package ???)
  600. (begin))
  601. (define-syntax parse-ctype
  602. (syntax-rules (:int)
  603. ((_ :int) int)))
  604. (define-syntax defctype (name type docstring)
  605. (define name (parse-ctype type)))
  606. (define-syntax-rule (defcfun name proc type)
  607. (define type
  608. (let ((cfun (dynamic-func name (dynamic-link))))
  609. (pointer->procedure
  610. |#