i try to set up a macro in biwascheme:
(define-macro (do b1 . Larg)
(let ((lst (gensym)) ;; list
(rev-lst (gensym)) ;; reversed list
(pred (gensym)) ;; predicate
(q-while (gensym)) ;; MUST be (quote while)
(lst-instr (gensym))) ;; instructions to execute list
(print "do")
`(let loop ((,lst (cons
(quote ,b1)
(quote ,Larg))) ;; list
(,rev-lst '()) ;; reversed list
(,pred '()) ;; predicate
(,q-while '()) ;; MUST be (quote while)
(,lst-instr '())) ;; instructions to execute list
(print "passed")
(if (< (length ,lst) 2)
(print "ERROR: too few arguments: must not be less than 2")
(begin
(set! ,rev-lst (reverse ,lst))
(print ,rev-lst)
(set! ,pred (car ,rev-lst))
(set! ,q-while (car (cdr ,rev-lst)))
(print ,pred)
(print ,q-while)
(print "passed")
(if (not
(or (equal? ,q-while '(quote while))
(equal? ,q-while '(quote WHILE))))
(print "ERROR: WHILE key-word not found")
(begin
(print "passed 2")
(set! ,lst-instr (reverse
(cdr
(cdr ,rev-lst))))
(print "passed set!")
(print ,lst-instr)
(begin
,@lst-instr)
(when ,pred (loop)))))))))
it crashed on the unquote-splicing at the end....
any ideas?
when macro is working well and use also unquote-splicing
(define-macro (when test s1 . Larg)
`(if ,test
(begin ,s1 ,@Larg)
#f))
i use the macro this way:
(define i 0)
(do (print "hello") (set! i (+ i 1)) 'while (< i 4))
Damien