On Sun, 12 Dec 2010 20:29:47 +0100, Daniel Carrera wrote:
> Hello,
>
> I am new to Lisp, but I know several other programming languages (C,
> Perl, Ruby, Fortran, Python, JavaScript, PHP, etc). I have been trying
> to use online resources to learn Common Lisp but I'm having a really
> hard time finding the information I need. Most information is for people
> who are new to programming.
>
> I was hoping someone could help me with the following:
>
> (1) I would like to have a list of Common Lisp functions, and what they
> do. Right now I'm getting frustrated with SETF and SETQ and I can't find
> any information about them.
First, I would suggest that you get a decent book. PCL by Peter
Seibel is very nice. There is an online version. It will introduce
you to proper CL style too.
When you have read PCL, you will find that SETF and SETQ, like all
things in CL, are documented thoroughly in the Hyperspec. You can
search that online (see eg lispdoc.com), but your IDE should make
stuff really convenient.
> (2) Can someone explain to me the difference between SETQ, SETF and
> DEFVAR?
>
> (3) Using SBCL, when I try to use SETQ I get an error I cannot
> understand:
>
> * (setq bar '(1 2))
>
> ; in: LAMBDA NIL
> ; (SETQ BAR '(1 2))
> ;
> ; caught WARNING:
> ; undefined variable: BAR
> ;
> ; compilation unit finished
> ; Undefined variable:
> ; BAR
> ; caught 1 WARNING condition
>
> Why is SBCL complaining that BAR is not defined? Of course it's not
> defined, I'm trying to define it right here... If I try to use the
Just use DEFPARAMETER or DEFVAR. SETF is for assignment. Ignore SETQ
for now.
> "list" construct, it's even worse. I just get the debugger:
>
> * (set bar (list 1 2 3))
>
> debugger invoked on a TYPE-ERROR in thread #<THREAD "initial thread"
> RUNNING {AA5E679}>:
> The value (1 2) is not of type SYMBOL.
>
> Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
>
> restarts (invokable by number or by possibly-abbreviated name):
> 0: [ABORT] Exit debugger, returning to top level.
>
>
> (4) Can anyone tell me how to add two lists / vectors component-wise? I
> want to solve an algebraic problem. Suppose I have vectors (1 2 3 4) and
> (2 3 4 5). I'd like to make a function "add-vect" that gives me (3 5 7
> 9). I expect a syntax similar to this:
>
> (setq v1 (1 2 3 4))
> (setq v2 (2 3 4 5))
> (setq sum (add-vect v1 v2))
(map 'vector #'+ '(1 2 3 4) '(2 3 4 5))
> Thanks for the help.
Also try comp.lang.lisp for general CL questions.
Best,
Tamas
|