tags:

views:

652

answers:

3

Berkeley's "CS 61A Lecture 8: UI Recursion and Iteration III" says that null? checks if the list is empty and empty? checks if the list is empty or the word is empty? The lecturer also goes on to say (null? empty) will return false. But DrScheme doesnt mind at all.

What is the difference between null? and empty? in Scheme?

+3  A: 

No difference (in my favorite dialect -- empty? is not in the standard, and it's too long since I used any different dialect;)...! Quoting PLT scheme docs:

(null? v) → boolean?
  v : any/c

Returns #t if v is the empty list, #f otherwise.

and

(empty? v) → boolean?
  v : any/c

The same as (null? v).
Alex Martelli
Is empty defined only in PLTScheme?
kunjaan
It's not in the standard, AFAIK, and it's been far too long since I used any other dialect - I'd better edit the answer to hint at that!-)
Alex Martelli
whats your fav dialect?
kunjaan
PLT (or DRScheme but that's the same bundle;-).
Alex Martelli
+3  A: 

Neither R5RS nor R6RS defines empty? as a predicate, and both define null? as follows:

Returns #t if obj is the empty list, otherwise returns #f.

Greg Hewgill
A: 

empty? is specific to PLT Scheme; it is the same as null?.

grettke