Search code examples
lispcommon-lisp

Colon in a custom function name causing error


I'm new to Lisp and I'm currently trying to redo an old UCI Lisp program in Common Lisp. I'm having the following problem when I copy the following code (in funcs.lisp):

;;; HEADER-CD gets the head act of a CD form.
(defun header:cd 
    (x) 
    (car x))

The interpreter issues this error:

- READ from #<INPUT BUFFERED FILE-STREAM CHARACTER #P"funcs.lisp" @11>: there is no package
  with name "HEADER"

I do not understand the purpose for the colon in the code but I am guessing it's to specify the type of acceptable input since there is another function called "header:pair".

I'm not sure how to resolve this. Perhaps I could move to UCI lisp but I can't find its compiler/interpreter. Kindly help.


Solution

  • I don't think the colon in UCI Lisp for header:cd has any specific technical meaning. It's just an identifier and identifiers in UCI Lisp probably can (could -> it's a Lisp from the 70s which is no longer in use) use most of the ASCII character set, including the colon :. Here it might be a coding convention.

    In Common Lisp the colon character has a special technical meaning in identifiers: it separates the package name from the symbol name. Note that UCI Lisp had no such feature as symbol packages.

    Thus, I would simply translate an UCI-Lisp-identifier header:cd to header-cd in Common Lisp.

    A slightly less useful way is to translate the UCI-Lisp-identifier header:cd to |HEADER:CD| or HEADER\:CD in Common Lisp. The vertical bars escape the symbol. The backslash escapes a single character in a symbol.

    CL-USER 3 > '|HEADER:CD|
    HEADER\:CD
    
    CL-USER 4 > (symbol-name '|HEADER:CD|)
    "HEADER:CD"