Welcome to the CHICKEN Scheme pasting service

no title pasted by buhman on Mon Dec 3 10:25:11 2018

(define-syntax test
  (ir-macro-transformer
   (lambda (exp inject compare)
     (let* ((type (cadr exp))
            (body (cddr exp))
            (get-x (inject (symbol-append (strip-syntax type) '- (strip-syntax 'x))))
            (get-y (inject (symbol-append (strip-syntax type) '- (strip-syntax 'y)))))
       `(let ((thing ,@body))
          (list (,get-x thing) (,get-y thing)))))))

(define-syntax test-outer
  (ir-macro-transformer
   (lambda (exp inject compare)
     (let* ((type (cadr exp))
            (body (cddr exp)))
       `(test ,type ,@body)))))

#;704> (test-outer my-foo (make-foo 1 2))

Error: unbound variable: my-foo-x

	Call history:

	<eval>	  (##sys#list (##core#quote let) (##sys#list (##sys#cons (##core#quote thing) body)) (##sys#list (##co...
	<eval>	  (##sys#list (##sys#cons (##core#quote thing) body))
	<eval>	  (##sys#cons (##core#quote thing) body)
	<eval>	  (##sys#list (##core#quote list) (##sys#list get-x (##core#quote thing)) (##sys#list get-y (##core#qu...
	<eval>	  (##sys#list get-x (##core#quote thing))
	<eval>	  (##sys#list get-y (##core#quote thing))
	<syntax>	  (##core#let ((thing2353278 (make-foo 1 2))) (list2353279 (my-foo-x thing2353278) (my-foo-y thing2353...
	<syntax>	  (##core#begin (list2353279 (my-foo-x thing2353278) (my-foo-y thing2353278)))
	<syntax>	  (list2353279 (my-foo-x thing2353278) (my-foo-y thing2353278))
	<syntax>	  (my-foo-x thing2353278)
	<syntax>	  (my-foo-y thing2353278)
	<syntax>	  (make-foo 1 2)
	<eval>	  (make-foo 1 2)
	<eval>	  [make-foo] (##sys#make-structure (##core#quote foo) x y)
	<eval>	  (list2353279 (my-foo-x thing2353278) (my-foo-y thing2353278))
	<eval>	  (my-foo-x thing2353278)	<--

How to make this work added by sjamaan on Mon Dec 3 10:31:28 2018

(define-record-type foo
  (make-foo x y)
  foo?
  (x foo-x)
  (y foo-y))

(define-syntax test
  (ir-macro-transformer
   (lambda (exp inject compare)
     (let* ((type (cadr exp))
            (body (cddr exp))
            (get-x (inject (symbol-append (strip-syntax type) '- (strip-syntax 'x))))
            (get-y (inject (symbol-append (strip-syntax type) '- (strip-syntax 'y)))))
       `(let ((thing ,@body))
          (list (,get-x thing) (,get-y thing)))))))

(begin-for-syntax
 (define my-type 'foo)) ;; She's just my type

(define-syntax test-outer
  (ir-macro-transformer
   (lambda (exp inject compare)
     (let ((body (cdr exp)))
       `(test ,my-type ,@body)))))

(print (test-outer (make-foo 1 2)))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What type of object does `for-each' expect as second argument?
Visually impaired? Let me spell it for you (wav file) download WAV