XLISP intern

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

# intern

Type: | - | function (subr)
Source: | - | xlbfun.c

## Syntax

(intern name-str)
  name-str - a string expression
  returns - the new symbol

## Description

The 'intern' function takes a string name 'name-str' and creates a new interned symbol. What this means is that the symbol 'name-str' will be placed into the symbol hash table *obarray*. It's value will be unbound. It's property list will be NIL [empty]. If the symbol already exists, no error or action is taken and the old values and property lists remain intact. The 'intern' function returns the symbol as its result.

## Examples

    (defun lookin (sym)                  ; create a function to
      (aref *obarray*                    ;   look inside *OBARRAY* and
        (hash sym (length *obarray*))))  ;   look for a specific symbol
                                         ;   returns a list

    (lookin "FINGERS")                   ; see if "FINGERS" is a symbol
                                         ;   returns (:START1) - it isn't

    (intern "FINGERS")                   ; intern "FINGERS" as a symbol
                                         ;   returns FINGERS

    (lookin "FINGERS")                   ; returns (FINGERS :START1)

    (print fingers)                      ; error: unbound variable
                                         ;   it exists, but has no value

    (lookin "TOES")                      ; returns NIL - doesn't exist
    toes                                 ; error: unbound variable

    (lookin "TOES")                      ; returns (TOES)
                                         ;   the act of looking for a
                                         ;   value or using a symbol
                                         ;   causes it to be INTERNed

    (lookin "KNEECAPS")                  ; returns (MAX MAPLIST)
                                         ;   KNEECAPS doesn't exist

    (setq kneecaps 'a-bone)              ; create symbol with a value
    (lookin "KNEECAPS")                  ; returns (KNEECAPS MAX MAPLIST)

Note: When you 'intern' a string symbol like "fingers" in lower case letters, this gets placed in the *obarray* symbol table as a lower case symbol. Note that this is different from doing an 'intern' on a string symbol "FINGERS" in upper case letters which will get placed in the *obarray* as a upper case symbol. "fingers" and "FINGERS" then are two different symbols in *obarray*. Remember also that normal symbols created by XLISP are automatically converted to upper case names. So, an intern of the lower case symbol name 'fingers and the upper case symbol name 'FINGERS will result in the effect that both symbol names get interned as the same upper-case symbol FINGERS.

Common Lisp: Common LISP allows an optional package specification, which XLISP does not support.

See the intern function in the XLISP 2.0 manual.

Back to Top

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