scheme function member

33 views
Skip to first unread message

Minoru

unread,
Jun 9, 2026, 12:59:22 AM (8 days ago) Jun 9
to Extempore
Hi Ben,

My trouble about 'metre:' processing in my macro 'mkplay' is mostly ok now..

This processing uses put and get, so it doesn't work in ver 0.9.3, but it looks like well in ver 0.9.4,
actually it causes no error, but no sounds, why !?!???

(define *metre4* (make-metre '(2 2 4) 1))
(mkplay string1
...
...
'(metre: *metre4* '(1 2 3)))

My macro is expanded to check the value that metre returns as below ...

(if (member (*metre4* beat-n) '(1 2 3))
    play-now)

In ver 0.9.3 this sounds S S, S S, S S S /, .... ;(S=sound, /=no sound) by *metre4* definition.
In ver 0.9.4 doesn't any sounds though mkplay string1 works without error !

Finally I noticed the difference of function 'member' in both versions.

(*metre4* beat-n) returns 1.0000, 2,0 etc

In version 0.8.9
(member 1 '(1 2 3)) ; (1 2 3) means #t
(member 1.0 '(1 2 3)) ; same #t

But, version 0.9.4
(member 1 '(1 2 3)) ; (1 2 3) means #t
(member 1.0 '(1 2 3)) ; #f  THIS IS IT !!!!!!

So I changed the code ....
orginal one
(if (member (*metre4* beat-n) '(1 2 3))
    play-now)

new one
(if (member (truncate (*metre4* beat-n)) '(1 2 3))
    play-now)

then this works well, no error, plays defined sounds by metre func, so I changed some mkplay macro code.
mkplay macro works good again !

Buuut I noticed again, metre func is possible to return 1.5, 2.5 etc, so truncate is not good.

So I changed the 2nd argument just like this ....
(member 1.0 '(1.0 2.0 3.0)) ; (1.000000 2.000000 3.000000), means #t,
OK !

in my mkplay macro ...
(mkplay string1
...
...
'(metre: *metre4* '(1. 2. 3.)))

Ok, it looks like an effective approach for now !
It's nice to change nothing in my macro mkplya code!

I haven't read RnRS about 'member' func yet, so I don't know how member is supposed to be, but I think it is a good prctical solution for this time.

Thanks so much !

Ben Swift

unread,
Jun 10, 2026, 8:27:41 AM (7 days ago) Jun 10
to extemp...@googlegroups.com
Hi Minoru,

Nice debugging --- you pinned down exactly the right thing.

It's a side effect of the move from TinyScheme (0.8.x) to s7 (0.9.x). s7 follows R7RS closely, and there member compares with equal?, which for numbers falls back to eqv?. eqv? treats an exact and an inexact number as different, so (eqv? 1 1.0) is #f --- and therefore so is (member 1.0 '(1 2 3)). The old TinyScheme result (#t) was actually the non-standard one; s7's #f is correct per the spec.

Your fix of using inexact literals in the list is fine. If you'd rather leave the list as integers, s7's member also takes an optional comparison procedure, so you can supply your own test:

(member 1.0 '(1 2 3) =) ; numeric equality, ignores exactness
(member 1.0 '(1 2 3) equivalent?) ; s7's "morally equal", also fine

Both return the matching tail. = is probably the one you want, since your metre values are just numbers --- and a 1.5 still correctly matches nothing.

Glad mkplay is singing again.

Cheers,
Ben
>--
>You received this message because you are subscribed to the Google Groups "Extempore" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to extemporelan...@googlegroups.com.
>To view this discussion visit https://groups.google.com/d/msgid/extemporelang/4c43b311-4dea-4196-89f4-17b9f68572c9n%40googlegroups.com.


--

Cheers,
Ben

Minoru

unread,
Jun 11, 2026, 7:22:20 AM (6 days ago) Jun 11
to Extempore
Hi Ben,

Thank you very much for your comments and nice explanations on my posting ....

Yes I too, had tried member's 3rd argument, then even I had tried to make my own function for this 3rd argument function ..... processing intger/real/exact/inexact etc inclusing random func,  but I decided to use 2nd argument as I wrote above..... in order not to forget values's type/form that metre returns and in order not to rewrite macro code .....

p.s.  Now, I'm struggling with define-macro's optional argument which works well in ver 0.8.9 but not in ver 0.9.4 ....

2026年6月10日水曜日 21:27:41 UTC+9 ben:

Ben Swift

unread,
Jun 11, 2026, 7:29:27 PM (6 days ago) Jun 11
to extemp...@googlegroups.com
Hi Minoru,

Thanks for bearing with the changes between 0.8.x and 0.9.x --- it's no fun when working code suddenly goes quiet on you. The cause is the same each time: 0.8.x used the TinyScheme interpreter, and 0.9.x switched to s7, which follows the Scheme standard (R7RS) much more closely. The member exact/inexact case was one of these --- s7 is doing the correct thing, and TinyScheme had been a bit loose.

So rather than make s7 imitate the old TinyScheme behaviour (which would mean putting the non-standard quirks back), the better path is to nudge these few spots in your code onto the standard idioms. It's usually a small change, and it won't move under you again.

For the define-macro optional argument: s7 keeps plain define-macro strict about its arguments, but gives you define-macro* for exactly this --- optional parameters with defaults:

▎ (define-macro* (my-macro a (b 99))
▎ `(list ,a ,b))

▎ (my-macro 1) ; => (1 99) b takes its default
▎ (my-macro 1 2) ; => (1 2)
▎ If your macro is doing something define-macro* doesn't cover, paste it here and I'll help you port it across.

Cheers,
Ben
>To view this discussion visit https://groups.google.com/d/msgid/extemporelang/5b65c3a5-cbe2-4012-9be5-8c6295ca1cc4n%40googlegroups.com.


--

Cheers,
Ben

Minoru

unread,
Jun 11, 2026, 9:51:14 PM (6 days ago) Jun 11
to Extempore
corrections ....

  intger -> integer
  inclusing -> including
  values's -> values'

2026年6月12日金曜日 8:29:27 UTC+9 ben:

Minoru

unread,
Jun 11, 2026, 10:16:53 PM (6 days ago) Jun 11
to Extempore
Hi Ben,

Of course, I totally agree with you, I will fix the code that doesn't work in ver 0.9... , in line with s7.

Thanks ...

2026年6月12日金曜日 10:51:14 UTC+9 Minoru:
Reply all
Reply to author
Forward
0 new messages