definite nooby!
-
- Posts: 2
- Joined: Sat Aug 31, 2013 4:27 pm
- Location: Irwin, PA
- Contact:
definite nooby!
Hi all. I'm trying to work my way thru Peter Seibel's book, "Practical Common Lisp", and I'm finding it somewhat difficult. I know from past experience how I best learn a language. For C and several dialects of BASIC, I started with a listing of key/reserved words and functions/statements organized according to function. Then I would construct basic programs from this list, adding complexity and functionality as I went along. I've been all over the Net (at least all the resources I could find) and I can't find such a list for Lisp. Is there such a thing and could someone point me to it???
Thanks.
Bill
Thanks.
Bill
******************************
Keller Racing
"Performance By Design"
http://KellerRacing.net
******************************
Keller Racing
"Performance By Design"
http://KellerRacing.net
******************************
Re: definite nooby!
Hi. Look at the Common Lisp Hyperspec and the Common Lisp Quick Reference. Links are in the FAQ for this forum section.
Re: definite nooby!
As nuntius says, the ANSI Spec is the final say on anything within ANSI Common Lisp.
I think it is fair to say that in some sense, there are no key/reserved words in Common Lisp. That is, in terms of syntactic elements, no token in Common Lisp is reserved. Common Lisp, however, has some restrictions on symbols, which have a meaning outside of pure syntax. To be precise, any symbol that comes from the Common-Lisp package has restrictions placed on what it can be used for (actually, the spec says "the consequences are undefined if..." but that is just how the spec says "if you do this, don't expect anything good to happen" (see "11.1.2.1.2 Constraints on the COMMON-LISP Package for Conforming Programs" in the Spec)). So, the reserved words in Common Lisp are kind of like all of the symbols exported from the Common-Lisp package. The spec tells me that there are 978 exported symbols from the Common-Lisp package. In some sense, there are 978 reserved words in Common Lisp. This is a result of the fact that ANSI Common Lisp is a tremendously large language.
That said, you don't need to know all of the exported symbols of the Common-Lisp package in order to be productive (I certainly don't, but believe I am productive).
In most languages, the reserved words are syntactic markers that typically indicate a change in syntax. In Common Lisp, this most closely maps onto something we would call a special form or a macro (two different things but either typically mark a change in syntactic structure). These are much less frequent than the actual symbols that are restricted; there are some 25 special forms (see "3.1.2.1.2.1 Special Forms" in the Spec):
...and another 91 standard macros (exported from the Common-Lisp package):
...with some slight formatting for saving space. These are in some sense the keywords of Common Lisp that you are looking for. Sorry I can't group them by purpose right now... you can consult the Spec to understand what each does.
I think it is fair to say that in some sense, there are no key/reserved words in Common Lisp. That is, in terms of syntactic elements, no token in Common Lisp is reserved. Common Lisp, however, has some restrictions on symbols, which have a meaning outside of pure syntax. To be precise, any symbol that comes from the Common-Lisp package has restrictions placed on what it can be used for (actually, the spec says "the consequences are undefined if..." but that is just how the spec says "if you do this, don't expect anything good to happen" (see "11.1.2.1.2 Constraints on the COMMON-LISP Package for Conforming Programs" in the Spec)). So, the reserved words in Common Lisp are kind of like all of the symbols exported from the Common-Lisp package. The spec tells me that there are 978 exported symbols from the Common-Lisp package. In some sense, there are 978 reserved words in Common Lisp. This is a result of the fact that ANSI Common Lisp is a tremendously large language.
That said, you don't need to know all of the exported symbols of the Common-Lisp package in order to be productive (I certainly don't, but believe I am productive).
In most languages, the reserved words are syntactic markers that typically indicate a change in syntax. In Common Lisp, this most closely maps onto something we would call a special form or a macro (two different things but either typically mark a change in syntactic structure). These are much less frequent than the actual symbols that are restricted; there are some 25 special forms (see "3.1.2.1.2.1 Special Forms" in the Spec):
Code: Select all
block let* return-from catch quote
load-time-value setq eval-when
locally symbol-macrolet flet macrolet
tagbody function multiple-value-call
the go multiple-value-prog1 throw if
progn unwind-protect labels progv let
Code: Select all
CL-USER> (let ((count 0))
(do-external-symbols (sym (find-package :common-lisp))
(when (and (ignore-errors (macro-function sym))
(not (member sym '(block let* return-from catch
load-time-value setq eval-when
locally symbol-macrolet flet macrolet
tagbody function multiple-value-call
the go multiple-value-prog1 throw if
progn unwind-protect labels progv let
quote))))
(let ((*print-case* :downcase))
(print sym))
(incf count)))
count)
untrace decf and case do-external-symbols handler-case when
pprint-logical-block remf call-method define-compiler-macro
with-open-stream with-compilation-unit do-all-symbols or cond
defpackage with-hash-table-iterator ctypecase defgeneric
etypecase dotimes multiple-value-list pop restart-case defclass
with-output-to-string rotatef with-slots
pprint-exit-if-list-exhausted with-input-from-string do typecase
psetq pprint-pop assert with-accessors handler-bind do*
print-unreadable-object define-setf-expander do-symbols
with-open-file with-package-iterator restart-bind defun trace
prog1 setf defstruct check-type defmacro dolist step unless ccase
deftype multiple-value-setq ecase loop formatter ignore-errors
time lambda destructuring-bind shiftf loop-finish
multiple-value-bind defsetf prog define-method-combination
declaim pushnew with-standard-io-syntax define-modify-macro psetf
in-package defparameter with-simple-restart
with-condition-restarts defmethod nth-value incf defconstant
define-symbol-macro push define-condition prog* return defvar
prog2
91
Re: definite nooby!
I don't know which implementation you use, but you will get a warning if you try defining functions or macros with names from the :CL package. Here is what happens in CLISP:
The last one there you can type continue and you have redefined CL::+. This will affect all other code in the packages that uses CL::+.
If you create you own packages base where you just import some symbols you are free to implement the ones you didn't import. This is the reason you have no reserved words. Example:
In the above code I'm making a package that only has some primitives from :CL package and I use that to implement my own let by using anonymous function application.
I named the package lisp1.5 since it's the first LISP dialect with a function name space, and a predecessor to CL.
Code: Select all
*** - DEFUN/DEFMACRO: LET is a special operator and may not be redefined.
** - Continuable Error
DEFUN/DEFMACRO(+): #<PACKAGE COMMON-LISP> is locked
If you continue (by typing 'continue'): Ignore the lock and proceed
If you create you own packages base where you just import some symbols you are free to implement the ones you didn't import. This is the reason you have no reserved words. Example:
Code: Select all
(defpackage :lisp1.5
(:import-from :cl
:if :quote :lambda :setq :defmacro :defun
:eq :atom :cons :car :cdr := :+ :-
:funcall :apply
:&optional :&rest :&body ; defmacro/defun need these
:in-package :macroexpand-1 :disassemble) ;; nice to have
(:use))
(in-package :lisp1.5)
;; map for only one list
(defun mapcar1 (fun list)
(if list
(cons (funcall fun (car list))
(mapcar1 fun (cdr list)))))
(defun cadr (x)
(car (cdr x)))
(let ((x 10)) (+ x x x)) ; ==> *** - COMMON-LISP:EVAL: undefined function LET
(defmacro let (defs &rest body)
`((lambda ,(mapcar1 #'car defs)
,@body) ,@(mapcar1 #'cadr defs)))
(let ((x 10)) (+ x x x)) ;; ==> 30
I named the package lisp1.5 since it's the first LISP dialect with a function name space, and a predecessor to CL.
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p
Currently I'm planning a Scheme compiler :p
Re: definite nooby!
Sylwester, is that directed to me or the OP?
Re: definite nooby!
The problem with CL resources in this aspect is that you can find what the certain symbol do, but not vice versa. I recommend reading source code written in CL, it's the way how to get what to use in situations. From PCL you learn lisp and a little from CL at least it seems like that to me, the large reference wants the time to icept.
For early begin could help this simplified reference and Learn X in Y minutes.
For early begin could help this simplified reference and Learn X in Y minutes.
Instead of the member part it's better to use special-operator-p.smithzv wrote:Code: Select all
CL-USER> (let ((count 0)) (do-external-symbols (sym (find-package :common-lisp)) (when (and (ignore-errors (macro-function sym)) (not (member sym '(block let* return-from catch load-time-value setq eval-when locally symbol-macrolet flet macrolet tagbody function multiple-value-call the go multiple-value-prog1 throw if progn unwind-protect labels progv let quote)))) (let ((*print-case* :downcase)) (print sym)) (incf count))) count)
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
Re: definite nooby!
To the OP. Your post is informative since most packages inherits :clsmithzv wrote:Sylwester, is that directed to me or the OP?
![Smile :-)](./images/smilies/icon_e_smile.gif)
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p
Currently I'm planning a Scheme compiler :p
-
- Posts: 2
- Joined: Sat Aug 31, 2013 4:27 pm
- Location: Irwin, PA
- Contact:
Re: definite nooby!
OK, I think the semantics of my question were a bit off.smithzv wrote:As nuntius says, the ANSI Spec is the final say on anything within ANSI Common Lisp.
I think it is fair to say that in some sense, there are no key/reserved words in Common Lisp. Sorry I can't group them by purpose right now... you can consult the Spec to understand what each does.
I've looked at the Hyperspec and CLtL2. Also, I've downloaded and started to review the Quick Reference (which may be what I'm looking for but with an additional level of complexity). I've got copies of "Basic Lisp Techniques", "On Lisp", "Gentle Intro ...", "Casting SPELs ...", etc. Plus all the documentation on the version I'm using, SBCL, 1.1.4.0.mswin.1288-90ab477.Hi. Look at the Common Lisp Hyperspec and the Common Lisp Quick Reference. Links are in the FAQ for this forum section.
Let me try an example here. When I was learning freeBASIC (http://freebasic.net/), and I wanted to know how to perform a certain task, I could just look in the "Keywords - Functional" (there is also a "Keywords - Alphabetical" and "Keyword - Graphical") listing. Then I could pick a function to see what it did and if it would serve my purposes. See below.
Code: Select all
Arrays
Erase
LBound
ReDim
Preserve
UBound
Extern...End Extern
Import
Shell
System
WindowTitle
Pointers
Pointer
ProcPtr
Ptr
SAdd
StrPtr
MKShort
Oct
Str
Val
ValLng
ValInt
ValUInt
ValULng
WBin
(whole bunch of stuff deleted for brevity's sake!)
I realize that Lisp is *different* from other languages but I had hoped, knowing my own learning patterns, that I could find something comparable.
Yes, this is same conclusion I've come to so far.The problem with CL resources in this aspect is that you can find what the certain symbol do, but not vice versa.
Thank you all for your suggestions.
Bill
******************************
Keller Racing
"Performance By Design"
http://KellerRacing.net
******************************
Keller Racing
"Performance By Design"
http://KellerRacing.net
******************************
Re: definite nooby!
Actually, some resources are arising in recent time. I read about one on Reddit, but I was searching for a while and couldn't find it. Instead of that site, I crossed sites:
BaLu Wiki, CL Cookbook and I add another one Quickdocs (sometimes it's only generated lists of symbols used in packages, but it's good per se when the source code is available alone and no docs exists).
BaLu Wiki, CL Cookbook and I add another one Quickdocs (sometimes it's only generated lists of symbols used in packages, but it's good per se when the source code is available alone and no docs exists).
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
Re: definite nooby!
Ah, finally, MiniSpec was that. I hope those links help you.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.