scheme

Difference between null? and empty? in Scheme


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?


Solution

  • 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).