Skip to content
This repository has been archived by the owner on Jan 28, 2018. It is now read-only.

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
zaoqi committed Dec 30, 2017
1 parent c98aa54 commit 08b02f1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions prelude.scm
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@
(define-macro (define-record-type name constructor pred . fields)
(let ([c-fields (cdr constructor)] [c (car constructor)])
(let* ([nf (map (λ (filed)
(cons (first filed) (cons (gensym) (second filed))))
fields)]
(cons (first filed) (cons (gensym) (second filed))))
fields)]
[f-hash (make-immutable-hash nf)])
`(begin
(RECORDz
,pred ,c ,@(map (λ (c-f) (car (hash-ref f-hash c-f))) c-fields))
,@(map (λ (nfe)
(let ([p (cdr nfe)])
`(define ,(cdr p) ,(car p)))) nf)
))))
(RECORDz
,pred ,c ,@(map (λ (c-f) (car (hash-ref f-hash c-f))) c-fields))
,@(map (λ (nfe)
(let ([p (cdr nfe)])
`(define (,(cdr p) x)
(if (,pred x)
,(car p)
(error ,(string-append (symbol->string (cdr p)) ": isn't a " (symbol->string name)) x)
)))) nf)))))
(define-record-type error-object
(error-object message irritants)
error-object?
Expand Down

0 comments on commit 08b02f1

Please sign in to comment.