7

Today I came across these three commands:

\@nil
\@cdr
\@car

Some are mentioned here and here, but I didn't get the idea of it. It seems to have to do with the macro character.

I haven't seen any description about it on google and TeX.SX.

4
  • I retagged from tex-core to latex-base as these are latex macros Feb 13, 2017 at 22:01
  • 3
    This question explains them quite well: Lisp relics in LaTeXe logo
    – Alan Munn
    Feb 13, 2017 at 22:02
  • @AlanMunn ooh it does but this one has a better title Feb 13, 2017 at 22:03
  • That's probably the reason I haven't found it Feb 13, 2017 at 22:04

1 Answer 1

10

the names come from lisp.

In lisp, car returns the head of a list, cdr returns the tail of a list and nil is an empty list.


in latex

\def\@car#1#2\@nil{#1}
\def\@cdr#1#2\@nil{#2}

(\@nil is not defined at all)

so

\@car abc\@nil

expands to a

and

\@cdr abc\@nil

expands to bc

9
  • In expl3 lingo, \tl_head:n {abc} and \tl_tail:n {abc}
    – egreg
    Feb 13, 2017 at 22:02
  • But how does this work, if \@nil is undefined. Why is there no undefined error? Feb 13, 2017 at 22:02
  • 6
    @MaestroGlanz tokens only make an undefined error if you try to expand them. tokens used to delimit a macro argument are not expanded, try \def\foo#1\wibblethingy{hello #1}...\foo Maestro\wibblethingy Feb 13, 2017 at 22:06
  • 2
    @egreg we should put in a change request \tl_car:n and tl_cdr:n to honour the cultural heritage Feb 13, 2017 at 22:08
  • Aaaaah. Good to know. Feb 13, 2017 at 22:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .