05/22/81 -- Lisp Backquote (`) Facility for Template-building ** This documentation is not intended to be used with the help ** ** command. It is intended to be printed, dprinted, or read with** ** an editor. ** The backquote facility defines two reader macro characters, backquote ("`", ASCII code 140) and comma (",", ASCII code 54). These two macro characters can be used together to abbreviate large compositions of functions like cons, list, list* and append. It is typically used to specify templates for building code or other list structure, and often finds application in the construction of Lisp macros. To use the backquote facility, the form "(%include backquote)" should appear in your source before the first use of backquote. Backquote has a syntax similar to that of quote ("'", ascii 47). A backquote is followed by a single form. If the form does not contain any use of the comma macro character, then the form will simply be quoted. For example: `(a b c) = (quote (a b c)) = '(a b c) The comma macro character may only be used within a form following a backquote. Comma also has a syntax like that of quote. The comma is followed by a form, and that form is evaluated even though it is inside the backquote. For example: `(,a b c) = (cons a (quote (b c))) = (cons a '(b c)) `(a ,b c) = (list* (quote a) b (quote (c))) = (list* 'a b '(c)) `(a b ,c) = (list (quote a) (quote b) c) = (list 'a 'b c) `(a . ,rest) = (cons (quote a) rest) = (cons 'a rest) Thus, if one wished to write the common macro "push" using backquote, he or she could proceed from the standard definition (defun push macro (form) (list 'setq (caddr form) (list 'cons (cadr form)(caddr form)))) to (defun push macro (form) `(setq ,(caddr form) (cons ,(cadr form) ,(caddr form)))) Note how the code to build the macro's output code begins to look more like the output code itself. In fact, with a use of "let", we can go all the way to (defun push macro (form) (let ((datum (cadr form)) (list (caddr form))) `(setq ,list (cons ,datum ,list)))) and produce very legible code. Backquote expands into forms that call cons, list, list* or whatever other functions it deems appropriate for the task of constructing a form that looks like the one following the backquote, but with the values of the forms following the commas substituted in. Since backquote's contract is specified not in terms of the code that it expands into, but rather in terms of what that code produces when evaluated, the user should not assume that he or she knows anything about what that code might look like. The examples in this document only reflect the way that backquote expands at the time of writing, it is not guaranteed that this is the way they will expand in the future. If a comma inside a backquote form is followed by an "at" sign ("@", ASCII code 100), then the form following the ",@" should return a list. Backquote arranges that the elements of that list will be substituted into the resulting list structure. Frequently this involves generating a call to the function append. For example, `(,@a b c) = (append a (quote (b c))) = (append a '(b c)) `(a ,@b c) = (cons (quote a) (append b (quote (c)))) = (cons 'a (append b '(c))) `(a b ,@c) = (list* (quote a) (quote b) c) = (list* 'a 'b c) Similar to following the comma by an atsign is following the comma by a dot (".", ASCII code 56). The dot is a declaration to backquote telling it that the list returned by the form following the ",." is expendable. This allows backquote to produce code that calls functions like nconc that rplac the list. Backquote examines the forms following the commas to see if it can simplify the resulting code. For example, `(a b . ,(cons x y)) = (list* (quote a) (quote b) x y) = (list* 'a 'b x y) `(a 3 ,b c ,17) = (list* (quote a) 3 b (quote (c 17))) = (list* 'a 3 b '(c 17)) `(a ,@b ,@nil) = (cons (quote a) b) = (cons 'a b) `(a ,.b ,@(nconc c d)) = (cons (quote a) (nconc b c d)) = (cons 'a (nconc b c d)) These examples should convince the user that he or she really cannot depend on what the code that backquote expands into will look like. A simple minded backquote might expand "(,@a ,@nil)" into "(append a 'nil)", but this cannot be used as a reliable way to copy a list since a sophisticated backquote (like this one) can optimize the copying away. It is sometimes useful to nest one use of backquote within another. This might happen when the user is writing some code that will cons up some more code that will in turn cons up yet more code. The usual example is in writing macro defining macros. When this becomes necessary it is sometimes difficult to determine exactly how to use comma to cause evaluation to happen at the correct times. The following example exhibits all the useful combinations: ``(a ,b ,,c ,',d) = (list 'list* ''a 'b c (list 'quote (list d))) When evaluated once this yields: (list* 'a b '()) Which when evaluated yields: (a <-at-time-2> ) Thus "" means never evaluate, "," means evaluate only the second time, ",," means evaluate both times, and ",'," means evaluate only the first time. ----------------------------------------------------------- Historical Background This edition of the Multics software materials and documentation is provided and donated to Massachusetts Institute of Technology by Group BULL including BULL HN Information Systems Inc. as a contribution to computer science knowledge. This donation is made also to give evidence of the common contributions of Massachusetts Institute of Technology, Bell Laboratories, General Electric, Honeywell Information Systems Inc., Honeywell BULL Inc., Groupe BULL and BULL HN Information Systems Inc. to the development of this operating system. Multics development was initiated by Massachusetts Institute of Technology Project MAC (1963-1970), renamed the MIT Laboratory for Computer Science and Artificial Intelligence in the mid 1970s, under the leadership of Professor Fernando Jose Corbato. Users consider that Multics provided the best software architecture for managing computer hardware properly and for executing programs. Many subsequent operating systems incorporated Multics principles. Multics was distributed in 1975 to 2000 by Group Bull in Europe , and in the U.S. by Bull HN Information Systems Inc., as successor in interest by change in name only to Honeywell Bull Inc. and Honeywell Information Systems Inc. . ----------------------------------------------------------- Permission to use, copy, modify, and distribute these programs and their documentation for any purpose and without fee is hereby granted,provided that the below copyright notice and historical background appear in all copies and that both the copyright notice and historical background and this permission notice appear in supporting documentation, and that the names of MIT, HIS, BULL or BULL HN not be used in advertising or publicity pertaining to distribution of the programs without specific prior written permission. Copyright 1972 by Massachusetts Institute of Technology and Honeywell Information Systems Inc. Copyright 2006 by BULL HN Information Systems Inc. Copyright 2006 by Bull SAS All Rights Reserved