[CM] Possible bug in `member`
Woody Douglass
wdouglass at carnegierobotics.com
Wed Dec 8 11:41:18 PST 2021
Hello,
I believe i may have found a bug
consider the following code, which searches a list of names by
substring:
```
(let* ((records (list
(inlet :person "oscar meyer")
(inlet :person "howard johnson")
(inlet :person "betty crocker")))
(match-record (lambda (name record)
(format (current-error-port) "COMPARE '~A' '~A'~%" name (record 'person))
(let ((vname (record 'person)))
(equal? name (substring vname 0 (min (length name) (length vname)))))))
(find-record (lambda (name)
(format (current-error-port) "FINDING ~A~%" name)
(let* ((found (member name records match-record)))
(if found
(car found)
#f)))))
(format #t "~A~%" (find-record "betty")))
```
I expect that code to print one line for each comparison, and the `a`
argument to `match-record` to be "betty". instead, as of git revision
b8d66a23084183b97139e49d1867638cd39a2808 this excerpt prints
```
FINDING betty
COMPARE 'betty' 'oscar meyer'
COMPARE 'oscar meyer' 'howard johnson'
COMPARE 'howard johnson' 'betty crocker'
#f
```
The compares are being rotated in a way that, to me, looks like a
stacking bug. my s7 instance in this case is compiled with
```
gcc -g3 -Wall -c -o s7.o s7.c
gcc -o repl repl.o s7.o -lm -I. -ldl -Wl,-export-dynamic
```
Is this a bug in s7? do i completely misunderstand how `member` works?
Thanks for any advice,
Woody Douglass
More information about the Cmdist
mailing list