Page 61: the example with the member function. This statement in the book is actually not true: "...the member function still gives the correct answer, even when we search for nil as the member!"

62 views
Skip to first unread message

Shafique

unread,
Aug 24, 2012, 9:31:42 AM8/24/12
to land-o...@googlegroups.com
This seems to be true for the example given, but not universally true. Try the following:

(if (member nil '(3 4 1 nil)))
    'nil-is-in-the-list
    'nil-is-not-in-the-list)

The member function will return nil even though nil is in the list (I tested this).

Any thoughts?
 

Archie Maskill

unread,
Aug 24, 2012, 9:45:21 AM8/24/12
to land-o...@googlegroups.com
On Fri, Aug 24, 2012 at 2:31 PM, Shafique <shafiqu...@gmail.com> wrote:
> (if (member nil '(3 4 1 nil)))
> 'nil-is-in-the-list
> 'nil-is-not-in-the-list)
>
> The member function will return nil even though nil is in the list (I tested
> this).

Are you sure that member is returning nil?
For me, in the example you gave, member returns '(nil), which is
different from nil.

Archie

Shafique

unread,
Aug 24, 2012, 12:47:41 PM8/24/12
to land-o...@googlegroups.com, archie....@gmail.com
Hello Archie,

Many thanks for responding. I don't know what I'm doing wrong. When I entered that line, the output was the second of the options, and it prints FALSE (so I guess it is returning FALSE instead of '(nil) ).

I have attached a screenshot (see attached)... am I missing something simple?
Screen shot 2012-08-24 at 9.43.51 PM.png

Archie Maskill

unread,
Aug 24, 2012, 5:02:00 PM8/24/12
to land-o...@googlegroups.com
Hi Shafique,

In your screenshot, towards the top, you have made a typo. You wrote
"nul" instead of "nil":

(if (member nil '(3 4 1 nul))
'nil-is-in-the-list
'nil-is-not-in-the-list)

Therefore, nil is not found in the list, and the second of the options
is printed.

In your second example:
(if (member nil '(3 4 1 nil))
'false
'true)

nil is found in '(3 4 1 nil), so member returns the tail, which is
'(nil). This evaluates to true (because it is not nil), and therefore
the first option is returned, which you've specified to be the symbol
'false (which might be what is confusing you!)

Archie

Shafique

unread,
Aug 25, 2012, 2:31:11 AM8/25/12
to land-o...@googlegroups.com, archie....@gmail.com
Aha- got it now! Many thanks again, Archie, for taking the time to look through the screenshot and catching the typo. I very much appreciate it!
Reply all
Reply to author
Forward
0 new messages