From a8e0c5418598655bdfdda6d5cb541262a5575927 Mon Sep 17 00:00:00 2001 From: Oleh Krehel Date: Fri, 9 Jan 2015 08:33:07 +0100 Subject: [PATCH] Modify reader: #([^"]...) is (short-lambda ...) * src/lread.c (read1): When "#(" is found, check if the next symbol is '"'. If it is, continue with the old string syntax. Otherwise, treat "#(...)" similar to a backquote, except the symbol name is `short-lambda' instead of `backquote'. The indent is to allow to use "#(+ % %)" in place of "(lambda (%) (+ % %))". The simplest implementation: (defmacro short-lambda (structure) `(lambda (%) ,structure)) It could be easily extended to produce "(lambda (%1 %2) (+ %1 %2))" from "#(+ %1 %2)". --- src/lread.c | 65 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/lread.c b/src/lread.c index 3240524..905164f 100644 --- a/src/lread.c +++ b/src/lread.c @@ -2671,34 +2671,42 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) } if (c == '(') { - Lisp_Object tmp; - struct gcpro gcpro1; - int ch; - - /* Read the string itself. */ - tmp = read1 (readcharfun, &ch, 0); - if (ch != 0 || !STRINGP (tmp)) - invalid_syntax ("#"); - GCPRO1 (tmp); - /* Read the intervals and their properties. */ - while (1) - { - Lisp_Object beg, end, plist; - - beg = read1 (readcharfun, &ch, 0); - end = plist = Qnil; - if (ch == ')') - break; - if (ch == 0) - end = read1 (readcharfun, &ch, 0); - if (ch == 0) - plist = read1 (readcharfun, &ch, 0); - if (ch) - invalid_syntax ("Invalid string property list"); - Fset_text_properties (beg, end, plist, tmp); - } - UNGCPRO; - return tmp; + int next_char = READCHAR; + UNREAD (next_char); + if (next_char == '"') { + Lisp_Object tmp; + struct gcpro gcpro1; + int ch; + + /* Read the string itself. */ + tmp = read1 (readcharfun, &ch, 0); + if (ch != 0 || !STRINGP (tmp)) + invalid_syntax ("#"); + GCPRO1 (tmp); + /* Read the intervals and their properties. */ + while (1) + { + Lisp_Object beg, end, plist; + + beg = read1 (readcharfun, &ch, 0); + end = plist = Qnil; + if (ch == ')') + break; + if (ch == 0) + end = read1 (readcharfun, &ch, 0); + if (ch == 0) + plist = read1 (readcharfun, &ch, 0); + if (ch) + invalid_syntax ("Invalid string property list"); + Fset_text_properties (beg, end, plist, tmp); + } + UNGCPRO; + return tmp; + } else { + UNREAD(c); + Lisp_Object value = read0 (readcharfun); + return list2 (Qshort_lambda, value); + } } /* address@hidden is used to skip NUMBER following bytes. @@ -4731,6 +4739,7 @@ that are loaded before your customizations are read! */); DEFSYM (Qcomma, ","); DEFSYM (Qcomma_at, ",@"); DEFSYM (Qcomma_dot, ",."); + DEFSYM (Qshort_lambda, "short-lambda"); DEFSYM (Qinhibit_file_name_operation, "inhibit-file-name-operation"); DEFSYM (Qascii_character, "ascii-character"); -- 1.8.4