--------------------------------------------------------------------
20 lines shortform
--------------------------------------------------------------------
*Claim* (shortform, see section [claim] for details):
An ANSI Conforming Common Lisp implementation *must* execute:
(set-syntax-from-char #\] #\) ) ; => T
(set-syntax-from-char #\[ #\( ) ; => T
[+ 3 2] ; => 5
*Rationales* (shortforms, see sections [derivation <x>] for details):
The standard document defines explicitly:
*Rationale a)* - see section [derivation a]
" A *right-parenthesis* terminates any token, and the
*right-parenthesis-reader macro function* is called no matter where the
*right-parenthesis* appears."
*Rationale b)* - see section [derivation b]
"[...] Upon encountering a *right-parenthesis* the *function READ* calls
the *right-parenthesis-reader macro function*"
*Rationale c)* - see section [derivation c]
" A *right-parenthesis* has an associated function called a reader macro
function that implements its specialized parsing behavior. [...] "
--------------------------------------------------------------------
[claim]
;;;;----------------------------------------------------------------
;;;; The Scary Readtable #V0.5 - ilias - 2002-09-12
;;;;----------------------------------------------------------------
;;; ( ) => [ ] - with CommonLisp conforming code
;;; definitive starting state
;;; activate a fresh standard-readtable
(copy-readtable nil *readtable*)
;;; (copy-readtable nil) creates a fresh standard-readtable
(setq *scary-readtable* (copy-readtable nil) )
;;; activate *scary-readtable*
;;; notice the direction: from-readtable -> to-readtable
(copy-readtable *scary-readtable* *readtable*) ; activates readtable
;;; following code modifies the *scary-readtable*
(set-syntax-from-char #\] #\) ) ;
(set-syntax-from-char #\[ #\( ) ;
;;; syntax is now non-conforming (but legal)
(+ 3 2) ; => 5
[+ 3 2] ; => 5 [the main point]
(eql (get-macro-character #\() (get-macro-character #\[) ) ; =>T
(eql (get-macro-character #\)) (get-macro-character #\]) ) ; =>T
;;; the char-code muste be still different
(eql #\) #\] ) ;;=> nil
(eql #\( #\[ ) ;;=> nil
(copy-readtable nil *readtable*) ; restore standard-syntax
;;; syntax is conforming again
(+ 3 2) ; => 5
[+ 3 2] ; [original behaviour], some error
(eql (get-macro-character #\() (get-macro-character #\[) ) ; => nil
(eql (get-macro-character #\)) (get-macro-character #\]) ) ; => nil
(eql #\) #\] ) ;;=> nil
(eql #\( #\[ ) ;;=> nil
;;;-----------------------------------------------------------------
[ *claim 1* : the #\) reader macro function *must* be called. ]
[ *claim 2* : READ *is* the function that *must* be used for
reading in the right paren ]
[ *claim 3* : the #\) reader macro *must* be used to signal
its occurrence to the #\( reader-macro]
;;;-----------------------------------------------------------------
=====================================================================
[derivations]:
=====================================================================
---------------------------------------------------------------------
*initial definitions*:
---------------------------------------------------------------------
http://www.lispworks.com/reference/HyperSpec/Body/02_d.htm
"The macro characters defined initially in a conforming implementation
include the following:
[...]
2.4.2 Right-Parenthesis
[...] "
=> *Right-Parenthesis* is defined as *macro character*.
http://www.lispworks.com/reference/HyperSpec/Body/02_ad.htm
"[...] ) terminating macro char [...] "
=> *Right-Parenthesis* is defined as *terminating* macro character
http://www.lispworks.com/reference/HyperSpec/Body/26_glo_l.htm#lisp_r...
"Lisp reader n. Trad. the procedure that parses character
representations of objects from a stream, producing objects. (This
procedure is implemented by the function read.)"
=> The *Lisp reader* is defined to be implemented by the *function READ*
---------------------------------------------------------------------
Some of the many resulting possible concretisations:
a macro character =>a right-parenthesis
a terminating macro character => a right-parenthesis
the Lisp reader => the function READ
---------------------------------------------------------------------
*[derivation a]*
---------------------------------------------------------------------
*The general definition of the terminating macro characters:*
http://www.lispworks.com/reference/HyperSpec/Body/02_add.htm
4th paragraph, at the end:
"[...] A terminating macro character terminates any token, and its
associated reader macro function is called no matter where the character
appears. [...]"
concretisation to right-parenthesis:
" A *right-parenthesis* terminates any token, and the
*right-parenthesis-reader macro function* is called no matter where the
*right-parenthesis* appears."
This proofs: [ *claim 1* : the #\) reader macro function *must* be called. ]
---------------------------------------------------------------------
*[derivation b]*
---------------------------------------------------------------------
*The general definition of the macro characters:*
http://www.lispworks.com/reference/HyperSpec/Body/02_add.htm
3rd paragraph:
"[...] Upon encountering a macro character, the Lisp reader calls its
reader macro function, which parses one specially formatted object from
the input stream. The function either returns the parsed object, or else
it returns no values to indicate that the characters scanned by the
function are being ignored (e.g., in the case of a comment). Examples of
macro characters are backquote, single-quote, left-parenthesis, and
right-parenthesis. [...]"
*concretisation to right-parenthesis:*
"[...] Upon encountering a *right-parenthesis* the *function READ* calls
the *right-parenthesis-reader macro function*"
This poofs: [ *claim 2* : READ *is* the function that *must* be used for
reading in the right paren ]
---------------------------------------------------------------------
*[derivation c]*
---------------------------------------------------------------------
*The general definition of the macro characters:*
http://www.lispworks.com/reference/HyperSpec/Body/02_add.htm
2nd paragraph
" A macro character has an associated function called a reader macro
function that implements its specialized parsing behavior. An
association of this kind can be established or modified under control of
a conforming program by using the functions set-macro-character and
set-dispatch-macro-character."
*concretisation to right-parenthesis:*
" A *right-parenthesis* has an associated function called a reader macro
function that implements its specialized parsing behavior. [...] "
this proofs: [ *claim 3* : the #\) reader macro *must* be used to signal
its occurrence to the #\( reader-macro]
-
=========================================================================
The main arguments *against* the claim:
=========================================================================
*The definition of left-parenthesis:*
*[rejoinder a]*
http://www.lispworks.com/reference/HyperSpec/Body/02_da.htm
" The left-parenthesis initiates reading of a list. read is called
recursively to read successive objects until a right parenthesis is
found in the input stream. "
This definition of left-parenthesis is then referenced in...
*The definition of set-syntax-from-char:*
[Remark: the text in the specs refers to {} but can be applied identical
to the [] pair, which has been chosen for better visibility ]
*[rejoinder b]*
http://www.lispworks.com/reference/HyperSpec/Body/f_set_sy.htm
" The definition of ( can not be meaningfully copied to {, on the other
hand. The result is that lists are of the form {a b c), not {a b c},
because the definition always looks for a closing parenthesis, not a
closing brace."
"[..] because the *definition* always looks[...]" refers to the
definition of left-parenthesis.
[rejoinder b] depends on [rejoinder a].
So i focus on [rejoinder a].
=========================================================================
"1.5.1.4.1 Resolution of Apparent Conflicts in Exceptional Situations"
=========================================================================
http://www.lispworks.com/reference/HyperSpec/Body/01_eada.htm
" If more than one passage in this specification appears to apply to the
same situation but in conflicting ways, the passage that appears to
describe the situation in the most specific way (not necessarily the
passage that provides the most constrained kind of error detection)
takes precedence. "
=========================================================================
The passages under [Rationale a,b,c] describe the situation in the most
specific way. They define explicitly and undoubtable.
Whereas the passage under [rejoinder a] is unspecific.
But even if you take [rejoinder a]:
[rejoinder a]
" The left-parenthesis initiates reading of a list. read is called
recursively to read successive objects until a right parenthesis is
found in the input stream. "
The term *left-parenthesis* refers to the *definition of
left-parenthesis* or more precise to the
*syntax-definition-of-left-parenthesis*.
Simple Rationale:
The *syntax-definition-of-left-parenthesis* initiates the reading of a
list *not* the character *left-parenthesis* itself.
Conclusion:
The term *right parenthesis* in the same sentence refers to
*syntax-definition-of-right-parenthesis* and not to the character
*right-parenthesis*.
Simple Backup:
http://www.lispworks.com/reference/HyperSpec/Body/02_ad.htm
[...] The syntax type of a character in a readtable determines how that
character is interpreted by the Lisp reader [...]
-------------------------------------------------------------------------
I think i've done
...
read more »