Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (search x s p)
- (if (equal? x (car s))
- p
- (search x (cdr s) (+ p 1))))
- (define (super-cons x res)
- (if (null? x)
- (reverse res)
- (super-cons (cdr x) (cons (car x) res))))
- (define-syntax define-struct
- (syntax-rules ()
- ((_ type (arg . args))
- (begin
- (eval `(define (,(string->symbol (string-append (string-append (symbol->string 'make) (symbol->string '-)) (symbol->string 'type))) val . vals)
- (let ((res '()))
- (list->vector (cons 'type (cons val (super-cons vals res)))))) (interaction-environment))
- (eval `(define (,(string->symbol (string-append (symbol->string 'type) (symbol->string '?))) x)
- (and (vector? x) (equal? 'type (vector-ref x 0)))) (interaction-environment))
- (for-each (lambda (i)
- (begin
- (eval `(define (,(string->symbol (string-append (string-append (symbol->string 'type) (symbol->string '-)) (symbol->string i))) x)
- (vector-ref x (+ (search ',i (cons 'arg 'args) 0) 1))) (interaction-environment))
- (eval `(define (,(string->symbol (string-append (string-append (string-append (string-append (string-append (string-append (symbol->string 'set) (symbol->string '-)) (symbol->string 'pos))) (symbol->string '-)) (symbol->string i)) (symbol->string '!))) x new)
- (vector-set! x (+ (search ',i (cons 'arg 'args) 0) 1) new)
- ) (interaction-environment))
- )) (cons 'arg 'args))
- ))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement