define, lambda, define*, lambda*, macro, macro* in s7 vs. tinyscheme

13 views
Skip to first unread message

Minoru

unread,
Jul 3, 2026, 1:37:18 AM (12 days ago) Jul 3
to Extempore
Hi Ben, George and all,

;; evaluated by ver 0.10.1 s7 scheme

;; define* doesn't accept this way of writing ....
(define* yy20
  (lambda a (b 50) (c 60)
          (list a b c)))
;;  -> error
;define*'s first argument, yy20, is a symbol but should be a list: (name ...)
;    (define* yy20 (lambda a (b 50) (c...


;; this way is accepted !
(define* (yy20-1 a (b 50) (c 60))
  (list a b c))

(yy20-1 100) ;(100 50 60)
(yy20-1 100 10) ;(100 10 60)

(get-closure-code yy20-1)
;; (lambda* (a (b 50) (c 60)) (list a b c))

((lambda* (a (b 50) (c 60)) (list a b c))  100) ; (100 50 60) ok


;; Oh, that means ....
;; yes, ok !!
(define yy21
  (lambda* (a (b 200) (c 300))
           (list a b c)))

(yy21 10) ;(10 200 300)
(yy21 10 20) ;(10 20 300)

(get-closure-code yy21)
;; (lambda* (a (b 200) (c 300)) (list a b c))

((lambda* (a (b 200) (c 300)) (list a b c)) 10) ;(10 200 300)  ok


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; macro
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; slice macro
(define-macro (yy52 a . b)
  `(list ,a ,@b))

(yy52 10)    ;(10)
(yy52 10 20) ;(10 20)
(yy52 10 20 30 40) ;(10 20 30 40)

(get-closure-code yy52)
;; (macro (a . b) (#_list-values (#_quote list) a (#_apply-values b)))

((macro (a . b) (#_list-values (#_quote list) a (#_apply-values b)))  10 20 30) ;(10 20 30) ok
 
;; that means .... this way of writing may be accepted ...
(define yy55
  (macro (a)
         `(list ,a)))
;; -> yy55

(yy55 10) ;(10) ok!

(get-closure-code yy55)
;; (macro (a) (#_list-values (#_quote list) a))

((macro (a) (#_list-values (#_quote list) a)) 10)
;; (10) ; oh ok !!


;; that means ... macro* too ???
(define yy56
  (macro* (a)
         `(list ,a)))

(yy56 10) ;(10) ok!
(get-closure-code yy56)
;; (macro* (a) (#_list-values (#_quote list) a))

((macro* (a) (#_list-values (#_quote list) a)) 10)
;; (10) ; oh ok !!


;; usually write as below .....
(define-macro* (yy56-1 a (b 100))
  `(list ,a ,b))

(yy56-1 10) ;(10 100) ok!
(yy56-1) ;(#f 100) ok!
(yy56-1 10 20) ;(10 20) ok!
(get-closure-code yy56-1)
;; (macro* (a (b 100)) (#_list-values (#_quote list) a b))
((macro* (a (b 100)) (#_list-values (#_quote list) a b))  10) ; (10 100) ok!
((macro* (a (b 100)) (#_list-values (#_quote list) a b))  10 20) ; (10 20) ok!


;; this way is ok ....
(define yy56-2
  (macro* (a (b 1000))
         `(list ,a ,b)))

(yy56-2 10) ;(10 1000) ok!
(yy56-2) ;(#f 1000) ok!
(yy56-2 10 20) ;(10 20) ok!
(get-closure-code yy56-2)
;; (macro* (a (b 1000)) (#_list-values (#_quote list) a b))
((macro* (a (b 1000)) (#_list-values (#_quote list) a b))  10) ; (10 1000) ok!
((macro* (a (b 1000)) (#_list-values (#_quote list) a b))  10 20) ; (10 20) ok!



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  evaluated by ver 0.8.9 tinyscheme

;; ver 0.8.9 tinyscheme doesn't have define*, define-macro* ...

(define yy70
  (macro (a)
         `(list ,a)))
;; -> yy70, oh ok??

;; but ....

(yy70 10)
;; -> error
;; illegal function
;; Trace:

(get-closure-code yy70)
;; #f

yy70
;; -> a, not function but argument, maybe

((macro (a) (list 'list a)) 10)
;; illegal function ; ok in s7, though
((macro (a) `(list  ,a)) 10)
;; illegal function ; ok in s7, though

(define yy71
  (macro (b1)
         `(list ,b1)))
;; -> yy71

(yy71 10)
;; illegal function

yy71
;; -> b1,  not function but argument


;; usual way ....
(define-macro (yy72 a)
`(list ,a))

(yy72 10) ; (10) ok

(get-closure-code yy72)
;; (lambda (gensym-89) (apply (lambda (a) (quasiquote (list (unquote a)))) (cdr gensym-89)))

((lambda (gensym-89) (apply (lambda (a) (quasiquote (list (unquote a)))) (cdr gensym-89)))
 10)
;; error

((lambda (a) (quasiquote (list (unquote a))))  10)
;; (list 10)

(eval ((lambda (a) (quasiquote (list (unquote a))))  10))
;; (10)  ok as macro function way !



s7 scheme seems to be more scheme than tinyscheme.
It's consistensy is very nice, I reckong.

(define (name arg1) ... ) =
(define name (lambda (arg1) ...))

(define* (name arg1) .....) =
(define name (lambda* (arg1)  ...))

(define-macro (name arg1) ... ) =
(define name (macro (arg1) ....))

(define-macro* (name arg1) ... ) =
(define name (macro* (arg1) ....))

Minoru

unread,
Jul 3, 2026, 5:43:46 AM (12 days ago) Jul 3
to Extempore
define* or lambda* is vry interesting !   (so, macro*, too)

;; (I like this way of writing .... )

(define yy21
  (lambda* (a (b 200) (c 300))
           (list a b c)))

(yy21 10) ;(10 200 300)
(yy21 10 20) ;(10 20 300)


;; there is option args or nothing,
;;  it is very easy to check by if ...
(define yy22
  (lambda* (a b c)
           (list a b c)))

(yy22 10) ; (10 #f #f)
(yy22)    ; (#f #f #f),  oh not error but #f is returned !
(yy22 1 2 3) ;(1 2 3)


;; that means .....
(define yy23
  (lambda* ((a 100) (b 200)  (c 300))
           (list a b c)))

(yy23) ; (100 200 300) !!  .. as expected .....
(yy23 10) ;(10 200 300)
(yy23 #f 50) ;(#f 50 300)  possible to delete 1st arg, and use only 2nd arg,
             ; control arg's order, too ....

;; then ...
(define yy23-2
  (lambda* ((a 100) (b #f)  (c #f))
           (list a b c)))

(yy23-2) ; (100 #f #f) !!
(yy23-2 10) ;(10 #f #f)
(yy23-2 #f 50) ;(#f 50 #f)
(yy23-2 #f) ;(#f #f #f)


It is easy to controle the number of argument and value of each argument.
In other words, it is possible to ignore/disable each argument in the function, I reckon.
2026年7月3日金曜日 14:37:18 UTC+9 Minoru:
Reply all
Reply to author
Forward
0 new messages