Advertisement
Void-voiD

Untitled

Dec 9th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. (define (search x s p)
  2. (if (equal? x (car s))
  3. p
  4. (search x (cdr s) (+ p 1))))
  5.  
  6. (define (super-cons x res)
  7. (if (null? x)
  8. (reverse res)
  9. (super-cons (cdr x) (cons (car x) res))))
  10.  
  11. (define-syntax define-struct
  12. (syntax-rules ()
  13. ((_ type (arg . args))
  14. (begin
  15. (eval `(define (,(string->symbol (string-append (string-append (symbol->string 'make) (symbol->string '-)) (symbol->string 'type))) val . vals)
  16. (let ((res '()))
  17. (list->vector (cons 'type (cons val (super-cons vals res)))))) (interaction-environment))
  18. (eval `(define (,(string->symbol (string-append (symbol->string 'type) (symbol->string '?))) x)
  19. (and (vector? x) (equal? 'type (vector-ref x 0)))) (interaction-environment))
  20. (for-each (lambda (i)
  21. (begin
  22. (eval `(define (,(string->symbol (string-append (string-append (symbol->string 'type) (symbol->string '-)) (symbol->string i))) x)
  23. (vector-ref x (+ (search ',i (cons 'arg 'args) 0) 1))) (interaction-environment))
  24. (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)
  25. (vector-set! x (+ (search ',i (cons 'arg 'args) 0) 1) new)
  26. ) (interaction-environment))
  27. )) (cons 'arg 'args))
  28. ))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement