GNU bug report logs -
#33036
Bug with the procedure nil? inside a specific code
Previous Next
Reported by: calcium <calcium <at> disroot.org>
Date: Sat, 13 Oct 2018 18:20:02 UTC
Severity: normal
Done: Mark H Weaver <mhw <at> netris.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Fri, 19 Oct 2018 21:13:14 -0400
with message-id <87zhv94dzp.fsf <at> netris.org>
and subject line Re: bug#33036: Bug with the procedure nil? inside a specific code
has caused the debbugs.gnu.org bug report #33036,
regarding Bug with the procedure nil? inside a specific code
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
33036: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=33036
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Order of content:
1] --- Setup information
2] --- what is the procedure nil?
3] --- snippet of code that trigger the bug
4] --- snippet of code that doesn't trigger the bug
5] --- Summary and end
1] ---
Setup :
$ ./config.guess
x86_64-pc-linux-gnu
$ guile --version
guile: warning: failed to install locale
guile (GNU Guile) 2.2.3
etc ...
-> Guile was installed in a foreign Gnu/Linux distribution via Guix.
2] ---
The procedure nil? is not listed in the procedure index :
https://www.gnu.org/software/guile/docs/docs-2.0/guile-ref/Procedure-Index.html
There is a page that speak about nil :
https://www.gnu.org/software/guile/manual/html_node/Nil.html
However it doesn’t mention the nil? Procedure
The only documentation that I found about nil? is this one :
(procedure-documentation nil?)
=> "- Scheme Procedure: nil? x\n Return `#t' iff X is nil, else
return `#f'."
(procedure-documentation null?)
=> "- Scheme Procedure: null? x\n Return `#t' iff X is the empty
list, else `#f'."
The procedure documentation is not the same for nil? and null?
They seem nonetheless to be the same.
(null? #nil)
=> #t
(null? ‘())
=> #t
(nil? #nil)
=> #t
(nil? '())
=> #t
3] ---
Here is the bug that I found :
;;; -START- code with the bug -START- ;;;
(define (strange lst)
(let loop ((lst lst)
(is-empty '()))
(cond ((nil? lst)
(if (nil? is-empty) 'works
(list 'should-not-occur is-empty)))
(else
(loop (cdr lst)
is-empty)))))
(strange '())
=> (should-not-occur ())
(strange #nil)
=> (should-not-occur ())
;;; -END- code with the bug -END- ;;;
4] ---
And here follows 3 version that doesn’t trigger this bug.
;;; in this one we remove the call to the loop in the else clause
;;; -START- code that works (1) -START- ;;;
(define (not-strange-1 lst)
(let loop ((lst lst)
(is-empty '()))
(cond ((nil? lst)
(if (nil? is-empty) 'works
(list 'should-not-occur is-empty)))
(else
'no-more-bug))))
(not-strange-1 '())
=> works
(not-strange-1 #nil)
=> works
;;; -END- code that works (1) -END- ;;;
;;; we change the ‘() of is-empty to #nil
;;; -START- code that works (2) -START- ;;;
(define (not-strange-2 lst)
(let loop ((lst lst)
(is-empty #nil))
(cond ((nil? lst)
(if (nil? is-empty) 'works
(list 'should-not-occur is-empty)))
(else
(loop (cdr lst)
is-empty)))))
(not-strange-2 '())
=> works
(not-strange-2 #nil)
=> works
;;; -END- code that works (2) -END- ;;;
;;; if we use null? instead of nil? at the critical point (nil? is-empty)
;;; -START- code that works (3) -START- ;;;
(define (not-strange-3 lst)
(let loop ((lst lst)
(is-empty '()))
(cond ((nil? lst)
(if (null? is-empty) 'works
(list 'should-not-occur is-empty)))
(else
(loop (cdr lst)
is-empty)))))
(not-strange-3 '())
=> works
(not-strange-3 #nil)
=> works
;;; -END- code that works (3) -END- ;;;
5] ---
So in summary :
1) removing the call to the loop in the else clause remove the bug.
This is interesting because we don’t enter the else clause
2) using the #nil instead of ‘() did change the outcome.
But except for this case, it doesn't seem to change the outcome to use
#nil or ‘()
3) using null? Instead of nil? did change the outcome.
This is similar to point 2. except that we change the procedure instead
of the value.
I think that there is 2 way to look at this bug:
The first one is to consider that it is a bug because nil? and null?
should give the same answer.
The second one is to consider that nil? should only answer #t when we
use it with #nil, and otherwise give #f (this include ‘() ).
---
If you require any further information or did not understand what I
said, feel free to contact me at calcium <at> disroot.org
[Message part 3 (message/rfc822, inline)]
Hi Andy,
Andy Wingo <wingo <at> pobox.com> writes:
> Thank you, Mark! That looks great.
Great, thanks for looking it over. I pushed it to the stable-2.2 branch
as commit c3e14b74e81d0fd3266b97e6bd629cd4e2f98803.
I'm closing this bug now, but feel free to reopen if appropriate.
Thanks!
Mark
This bug report was last modified 6 years and 218 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.