Hi Ben,
Thanks so much for your explanations and ideas,
I didn't know 'define-macro*'.....
I thougt it's a reader macro error when one slash error occurs in read-eval-print loop, too.
Your nice explanations said so then I was convinced ... thanks again !!
The trouble with optional arg is just simple, evaluating the macro func has opt arg or not ....
My macro is ....
(define-macro (mklisgen2 n f . bsp)
(let ((n1 (gensym))
(opt (gensym))
(ans (gensym))
(ans-all (gensym)))
`(let loop ((,n1 ,n)
;; org in ver 0.8.9, but error in ver 0.9.4 when no opt arg.
;; (,opt (if (not (null? ',@bsp)) ,@bsp '())) ; <----
;; 2026-06-13, fixed, ok in ver 0.9.4.
(,opt (if (not (null? ',bsp)) (eval (car ',bsp)))) ; <---
(,ans ,f)
(,ans-all '()))
(if (not (null? ,opt))
(if (number? ,ans) ;single note is a number, chord is a list.
(set! ,ans (+ ,opt ,ans))
(set! ,ans (map (lambda (p) (+ ,opt p))
,ans))))
(if (= ,n1 1)
(reverse (cons ,ans ,ans-all))
(loop (- ,n1 1)
(if (not (null? ,opt)) ,@bsp ,opt)
,f
(cons ,ans ,ans-all))
))))
(mklisgen2 4 (random '(0 4 7)) )
;; -> (4 7 4 0), (7 0 0 7), (4 4 7 7), etc ...
(mklisgen2 4 (random '((0 4 7) (2 5 9) (5 9 4))) )
;; ->((5 9 4) (5 9 4) (2 5 9) (0 4 7)), etc ...
;; if opt arg, it is added to each
(define *bsp* 60)
(mklisgen2 4 (random '((0 4 7) (2 5 9) (5 9 4))) *bsp*)
;; -> ((60 64 67) (65 69 64) (62 65 69) (60 64 67)), etc
(sys:load "libs/core/pc_ivl.xtm")
(mklisgen2 4 (pc:make-chord 60 72 (random 1 4) (random '((0 4 7) (2 5 9) (5 9 4)))))
;; -> ((69) (60 64 67) (64) (65 69)), etc
(define *oct1* '(random '(0 12 -12)))
(mklisgen2 4 (pc:make-chord 60 72 (random 1 4) (random '((0 4 7) (2 5 9) (5 9 4)))) (eval *oct1*))
;; -> ((72) (48 55) (72 76 79) (53 57))
(define *kplus* '(random '(0)))
(define *bsp1* '(+ (eval *kplus*) (random '(60))))
(define *bsp2* '(+ (eval *kplus*) (random '(48 60 72))))
(mklisgen2 3 (random '((0 4 7) (2 5 9) (9 0 4))) (eval *bsp2*))
;; -> ((72 76 79) (50 53 57) (81 72 76)), etc
(mklisgen2 3 (random '((0 4 7) (2 5 9) (9 0 4))) (random '(48 60 72)))
;; same as above
(mklisgen2 3 (pc:diatonic 0 '^ (random '(i ii iv vi))) (eval *bsp2*))
;; ->((74 77 81) (53 57 48) (65 69 60)), etc ...
2026年6月19日金曜日 16:45:26 UTC+9 ben: