1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 19:50:24 +02:00

add read syntax for #nil

* 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.
This commit is contained in:
Andy Wingo 2010-04-09 14:15:16 +02:00
parent c1b7c940ec
commit 7c4aad9cc7
2 changed files with 17 additions and 1 deletions

View file

@ -71,7 +71,7 @@ SCM_DEFINE (scm_self_evaluating_p, "self-evaluating?", 1, 0, 0,
return SCM_BOOL_T; return SCM_BOOL_T;
case scm_tc3_imm24: case scm_tc3_imm24:
/* characters, booleans, other immediates */ /* 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: case scm_tc3_cons:
switch (SCM_TYP7 (obj)) switch (SCM_TYP7 (obj))
{ {

View file

@ -60,6 +60,7 @@
SCM_GLOBAL_SYMBOL (scm_sym_dot, "."); SCM_GLOBAL_SYMBOL (scm_sym_dot, ".");
SCM_SYMBOL (scm_keyword_prefix, "prefix"); SCM_SYMBOL (scm_keyword_prefix, "prefix");
SCM_SYMBOL (scm_keyword_postfix, "postfix"); SCM_SYMBOL (scm_keyword_postfix, "postfix");
SCM_SYMBOL (sym_nil, "nil");
scm_t_option scm_read_opts[] = { scm_t_option scm_read_opts[] = {
{ SCM_OPTION_BOOLEAN, "copy", 0, { SCM_OPTION_BOOLEAN, "copy", 0,
@ -846,6 +847,19 @@ scm_read_syntax (int chr, SCM port)
return p; 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 static inline SCM
scm_read_semicolon_comment (int chr, SCM port) scm_read_semicolon_comment (int chr, SCM port)
{ {
@ -1316,6 +1330,8 @@ scm_read_sharp (scm_t_wchar chr, SCM port)
case '\'': case '\'':
case ',': case ',':
return (scm_read_syntax (chr, port)); return (scm_read_syntax (chr, port));
case 'n':
return (scm_read_nil (chr, port));
default: default:
result = scm_read_sharp_extension (chr, port); result = scm_read_sharp_extension (chr, port);
if (scm_is_eq (result, SCM_UNSPECIFIED)) if (scm_is_eq (result, SCM_UNSPECIFIED))