definite nooby!

Discussion of Common Lisp

definite nooby!

Postby KellerRacing » Sat Aug 31, 2013 4:37 pm

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
******************************
Keller Racing
"Performance By Design"
http://KellerRacing.net
******************************
KellerRacing
 
Posts: 2
Joined: Sat Aug 31, 2013 4:27 pm
Location: Irwin, PA

Re: definite nooby!

Postby nuntius » Sat Aug 31, 2013 8:04 pm

Hi. Look at the Common Lisp Hyperspec and the Common Lisp Quick Reference. Links are in the FAQ for this forum section.
User avatar
nuntius
 
Posts: 500
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: definite nooby!

Postby smithzv » Sat Aug 31, 2013 9:15 pm

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):
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


...and another 91 standard macros (exported from the Common-Lisp package):

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

...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.
smithzv
 
Posts: 94
Joined: Wed Jul 23, 2008 11:36 am

Re: definite nooby!

Postby sylwester » Sun Sep 01, 2013 4:39 am

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:
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


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:
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


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.
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p
sylwester
 
Posts: 83
Joined: Mon Jul 11, 2011 2:53 pm

Re: definite nooby!

Postby smithzv » Sun Sep 01, 2013 7:13 am

Sylwester, is that directed to me or the OP?
smithzv
 
Posts: 94
Joined: Wed Jul 23, 2008 11:36 am

Re: definite nooby!

Postby Goheeca » Sun Sep 01, 2013 7:37 am

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.

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)


Instead of the member part it's better to use special-operator-p.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version).
User avatar
Goheeca
 
Posts: 218
Joined: Thu May 10, 2012 12:54 pm

Re: definite nooby!

Postby sylwester » Sun Sep 01, 2013 7:54 am

smithzv wrote:Sylwester, is that directed to me or the OP?


To the OP. Your post is informative since most packages inherits :cl :-)
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p
sylwester
 
Posts: 83
Joined: Mon Jul 11, 2011 2:53 pm

Re: definite nooby!

Postby KellerRacing » Sun Sep 01, 2013 10:13 am

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.


OK, I think the semantics of my question were a bit off.

Hi. Look at the Common Lisp Hyperspec and the Common Lisp Quick Reference. Links are in the FAQ for this forum section.


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.

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!)



So if I wanted to know how to clear the screen, I'd look up the function in the list and "learn" how to use it. Same thing if I needed to know how to perform a file function, console function, error handling, etc.

I realize that Lisp is *different* from other languages but I had hoped, knowing my own learning patterns, that I could find something comparable.

The problem with CL resources in this aspect is that you can find what the certain symbol do, but not vice versa.


Yes, this is same conclusion I've come to so far.

Thank you all for your suggestions.

Bill
******************************
Keller Racing
"Performance By Design"
http://KellerRacing.net
******************************
KellerRacing
 
Posts: 2
Joined: Sat Aug 31, 2013 4:27 pm
Location: Irwin, PA

Re: definite nooby!

Postby Goheeca » Sun Sep 01, 2013 10:36 am

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).
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version).
User avatar
Goheeca
 
Posts: 218
Joined: Thu May 10, 2012 12:54 pm

Re: definite nooby!

Postby Goheeca » Sun Sep 01, 2013 10:48 am

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).
User avatar
Goheeca
 
Posts: 218
Joined: Thu May 10, 2012 12:54 pm


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 6 guests