Nyquist / XLISP 2.0  -  Contents | Tutorials | Examples | Reference

backquote


backquote:

Type:   -   special form (fsubr)
Source:   -   xlcont.c, xlread.c

comma, comma-at:

Type:   -   reader expansion
Source:   -   xlcont.c, xlread.c

Syntax

(backquote expr)
expr - an expression which is not evaluated except for 'comma' and 'comma-at' portions
returns - a copy of the template with 'comma' and 'comma-at' expressions expanded
(comma expr)
expr - an expression which is evaluated within a backquoted expression
(comma-at expr)
expr - an expression which is evaluated within a backquoted expression

Description

The 'backquote' special form returns 'expr' unevaluated, like quote. The difference is that portions of the expression may be evaluated when they are preceeded by a 'comma' or 'comma-at'.

XLISP supports the following read macros:

   `expression   →   (backquote expression)
   ,expression   →   (comma expression)
   ,@expression   →   (comma-at expression)

Examples

(setq box 'stuff-inside)  => STUFF-INSIDE  ; BOX contains STUFF-INSIDE
(print box)               => STUFF-INSIDE

'(i have the box)   ≡ (quote (i have the box))                 => (I HAVE THE BOX)
`(i have the box)   ≡ (backquote (i have the box))             => (I HAVE THE BOX)
`(i have the ,box)  ≡ (backquote (i have the (comma box)))     => (I HAVE THE STUFF-INSIDE)
`(i have the ,@box) ≡ (backquote (I have the (comma-at box)))  => (I HAVE THE)  ; STUFF-INSIDE is not a list

(setq automobile '(a van))  => (A VAN)  ; AUTOMOBILE is a VAN
(print automobile)          => (A VAN)

'(I have automobile)   ≡ (quote (I have automobile))                 => (I HAVE AUTOMOBILE)
`(I have automobile)   ≡ (backquote (I have automobile))             => (I HAVE AUTOMOBILE)
`(I have ,automobile)  ≡ (backquote (I have (comma automobile)))     => (I HAVE (A VAN))
`(I have ,@automobile) ≡ (backquote (I have (comma-at automobile)))  => (I HAVE A VAN)

Common errors:

`(,@(i am a list))   => error: bad function - I
`(,@'(i am a list))  => (I AM A LIST)

Note: 'backquote', 'comma', and 'comma-at' are very useful in defining macros via defmacro.

See also:

  Back to Top


Nyquist / XLISP 2.0  -  Contents | Tutorials | Examples | Reference