add read syntax for #nil
authorAndy Wingo <wingo@pobox.com>
Fri, 9 Apr 2010 12:15:16 +0000 (14:15 +0200)
committerAndy Wingo <wingo@pobox.com>
Fri, 9 Apr 2010 12:15:16 +0000 (14:15 +0200)
* libguile/evalext.c (scm_self_evaluating_p): #nil is self-evaluating.

* libguile/read.c (scm_read_nil, scm_read_sharp): Add read syntax for
  #nil.

libguile/evalext.c
libguile/read.c

index be775a8e1ef0b9d97eb9dc07f89f5ecfa03fe391..b397cbd0540510382d86e4c39d7286885e461262 100644 (file)
@@ -71,7 +71,7 @@ SCM_DEFINE (scm_self_evaluating_p, "self-evaluating?", 1, 0, 0,
       return SCM_BOOL_T;
     case scm_tc3_imm24:
        /* characters, booleans, other immediates */
-      return scm_from_bool (!scm_is_null (obj));
+      return scm_from_bool (!scm_is_null_and_not_nil (obj));
     case scm_tc3_cons:
       switch (SCM_TYP7 (obj))
        {
index ee8786133b18eeca6df4f6a98baf74303d0c8acd..c54fbb62d58cb85ef2e8efdb434c47bd754d518d 100644 (file)
@@ -60,6 +60,7 @@
 SCM_GLOBAL_SYMBOL (scm_sym_dot, ".");
 SCM_SYMBOL (scm_keyword_prefix, "prefix");
 SCM_SYMBOL (scm_keyword_postfix, "postfix");
+SCM_SYMBOL (sym_nil, "nil");
 
 scm_t_option scm_read_opts[] = {
   { SCM_OPTION_BOOLEAN, "copy", 0,
@@ -846,6 +847,19 @@ scm_read_syntax (int chr, SCM port)
   return p;
 }
 
+static inline SCM
+scm_read_nil (int chr, SCM port)
+{
+  SCM id = scm_read_mixed_case_symbol (chr, port);
+
+  if (!scm_is_eq (id, sym_nil))
+    scm_i_input_error ("scm_read_nil", port,
+                       "unexpected input while reading #nil: ~a",
+                       scm_list_1 (id));
+
+  return SCM_ELISP_NIL;
+}
+  
 static inline SCM
 scm_read_semicolon_comment (int chr, SCM port)
 {
@@ -1316,6 +1330,8 @@ scm_read_sharp (scm_t_wchar chr, SCM port)
     case '\'':
     case ',':
       return (scm_read_syntax (chr, port));
+    case 'n':
+      return (scm_read_nil (chr, port));
     default:
       result = scm_read_sharp_extension (chr, port);
       if (scm_is_eq (result, SCM_UNSPECIFIED))