Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between null? and empty? in Scheme

Tags:

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?

like image 841
unj2 Avatar asked Jun 04 '09 02:06

unj2


People also ask

What is the difference between null and empty list?

An empty collection isn't the same as null . An empty collection is actually a collection, but there aren't any elements in it yet. null means no collection exists at all.

What does the dot mean in scheme?

The dot symbol is displayed when you build a cons -pair or a list which is not proper (meaning: it doesn't end with the empty list).


1 Answers

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).
like image 122
Alex Martelli Avatar answered Oct 25 '22 21:10

Alex Martelli