/* Symbol printer. NB: Uninterned symbols are treated as sharable objects (can be written with #n= syntax). It is handled by upper layer (write.c) so we don't worry about it in this routine. */ static void symbol_print(ScmObj obj, ScmPort *port, ScmWriteContext *ctx) { if (Scm_WriteContextMode(ctx) == SCM_WRITE_DISPLAY) { SCM_PUTS(SCM_SYMBOL_NAME(obj), port); } else { #if !GAUCHE_UNIFY_SYMBOL_KEYWORD if (SCM_KEYWORDP(obj)) { SCM_PUTC(':', port); /* We basically print keyword names in the same way as symbols (i.e. using |-escape if necessary). However, as a convention, two things are different from the default symbol writer. (1) We don't check the noninitials; :1 is unambiguously a keyword, so we don't need to print :|1|. (2) A keyword with an empty name can be printed just as :, instead of :||. These conventions are useful if we pass the S-expression with these keywords to other Scheme implementations that don't support CL-style keywords; they would just read those ones as symbols. */ Scm_WriteSymbolName(SCM_KEYWORD(obj)->name, port, ctx, (SCM_SYMBOL_WRITER_NOESCAPE_INITIAL |SCM_SYMBOL_WRITER_NOESCAPE_EMPTY)); return; } #endif /*!GAUCHE_UNIFY_SYMBOL_KEYWORD*/ if (!SCM_SYMBOL_INTERNED(obj)) SCM_PUTZ("#:", -1, port); Scm_WriteSymbolName(SCM_SYMBOL_NAME(obj), port, ctx, 0); } }
/* Symbol comparison procedure. Will be used via 'compare' procedure. Following srfi-114, we compare by name, but takes extra care of intern/unintern distinction; if the names are the same, interned symbol is less, and if both are uninterned, we compare addresses. */ static int symbol_compare(ScmObj x, ScmObj y, int equalp) { if (equalp) { /* Symbol equality test is handled in Scm_Eq* and will never come here, but just in case. */ return SCM_EQ(x, y)? 0:1; } else if (SCM_EQ(x, y)) { return 0; } else { int r = Scm_StringCmp(SCM_SYMBOL_NAME(x), SCM_SYMBOL_NAME(y)); if (r != 0) return r; if (SCM_SYMBOL_INTERNED(x)) return -1; /* y must be uninterned */ if (SCM_SYMBOL_INTERNED(y)) return 1; /* x must be uninterned */ return (x < y)? -1 : 1; /* both are uninterned */ } }
/* Symbol printer. NB: Uninterned symbols are treated as sharable objects (can be written with #n= syntax). It is handled by upper layer (write.c) so we don't worry about it in this routine. */ static void symbol_print(ScmObj obj, ScmPort *port, ScmWriteContext *ctx) { if (Scm_WriteContextMode(ctx) == SCM_WRITE_DISPLAY) { SCM_PUTS(SCM_SYMBOL_NAME(obj), port); } else { if (!SCM_SYMBOL_INTERNED(obj)) SCM_PUTZ("#:", -1, port); Scm_WriteSymbolName(SCM_SYMBOL_NAME(obj), port, ctx, 0); } }