From: Feral Dragoon
Subject: NEWB question! Help please!
Date: 
Message-ID: <f5m1pucl5qcul1r29smf5tdk165rodektr@4ax.com>
I have been looking through Guy Steele's Common Lisp book and have
found no information about reserved words or keywords. I am very new
to LISP, and just wanted to know if LISP uses reserved words or
keywords and if it does... where can I find a list of them?  I am
using a GNU common Lisp compiler on a Unix box...

Appreciated

From: Barry Margolin
Subject: Re: NEWB question! Help please!
Date: 
Message-ID: <X83k9.22$y77.2703@paloalto-snr1.gtei.net>
In article <··································@4ax.com>,
Feral Dragoon  <············@hotmail.com> wrote:
>I have been looking through Guy Steele's Common Lisp book and have
>found no information about reserved words or keywords. I am very new
>to LISP, and just wanted to know if LISP uses reserved words or
>keywords and if it does... where can I find a list of them?  I am
>using a GNU common Lisp compiler on a Unix box...

Common Lisp doesn't have reserved words or keywords like other languages;
the syntax is simply (<operator> <operands>) for everything.  However,
there are restrictions on what you can do with the names of the built-in
operators, which are described in the "Built-in Packages" section of the
Steele book.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Kaz Kylheku
Subject: Re: NEWB question! Help please!
Date: 
Message-ID: <cf333042.0209250815.4f7dd90f@posting.google.com>
Feral Dragoon <············@hotmail.com> wrote in message news:<··································@4ax.com>...
> I have been looking through Guy Steele's Common Lisp book and have
> found no information about reserved words or keywords. I am very new
> to LISP, and just wanted to know if LISP uses reserved words or
> keywords and if it does... where can I find a list of them?  I am
> using a GNU common Lisp compiler on a Unix box...

Firstly, you should understand that COMMON-LISP has a package
mechanism. There are some special symbols which have a reserved
purpose and do not behave like other symbols, namely the symbols NIL
and T in the COMMON-LISP package.

There is also a package whose name is "KEYWORD". This gives the
programmer an indefinitely large supply of keywords for whatever
purpose. Symbols in this package are not permitted to have bindings to
functions or values; they represent themselves, and are used for
purposes like enumeration, expression labels in tagbodies, indicators
in property lists and passing keyword parameters.

In addition to NIL and T, there are some restrictions related to the
COMMON-LISP package; the behavior is undefined if the program tries to
redefine a
function or special variable in that package. But these symbols are
not reserved; for instance, you can use the symbol LIST from that
package to name a lexical variable.

If you really want a function called LIST, or if you really want to
use the symbol name NIL, for whatever reason, you can create symbols
with these names in your own package.

So you see the answer is complex; Lisp doesn't reserve identifiers in
the same way that, say, languages like C or Pascal reserve them. In
C++ it's a syntax error to write int if = 3, but in Lisp you can do
(let ((if 3)) ...). You cannot do (let ((nil 4)) ...) but that's not
an issue of syntax; rather the NIL symbol has reserved *semantics*
that make it incompatible for use as a variable name.
From: Kalle Olavi Niemitalo
Subject: importing to the KEYWORD package
Date: 
Message-ID: <87heg8vrj5.fsf_-_@Astalo.y2000.kon.iki.fi>
···@ashi.footprints.net (Kaz Kylheku) writes:

> There is also a package whose name is "KEYWORD". This gives the
> programmer an indefinitely large supply of keywords for whatever
> purpose. Symbols in this package are not permitted to have bindings to
> functions or values; they represent themselves, [...]

AFAICT, this applies only if the symbol was originally interned in
the KEYWORD package (11.1.2.3.1) or read as a :FOO token (2.3.5).
It should be possible to work around that by creating the symbol
elsewhere and then importing it to the KEYWORD package:

  (defparameter *funky* (make-symbol "FUNKY"))
  (setf (symbol-value *funky*) 42)
  (import *funky* "KEYWORD")
  (export *funky* "KEYWORD")
  (eq (find-symbol "FUNKY" "KEYWORD") *funky*)  ; => T
  (constantp *funky*)           ; => NIL
  (keywordp *funky*)            ; => T
  (symbol-value *funky*)        ; => 42
  (symbol-package *funky*)      ; => #<The KEYWORD package, [...]>

Debian CMUCL 3.1.4 allows this but complains "Can't set keywords."
when I try to (setf (symbol-value *funky*) 69).  Debian SBCL
0.7.7-1 behaves similarly.

CLISP 2.28 changes the value of the symbol as soon as I import it
to the KEYWORD package.  Also, CLISP doesn't change the home
package of the symbol.
From: Erik Naggum
Subject: Re: importing to the KEYWORD package
Date: 
Message-ID: <3242308663187252@naggum.no>
* Kalle Olavi Niemitalo
| It should be possible to work around that by creating the symbol elsewhere
| and then importing it to the KEYWORD package:

  Even if "possible", this is a really stupid thing to do.  Do not do this.
  Do not break the expection that symbols in the keyword package have
  themselves as their value.

-- 
Erik Naggum, Oslo, Norway                 Today, the sum total of the money I
                                          would retain from the offers in the
more than 7500 Nigerian 419 scam letters received in the past 33 months would
have exceeded USD 100,000,000,000.  You can stop sending me more offers, now.
From: Tim Bradshaw
Subject: Re: importing to the KEYWORD package
Date: 
Message-ID: <ey3elbczmrh.fsf@cley.com>
* Kalle Olavi Niemitalo wrote:

> AFAICT, this applies only if the symbol was originally interned in
> the KEYWORD package (11.1.2.3.1) or read as a :FOO token (2.3.5).
> It should be possible to work around that by creating the symbol
> elsewhere and then importing it to the KEYWORD package:

Yeees.  I think this probably might work, maybe, but it's probably something
which you should never, ever, ever do.

--tim
From: ilias
Subject: Re: importing to the KEYWORD package
Date: 
Message-ID: <an9jar$2sp$2@usenet.otenet.gr>
Kalle Olavi Niemitalo wrote:
[...]
> It should be possible to work around that by creating the symbol
> elsewhere and then importing it to the KEYWORD package:

freedom.

individuality.
From: ilias
Subject: Re: NEWB question! Help please!
Date: 
Message-ID: <amrvm5$dis$1@usenet.otenet.gr>
Feral Dragoon wrote:
> I have been looking through Guy Steele's Common Lisp book and have
> found no information about reserved words or keywords. I am very new
> to LISP, and just wanted to know if LISP uses reserved words or
> keywords and if it does... where can I find a list of them?  I am
> using a GNU common Lisp compiler on a Unix box...
> 
> Appreciated

i'm not exactly sure what you meant.

but maybe this helps:

http://www.lispworks.com/reference/HyperSpec/Body/11_aba.htm

http://www.lispworks.com/reference/HyperSpec/Body/01_i.htm
From: Barry Watson
Subject: Re: NEWB question! Help please!
Date: 
Message-ID: <3D91B882.EB61A24D@uab.ericsson.se>
Feral Dragoon wrote:
> 
> I have been looking through Guy Steele's Common Lisp book and have
> found no information about reserved words or keywords. I am very new
> to LISP, and just wanted to know if LISP uses reserved words or
> keywords and if it does... where can I find a list of them?  I am
> using a GNU common Lisp compiler on a Unix box...
> 
> Appreciated

Maybe your asking the wrong question, LISPy languages have "special
forms", is there anything in the book about those?

Barry
From: Feral Dragoon
Subject: Re: NEWB question! Help please!
Date: 
Message-ID: <o9r3pug5eq5qice3dlvb3tmh1a4739bkc3@4ax.com>
On Wed, 25 Sep 2002 15:22:10 +0200, Barry Watson
<············@uab.ericsson.se> wrote:

>Feral Dragoon wrote:
>> 
>> I have been looking through Guy Steele's Common Lisp book and have
>> found no information about reserved words or keywords. I am very new
>> to LISP, and just wanted to know if LISP uses reserved words or
>> keywords and if it does... where can I find a list of them?  I am
>> using a GNU common Lisp compiler on a Unix box...
>> 
>> Appreciated
>
>Maybe your asking the wrong question, LISPy languages have "special
>forms", is there anything in the book about those?
>
>Barry

First off thanks for the responses! I greatly appreciate it.
Secondly, I guess what I'm trying to ask is in languages like Cobol,
there is a list of reserved words a mile long, words that can't be
used as variable names or anything else except for the specific
situations for which they were intended by the language designer. The
language I know the most about it Java, there are specific keywords
that are used by the language, but can be overridden if desired, such
as for variable names and the like, and there are reserved words such
as "int" which can only be used to define the numeric type int.

I hope this is clear.. I'm not usually so technically minded, so maybe
my description is lacking...

Thanks again
From: Kaz Kylheku
Subject: Re: NEWB question! Help please!
Date: 
Message-ID: <cf333042.0209251439.7434fe00@posting.google.com>
Feral Dragoon <············@hotmail.com> wrote in message news:<··································@4ax.com>...
> On Wed, 25 Sep 2002 15:22:10 +0200, Barry Watson
> <············@uab.ericsson.se> wrote:
> 
> >Feral Dragoon wrote:
> >> 
> >> I have been looking through Guy Steele's Common Lisp book and have
> >> found no information about reserved words or keywords. I am very new
> >> to LISP, and just wanted to know if LISP uses reserved words or
> >> keywords and if it does... where can I find a list of them?  I am
> >> using a GNU common Lisp compiler on a Unix box...
> >> 
> >> Appreciated
> >
> >Maybe your asking the wrong question, LISPy languages have "special
> >forms", is there anything in the book about those?
> >
> >Barry
> 
> First off thanks for the responses! I greatly appreciate it.
> Secondly, I guess what I'm trying to ask is in languages like Cobol,
> there is a list of reserved words a mile long, words that can't be
> used as variable names or anything else except for the specific
> situations for which they were intended by the language designer. The
> language I know the most about it Java, there are specific keywords
> that are used by the language, but can be overridden if desired, such
> as for variable names and the like, and there are reserved words such
> as "int" which can only be used to define the numeric type int.

Right. Now, armed with that information, consider how braindamaged is
this approach to language design. Suppose that it's time to update the
language with new features, which require new keywords. Problem: huge
quantities of existing code exist, in which any given word may appear
as a variable name. It's impossible to add keywords without the
possibility of wrecking someone's code.

The C language ran into this problem in its second release, C99. The
committee wanted to add a boolean type, but they could not call it
``bool''. So they came up with a hack: firstly, they called the type
_Bool, taking advantage of the reserved namespace of identifiers that
start with an underscore and a capital letter. Secondly, they
introduced a bool macro that expands to _Bool, and which is available
if a certain header is included.
From: Tim Bradshaw
Subject: Re: NEWB question! Help please!
Date: 
Message-ID: <ey3znu6yspd.fsf@cley.com>
* Feral Dragoon wrote:

> First off thanks for the responses! I greatly appreciate it.
> Secondly, I guess what I'm trying to ask is in languages like Cobol,
> there is a list of reserved words a mile long, words that can't be
> used as variable names or anything else except for the specific
> situations for which they were intended by the language designer. The
> language I know the most about it Java, there are specific keywords
> that are used by the language, but can be overridden if desired, such
> as for variable names and the like, and there are reserved words such
> as "int" which can only be used to define the numeric type int.

Well, the answer for Lisp is that symbols are what Lisp uses for names
of functions and variables &c.  Symbols usually live in packages which
are used to structure the namespace of a program.  Packages (among
other things) export symbols to make them available to `clients'
(loosely defined: programs or people writing programs).  Packages may
also have internal symbols which they do not export.

Common Lisp defines some standard packages, and for some of them
defines what symbols they export.  It also places some restrictions on
the use of the standard packages, and on the symbols they export by
conforming programs.

The most interesting standard package from this point of view is the
COMMON-LISP package, which exports 978 symbols which make up most of
the defined names in the language.  I'm not going to try and describe
exactly what the restrictions are on the CL package, but you can find
a very good description in section 11.1.2.1 of the standard.

A couple of notes:

1. The restrictions are not as onerous as you might think due to CL's
   multiple namespaces: even though LIST is (normally...) a
   symbol exported from CL, it is OK to say:

   (defun foo (list)
     ... do things with LIST ...)

2. If you do want to use the names of symbols from CL in ways that are
   forbidden you can devise packages where those names refer to other
   symbols, not from CL, and where the symbols can therefore be used
   as you wish.  There are (fairly obscure) cases where this does not
   do what you want.

3. Almost all of this article lacks precision (possibly to the point
   of being outright wrong in places): if you want to know what the
   real story is you need to look at the standard unfortunately.

--tim
From: Barry Watson
Subject: Re: NEWB question! Help please!
Date: 
Message-ID: <3D91DE23.F38C69A8@uab.ericsson.se>
Feral Dragoon wrote:
>
> First off thanks for the responses! I greatly appreciate it.
> Secondly, I guess what I'm trying to ask is in languages like Cobol,
> there is a list of reserved words a mile long, words that can't be
> used as variable names or anything else except for the specific
> situations for which they were intended by the language designer. The
> language I know the most about it Java, there are specific keywords
> that are used by the language, but can be overridden if desired, such
> as for variable names and the like, and there are reserved words such
> as "int" which can only be used to define the numeric type int.
> 
> I hope this is clear.. I'm not usually so technically minded, so maybe
> my description is lacking...
> 
> Thanks again

Seems pretty clear to me. I think the best thing for you would be to
understand how the interpreter works. What follows is something I wrote
(ported from Quiennec) a while back in the Lisp provided by the Emacs
editor. I'm not sure it even works. However, look at the "evaluate"
function. See how the names used in the language guide the
interpretation. If you evaluate the symbol "if" just on it's own it will
try to look up "if" in the environment and return it's value if it
exists. If the "if" symbol is in the car position then it will be a
ternary control form. Like real-estate it is location location location.
This language isn't Lisp, it's Scheme like but get your hands on the
Lisp 1.5 manual for a look at how a simple Lisp works. I think there is
some code on the Net.







(setq *global-env* nil)
(setq *the-false-value* (cons `false `boolean))

(defun evaluate (e env)
  (cond
   ((symbolp e) (lookup e env))
   ((atom e) e)
   ((listp e)
    (cond
     ((eq (car e) `lambda) (build-function (cadr e) (cddr e)))
     ((eq (car e) `quote) (cadr e))
     ((eq (car e) `set) (update (cadr e) (evaluate (caddr e) env) env))
     ((eq (car e) `if) (if (not (eq (evaluate (cadr e) env)
*the-false-value*))
                           (evaluate (caddr e) env)
                         (evaluate (cadddr e) env)))))
   (t (error "undefined")) ) )

(defun evlis (l env)
  (cond 
   ((null l) nil)
   (t (cons (evaluate (car l) env) 
            (evlis (cdr l) env))) ) )

(defun eprogn (p env)
  (cond
   ((null p) nil)
   (t (evaluate (car p) env) (eprogn (cdr p) env))))

;;
*************************************************************************************
;; ENVIRONMENT

(defun lookup (s env)
  (cond 
   ((null env) nil)
   ((eq s (caar env)) (cdar env))
   ( t (lookup s (cdr env)))))

(defun insert (sym val)
  (setq *global-env* (cons (cons sym val) *global-env*)))

(defun update (sym val env)
  (cond
   ((null env) (error "no such variable to update"))
   ((eq sym (caar env)) (setcdr (car env) val))
   (t (update sym val (cdr env))) ))

(defun extend (vars vals env)
  (cond 
   ((null vars) (if (not (null vals)) (error "formals/actuals mismatch")
env))
   (t (cons (cons (car vars) (car vals)) (extend (cdr vars) (cdr vals)
env)))))

(defun build-function (formals body)
  (cons formals body))