Hi, 
I'm trying to program a macro which defines different selectors for mutable 
pairs.
I know in Racket it's possible to use only mcar and mcdr, but mcdar etc. could 
be useful for me.

I would like to use macro this way: 

(with-mcxrs
  (let ((a (mcons (mcons 1 2) (mcons (mcons 3 4) '()))))
   (list (mcaar a)
         (mcdar a)
         (mcaadr a)
         (mcdadr a))))

Mcxrs will be defined in macro's body and then whole expresion would be 
evaluated - now with bindings in macro's environment so no error should appear.
I think procedure seek and macro defines3 are ok (when using separately they 
work fine) but in a macro "with-mcxrs" an error appears: mcaar undefined. 
Where's the problem? I can't figure it out. I would be glad if anyone could 
give me some advice. 

And could "defines3" be out of macro "with-mcxrs"? Or should it be inside - 
like in my code? 
Thanks a lot.

Code:
 first I go though whole body and I store found mcxrs in list, which is called 
"selectors" in let loop. And then call another macro "defines3" which should 
return procedure - for example: (lambda (pair) (mcar (mcdr (mcar pair)))). And 
this procedure should be defined as a value of particular mcaar or mcdar etc.

(define-macro with-mcxrs
  (lambda body

    `(define-macro defines3     
  (lambda (chars)
    (let ((loop (gensym)))
      `(lambda (pair)
         (let ,loop ((chsez ,chars))
           (if (null? chsez)
               pair
               (if (equal? (car chsez) #\a)
                   (mcar (,loop (cdr chsez)))
                   (mcdr (,loop (cdr chsez)))) ))))))

    (define seek2       
      (let ((pom '() ))
        (lambda (l)
          (cond ((null? l) pom )
                ((list? (car l)) (begin(seek2 (car l))
                                       (seek2 (cdr l))) )
                (else
                 (if (not (symbol? (car l)))
                     (seek2 (cdr l))
                     (let* ((test (symbol->string(car l)))
                            (len (string-length test)))
                       (if (> len 4)
                           (if (or (equal? (substring test 0 3) "mca")
                                   (equal? (substring test 0 3) "mcd"))
                               (begin 
                                 (set! pom (cons (car l) pom) )
                                 (seek2 (cdr l)))
                               (seek2 (cdr l)))
                           (seek2 (cdr l)) ))))))))

    (let ((loop (gensym)))
      `(let ,loop ((selectors (,seek2 (quote ,@body)) )) ;;list of selectors
        (cond ((null? selectors) (,@body))
              (else
                (define (car selectors)
                 (defines3 (string->list
                            (substring (car l) 2
                                    (- (string-length (car l))1)) )))
               (,loop (cdr selectors))) )))  ))


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to