1
0
Fork 0
cl-sites/novaspec.org/cl/f_set-macro-character.html
2025-02-05 18:52:26 +01:00

446 lines
No EOL
9.4 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>set-macro-character, get-macro-character | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_set-macro-character.html"
><LINK REL="next" HREF="f_set-syntax-from-char.html" TYPE="text/html" TITLE="set-syntax-from-char"
><LINK REL="prev" HREF="f_set-dispatch-macro-character.html" TYPE="text/html" TITLE="set-dispatch-macro-character, get-dispatch-macro-character"
><LINK REL="up" HREF="23_2_Reader_Dictionary.html" TYPE="text/html" TITLE="23.2 Reader Dictionary"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="23_Reader.html"
>23. Reader</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="23_2_Reader_Dictionary.html"
>23.2 Reader Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_set-macro-character.html"
>set-macro-character, get-macro-character</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_set-dispatch-macro-character.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="f_set-syntax-from-char.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><DIV CLASS="com"
><DIV CLASS="begincom"
><HR
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="set-macro-character, get-macro-character"
></SPAN
><B
>set-macro-character, get-macro-character</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Function</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><P CLASS="j"
><B
>get-macro-character</B
> <SPAN CLASS="cmssi"
>char</SPAN
> <SPAN CLASS="cmtt"
>&amp;optional</SPAN
> <SPAN CLASS="cmssi"
>readtable</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="cmssi"
>function,</SPAN
> <SPAN CLASS="cmssi"
>non-terminating-p</SPAN
></P
><P CLASS="j"
><B
>set-macro-character</B
> <SPAN CLASS="cmssi"
>char</SPAN
> <SPAN CLASS="cmssi"
>new-function</SPAN
> <SPAN CLASS="cmtt"
>&amp;optional</SPAN
> <SPAN CLASS="cmssi"
>non-terminating-p</SPAN
> <SPAN CLASS="cmssi"
>readtable</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="misc"
><B
>t</B
></SPAN
></P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>char</VAR
> &#8212; a <A HREF="26_1_Glossary.html#character"
><EM CLASS="term"
>character</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>non-terminating-p</VAR
> &#8212; a <A HREF="26_1_Glossary.html#generalized_boolean"
><EM CLASS="term"
>generalized boolean</EM
></A
>. The default is <A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>readtable</VAR
> &#8212; a <A HREF="26_1_Glossary.html#readtable_designator"
><EM CLASS="term"
>readtable designator</EM
></A
>. The default is the <A HREF="26_1_Glossary.html#current_readtable"
><EM CLASS="term"
>current readtable</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>function</VAR
> &#8212; <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>, or a <A HREF="26_1_Glossary.html#designator"
><EM CLASS="term"
>designator</EM
></A
> for a <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> of two <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>arguments</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>new-function</VAR
> &#8212; a <A HREF="26_1_Glossary.html#function_designator"
><EM CLASS="term"
>function designator</EM
></A
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
><A HREF="f_set-macro-character.html" CLASS="funref"
><B
>get-macro-character</B
></A
> returns as its <A HREF="26_1_Glossary.html#primary_value"
><EM CLASS="term"
>primary value</EM
></A
>, <VAR CLASS="param"
>function</VAR
>, the <A HREF="26_1_Glossary.html#reader_macro_function"
><EM CLASS="term"
>reader macro function</EM
></A
> associated with <VAR CLASS="param"
>char</VAR
> in <VAR CLASS="param"
>readtable</VAR
> (if any), or else <SPAN CLASS="misc"
><B
>nil</B
></SPAN
> if <VAR CLASS="param"
>char</VAR
> is not a <A HREF="26_1_Glossary.html#macro_character"
><EM CLASS="term"
>macro character</EM
></A
> in <VAR CLASS="param"
>readtable</VAR
>. The <A HREF="26_1_Glossary.html#secondary_value"
><EM CLASS="term"
>secondary value</EM
></A
>, <VAR CLASS="param"
>non-terminating-p</VAR
>, is <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
> if <VAR CLASS="param"
>char</VAR
> is a <A HREF="26_1_Glossary.html#non-terminating"
><EM CLASS="term"
>non-terminating</EM
></A
> <A HREF="26_1_Glossary.html#macro_character"
><EM CLASS="term"
>macro character</EM
></A
>; otherwise, it is <A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
>. </P
><P CLASS="j"
><A HREF="f_set-macro-character.html" CLASS="funref"
><B
>set-macro-character</B
></A
> causes <VAR CLASS="param"
>char</VAR
> to be a <A HREF="26_1_Glossary.html#macro_character"
><EM CLASS="term"
>macro character</EM
></A
> associated with the <A HREF="26_1_Glossary.html#reader_macro_function"
><EM CLASS="term"
>reader macro function</EM
></A
> <VAR CLASS="param"
>new-function</VAR
> (or the <A HREF="26_1_Glossary.html#designator"
><EM CLASS="term"
>designator</EM
></A
> for <VAR CLASS="param"
>new-function</VAR
>) in <VAR CLASS="param"
>readtable</VAR
>. If <VAR CLASS="param"
>non-terminating-p</VAR
> is <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
>, <VAR CLASS="param"
>char</VAR
> becomes a <A HREF="26_1_Glossary.html#non-terminating"
><EM CLASS="term"
>non-terminating</EM
></A
> <A HREF="26_1_Glossary.html#macro_character"
><EM CLASS="term"
>macro character</EM
></A
>; otherwise it becomes a <A HREF="26_1_Glossary.html#terminating"
><EM CLASS="term"
>terminating</EM
></A
> <A HREF="26_1_Glossary.html#macro_character"
><EM CLASS="term"
>macro character</EM
></A
>.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
>(get-macro-character #\{) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL, <A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
>
(not (get-macro-character #\;)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
></PRE
><P CLASS="j"
>The following is a possible definition for the <A HREF="26_1_Glossary.html#single-quote"
><EM CLASS="term"
>single-quote</EM
></A
> <A HREF="26_1_Glossary.html#reader_macro"
><EM CLASS="term"
>reader macro</EM
></A
> in <A HREF="26_1_Glossary.html#standard_syntax"
><EM CLASS="term"
>standard syntax</EM
></A
>:</P
><PRE CLASS="screen"
>(defun single-quote-reader (stream char)
(declare (ignore char))
(list 'quote (read stream t nil t))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> SINGLE-QUOTE-READER
(set-macro-character #\' #'single-quote-reader) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> T</PRE
><P CLASS="j"
>Here <CODE CLASS="f"
>single-quote-reader</CODE
> reads an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> following the <A HREF="26_1_Glossary.html#single-quote"
><EM CLASS="term"
>single-quote</EM
></A
> and returns a <A HREF="26_1_Glossary.html#list"
><EM CLASS="term"
>list</EM
></A
> of <A HREF="f_quote.html" CLASS="specref"
><B
>quote</B
></A
> and that <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
>. The <VAR CLASS="param"
>char</VAR
> argument is ignored. </P
><P CLASS="j"
>The following is a possible definition for the <A HREF="26_1_Glossary.html#semicolon"
><EM CLASS="term"
>semicolon</EM
></A
> <A HREF="26_1_Glossary.html#reader_macro"
><EM CLASS="term"
>reader macro</EM
></A
> in <A HREF="26_1_Glossary.html#standard_syntax"
><EM CLASS="term"
>standard syntax</EM
></A
>:</P
><PRE CLASS="screen"
>(defun semicolon-reader (stream char)
(declare (ignore char))
;; First swallow the rest of the current input line.
;; End-of-file is acceptable for terminating the comment.
(do () ((char= (read-char stream nil #\Newline t) #\Newline)))
;; Return zero values.
(values)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> SEMICOLON-READER
(set-macro-character #\; #'semicolon-reader) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> T</PRE
></DD
><DT
><B
>Side Effects</B
></DT
><DD
><P CLASS="j"
>The <VAR CLASS="param"
>readtable</VAR
> is modified.</P
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="v_readtable.html" CLASS="varref"
><B
>*readtable*</B
></A
></P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_set-dispatch-macro-character.html" CLASS="prev"
>&#8592;</A
><A HREF="f_set-syntax-from-char.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>