Syntax error in Lisp code with loop and conditions - lisp

What is the syntax error in following code?
(defun getchoice3 ()
(let ( (choice 1) )
(format t "~%Enter a number (1-5): ")
(loop for choice = (or (parse-integer (prompt-read "Choice: ") :junk-allowed t) 0) do
while (and (> choice 0) (< choice 6))
(cond
((= choice 1) (print "1 chosen"))
((= choice 2) (print "2 chosen"))
((= choice 3) (print "3 chosen"))
((= choice 4) (print "4 chosen"))
((= choice 5) (print "5 chosen"))
(t (print "invalid entry, exiting."))))
choice))
The error being reported is very general:
*** - LOOP: illegal syntax near
(COND ((= CHOICE 1) (PRINT "1 chosen")) ((= CHOICE 2) (PRINT "2 chosen")) ((= CHOICE 3) (PRINT "3 chosen"))
((= CHOICE 4) (PRINT "4 chosen")) ((= CHOICE 5) (PRINT "5 chosen")) (T (PRINT "0 chosen, exiting.")))
in
(LOOP FOR CHOICE = (OR (PARSE-INTEGER (PROMPT-READ "Choice: ") :JUNK-ALLOWED T) 0) WHILE (AND (> CHOICE 0) (< CHOICE 6))
(COND ((= CHOICE 1) (PRINT "1 chosen")) ((= CHOICE 2) (PRINT "2 chosen")) ((= CHOICE 3) (PRINT "3 chosen"))
((= CHOICE 4) (PRINT "4 chosen")) ((= CHOICE 5) (PRINT "5 chosen")) (T (PRINT "0 chosen, exiting."))))
Though 'do' is there in code, it is not being reported in Error message.

The syntax error is gone. You should actually try your code.
I fail to understand why you are not indenting the code properly. Without proper indentation you will not be able to write any working code, and especially not working Lisp code.
Your code:
(defun getchoice3 ()
(let ( (choice 1) )
(format t "~%Enter a number (1-5): ")
(loop for choice = (or (parse-integer (prompt-read "Choice: ") :junk-allowed t) 0)
while (and (> choice 0) (< choice 6)) do
(cond
((= choice 1) (print "1 chosen"))
((= choice 2) (print "2 chosen"))
((= choice 3) (print "3 chosen"))
((= choice 4) (print "4 chosen"))
((= choice 5) (print "5 chosen"))
(t (print "invalid entry, exiting."))))
choice)) ; <- WHY THIS INDENTATION?
The code properly formatted looks like more like this (there is not a single one way to format it, but indentation is always the same way):
(defun getchoice3 ()
(let ((choice 1))
(format t "~%Enter a number (1-5): ")
(loop for choice = (or (parse-integer (prompt-read "Choice: ")
:junk-allowed t)
0)
while (and (> choice 0)
(< choice 6))
do (cond
((= choice 1) (print "1 chosen"))
((= choice 2) (print "2 chosen"))
((= choice 3) (print "3 chosen"))
((= choice 4) (print "4 chosen"))
((= choice 5) (print "5 chosen"))
(t (print "invalid entry, exiting."))))
choice))
You see the difference for example in the last line? My version is correctly indented.
Why is that important? It may help you to understand that your function will always return 1. Independent of any input, the function will return always 1. Indentation helps you to understand what belongs to what, given some scope.
This is not correctly indented.
(let ((a 1))
(loop for a from 1 to 10)
a) ; <- where does this a belong to???
; this indentation indicates that A belongs to the LOOP
; which it doesn't
The correct indentation is:
(let ((a 1))
(loop for a from 1 to 10)
a) ; here it's clear to see that A was introduced by the LET construct
So, don't indent the code such a way how you dream it makes sense.
Use an editor command to do it correctly. Then you can spot the problems in your code much better.
Lisp code can be formatted and indented in arbitrary ways, because it uses an indentation independent data structure: the s-expression.
Lisp does not care:
(+ a b c)
or
(+
a b
c)
or
(+
a
b
c)
It's all the same for Lisp.
But not for humans. Only one version of those above is useful for humans to read.
If you don't put any effort into indenting and formatting your code, why should anyone put in the effort to answer your questions, which are so far all caused by trivial syntax errors.

Related

Common Lisp Execute expression as parameter in macro

So using common lisp, I want to be able to do something of the sorts of:
(defmacro foo (count &rest someExpression)
`(do
((,count 0 (+ ,count 1)))
((= ,count 5) T)
`(eval ,someExpression)
)
)
(foo (print 1) temp)
With the result of it printing 1 5 times. I do not want to simply call (print 1) directly, but by passing the expression through a macro parameter and calling it via the macro. In other words, the macro foo should handle any expression(s) as input and run it. This case does not seem to work.
Edited to clarify an explicit script and intended function.
Starting with your recent version, which is at least a reasonable candidate for a macro unlike the older one:
(defmacro foo (someExpression count-var)
`(do ((,count-var 0 (+ ,count 1)))
((= ,count-var 5) T)
`(eval (,someExpression))))
Well what is the expansion of (foo (print 1) c)?
(foo (print 1) x)
-> (do ((x 0 (+ x 1))) ((= x 5) t)
`(eval (,someexpression)))
Well, that's a disaster: what is that nested backquote doing? Let's just remove it:
(defmacro foo (someExpression count-var)
`(do ((,count-var 0 (+ ,count 1)))
((= ,count-var 5) T)
(eval (,someExpression))))
(foo (print 1) x)
-> (do ((x 0 (+ x 1))) ((= x 5) t)
(eval ((print 1))))
That's less disastrous, but the eval form is entirely bogus. We can make that 'work' by changing it to be at least syntactically legal:
(defmacro foo (someExpression count)
`(do ((,count 0 (+ ,count 1)))
((= ,count 5) T)
(eval ,someExpression)))
And now
(foo (print 1) x)
-> (do ((x 0 (+ x 1))) ((= x 5) t)
(eval (print 1)))
And this will 'work' but it will work purely by coincidence: because (print 1) returns 1 and the value of 1 is 1.
(foo (print 'foo) x)
-> (do ((x 0 (+ x 1))) ((= x 5) t)
(eval (print 'foo)))
and that's a run-time error.
But ... why are you using eval? eval is a terrible, terrible solution to almost any problem you can think of, unless the solution to the problem is called 'code injection attack', and in this case it's not just terrible: it's wrong. So we just remove it.
(defmacro foo (someExpression count)
`(do ((,count 0 (+ ,count 1)))
((= ,count 5) T)
,someExpression))
And now
(foo (print 'foo) x)
-> (do ((x 0 (+ x 1))) ((= x 5) t)
(print 'foo))
Which looks like the code transformation we want. So, finally:
> (foo (print 'foo) x)
foo
foo
foo
foo
foo
t
Which is, finally, fine. And this works:
> (foo (print x) x)
0
1
2
3
4
t
As with yet another edit to the question it probably is more useful to put the variable name first and allow a bunch of expressions:
(defmacro foo (count-var &body forms)
`(do ((,count-var 0 (+ ,count-var 1)))
((= ,count-var 5))
,#forms))
This will now allow multiple expressions in the body. And we could go further: we could allow it to specify the number of iterations and the return value`:
(defmacro foo ((count-var &optional (count 1) (value 'nil)) &body forms)
`(do ((,count-var 0 (1+ ,count-var)))
((= ,count-var ,count) ,value)
,#forms))
And now
> (foo (x 2)
(print x)
(print (* x 2)))
0
0
1
2
nil
Well, the name of this macro is dotimes of course.

If condition with and operator

How to use IF condition with AND operator?
I'm getting an error
(princ"Enter a year: ")
(defvar y(read))
(defun leap-year(y)
(if(and(= 0(mod y 400)(= 0(mod y 4))
(print"Is a leap year"))
(print"Is not"))))
(leap-year y)
Note that your code should ideally look like this:
(princ "Enter a year: ")
(finish-output) ; make sure that output is done
(defvar *year* ; use the usual naming convention for
; global variables.
(let ((*read-eval* nil)) ; don't run code during reading
(read)))
(defun leap-year-p (y)
; your implementation here
; return a truth value
)
(print (if (leap-year-p *year*) "yes" "no"))
Alternatively it also is a good idea to not work on the top-level with function calls and global variables. Write procedures/functions for everything. That way your code automatically is more modular, testable and reusable.
(defun prompt-for-year ()
(princ "Enter a year: ")
(finish-output)
(let ((*read-eval* nil))
(read)))
(defun leap-year-p (y)
; your implementation here
; return a truth value
)
(defun check-leap-year ()
(print (if (leap-year-p (prompt-for-year))
"yes"
"no")))
(check-leap-year)
How often happens in lisp languages, the problem is in missing (or extra) parentheses.
In your case you have multiple parentheses issues in the definition of the function, which should be:
(defun leap-year (y)
(if (and (= 0 (mod y 400)) (= 0(mod y 4)))
(print "Is a leap year")
(print "Is not")))
A good discipline on expression alignments and a good program editor like for instance Emacs are in fact very important (I would say “essential”) in programming in these languages.
Note that if you use the function in a REPL, you could omit the print:
(defun leap-year (y)
(if (and (= 0 (mod y 400)) (= 0(mod y 4)))
"Is a leap year"
"Is not"))
Finally, note that the check for a leap year is incorrect. A correct definition could be the following:
(defun leap-year (y)
(cond ((/= 0 (mod y 4)) "no")
((/= 0 (mod y 100)) "yes")
((/= 0 (mod y 400)) "no")
(t "yes")))
or, with the if:
(defun leap-year (y)
(if (or (and (zerop (mod y 4))
(not (zerop (mod y 100))))
(zerop (mod y 400)))
"yes"
"no"))

Trying to rewrite an ugly macro

I'm new to lisp, and have been trying to learn Common Lisp by diving in and writing some code. I've read plenty of documentation on the subject, but it's taking a while to really sink in.
I have written a couple of macros (? and ??) for performing unit tests, but I'm having some difficulty. The code is at the end of the post, to avoid cluttering the actual question.
Here is an example of usage:
(??
(? "Arithmetic tests"
(? "Addition"
(= (+ 1 2) 3)
(= (+ 1 2 3) 6)
(= (+ -1 -3) -4))))
And an example of output:
[Arithmetic tests]
[Addition]
(PASS) '(= (+ 1 2) 3)'
(PASS) '(= (+ 1 2 3) 6)'
(PASS) '(= (+ -1 -3) -4)'
Results: 3 tests passed, 0 tests failed
Now, the existing code works. Unfortunately, the (? ...) macro is ugly, verbose, resistant to change - and I'm pretty sure also badly structured. For example, do I really have to use a list to store pieces of output code and then emit the contents at the end?
I'd like to modify the macro to permit description strings (or symbols) to optionally follow each test, whereupon it would replace the test literal in the output, thus:
(??
(? "Arithmetic tests"
(? "Addition"
(= (+ 1 2) 3) "Adding 1 and 2 results in 3"
(= (+ 1 2 3) 6)
(= (+ -1 -3) -4))))
Output:
[Arithmetic tests]
[Addition]
(PASS) Adding 1 and 2 results in 3
(PASS) '(= (+ 1 2 3) 6)'
(PASS) '(= (+ -1 -3) -4)'
But unfortunately I can't find a sensible place in the macro to insert this change. Depending on where I put it, I get errors like you're not inside a backquote expression, label is not defined or body-forms is not defined. I know what these errors mean, but I can't find a way to avoid them.
Also, I'll be wanting to handle exceptions in the test, and treat that as a failure. Currently, there is no exception handling code - the test result is merely tested against nil. Again, it is not clear how I should add this functionality.
I'm thinking that maybe this macro is over-complex, due to my inexperience in writing macros; and perhaps if I simplify it, modification will be easier. I don't really want to separate it out into several smaller macros without good reason; but maybe there's a terser way to write it?
Can anyone help me out here, please?
A complete code listing follows:
(defmacro with-gensyms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensym)))
,#body))
(defmacro while (condition &body body)
`(loop while ,condition do (progn ,#body)))
(defun flatten (L)
"Converts a list to single level."
(if (null L)
nil
(if (atom (first L))
(cons (first L) (flatten (rest L)))
(append (flatten (first L)) (flatten (rest L))))))
(defun starts-with-p (str1 str2)
"Determine whether `str1` starts with `str2`"
(let ((p (search str2 str1)))
(and p (= 0 p))))
(defmacro pop-first-char (string)
`(with-gensyms (c)
(if (> (length ,string) 0)
(progn
(setf c (schar ,string 0))
(if (> (length ,string) 1)
(setf ,string (subseq ,string 1))
(setf ,string ""))))
c))
(defmacro pop-chars (string count)
`(with-gensyms (result)
(setf result ())
(dotimes (index ,count)
(push (pop-first-char ,string) result))
result))
(defun format-ansi-codes (text)
(let ((result ()))
(while (> (length text) 0)
(cond
((starts-with-p text "\\e")
(push (code-char #o33) result)
(pop-chars text 2)
)
((starts-with-p text "\\r")
(push (code-char 13) result)
(pop-chars text 2)
)
(t (push (pop-first-char text) result))
))
(setf result (nreverse result))
(coerce result 'string)))
(defun kv-lookup (values key)
"Like getf, but works with 'keys as well as :keys, in both the list and the supplied key"
(setf key (if (typep key 'cons) (nth 1 key) key))
(while values
(let ((k (pop values)) (v (pop values)))
(setf k (if (typep k 'cons) (nth 1 k) k))
(if (eql (symbol-name key) (symbol-name k))
(return v)))))
(defun make-ansi-escape (ansi-name)
(let ((ansi-codes '( :normal "\\e[00m" :white "\\e[1;37m" :light-grey "\\e[0;37m" :dark-grey "\\e[1;30m"
:red "\\e[0;31m" :light-red "\\e[1;31m" :green "\\e[0;32m" :blue "\\e[1;34m" :dark-blue "\\e[1;34m"
:cyan "\\e[1;36m" :magenta "\\e[1;35m" :yellow "\\e[0;33m"
:bg-dark-grey "\\e[100m"
:bold "\\e[1m" :underline "\\e[4m"
:start-of-line "\\r" :clear-line "\\e[2K" :move-up "\\e[1A")))
(format-ansi-codes (kv-lookup ansi-codes ansi-name))
))
(defun format-ansi-escaped-arg (out-stream arg)
(cond
((typep arg 'symbol) (format out-stream "~a" (make-ansi-escape arg)))
((typep arg 'string) (format out-stream arg))
(t (format out-stream "~a" arg))
))
(defun format-ansi-escaped (out-stream &rest args)
(while args
(let ((arg (pop args)))
(if (typep arg 'list)
(let ((first-arg (eval (first arg))))
(format out-stream first-arg (second arg))
)
(format-ansi-escaped-arg out-stream arg)
))
))
(defmacro while-pop ((var sequence &optional result-form) &rest forms)
(with-gensyms (seq)
`(let (,var)
(progn
(do () ((not ,sequence))
(setf ,var (pop ,sequence))
(progn ,#forms))
,result-form))))
(defun report-start (form)
(format t "( ) '~a'~%" form))
(defun report-result (result form)
(format-ansi-escaped t "(" (if result :green :red) `("~:[FAIL~;PASS~]" ,result) :normal `(") '~a'~%" ,form))
result)
(defmacro ? (name &body body-forms)
"Run any number of test forms, optionally nested within further (?) calls, and print the results of each test"
(with-gensyms (result indent indent-string)
(if (not body-forms)
:empty
(progn
(setf result () indent 0 indent-string " ")
(cond
((typep (first body-forms) 'integer)
(setf indent (pop body-forms))))
`(progn
(format t "~v#{~A~:*~}" ,indent ,indent-string)
(format-ansi-escaped t "[" :white ,name :normal "]~%")
(with-gensyms (test-results)
(setf test-results ())
,(while-pop (body-form body-forms `(progn ,#(nreverse result)))
(cond
( (EQL (first body-form) '?)
(push `(progn
(setf test-results (append test-results (? ',(nth 1 body-form) ,(1+ indent) ,#(nthcdr 2 body-form))))
(format t "~%")
test-results
) result)
)
(t
(push `(progn
(format t "~v#{~A~:*~}" ,(1+ indent) ,indent-string)
(report-start ',body-form)
(with-gensyms (result label)
(setf result ,body-form)
(format-ansi-escaped t :move-up :start-of-line :clear-line)
(format t "~v#{~A~:*~}" ,(1+ indent) ,indent-string)
(push (report-result result ',body-form) test-results)
test-results
)) result))))))))))
(defun ?? (&rest results)
"Run any number of tests, and print a summary afterward"
(setf results (flatten results))
(format-ansi-escaped t "~&" :white "Results: " :green `("~a test~:p passed" ,(count t results)) :normal ", "
(if (find NIL results) :red :normal) `("~a test~:p failed" ,(count NIL results))
:yellow `("~[~:;, ~:*~a test~:p not run~]" ,(count :skip results))
:brown `("~[~:;, ~:*~a empty test group~:p skipped~]" ,(count :empty results))
:normal "~%"))
For my part, the ? macro is rather technical and it's hard to follow the logic behind the formatting functions. So instead of tracking errors I'd like to suggest my own attempt, perhaps it'll be of use.
I think that actually your ?? doesn't want to evaluate anything, but rather to treat its body as individual tests or sections. If the body includes a list starting with ?, this list represents a section; other elements are test forms optionally followed by descriptions. So in my implementation ?? will be a macro, and ? will be just a symbol.
I start with wishful thinking. I suppose I can create individual tests using a function make-test-item and test sections using a function make-test-section (their implementation is unimportant for now), that I can display them using an auxiliary function display-test and compute results using the function results, which returns two values: the total number of tests and the number of passed ones. Then I'd like the code
(??
(? "Arithmetic tests"
(? "Addition"
(= (+ 1 2) 3) "Adding 1 and 2 results in 3"
(= (+ 1 2 3) 6)
(= (+ -1 -3) 4))
(? "Subtraction"
(= (- 1 2) 1)))
(= (sin 0) 0) "Sine of 0 equals 0")
to expand into something like
(let ((tests (list (make-test-section :header "Arithmetic tests"
:items (list (make-test-section :header "Addition"
:items (list (make-test-item :form '(= (+ 1 2) 3)
:description "Adding 1 and 2 results in 3"
:passp (= (+ 1 2) 3))
(make-test-item :form '(= (+ 1 2 3) 6)
:passp (= (+ 1 2 3) 6))
(make-test-item :form '(= (+ -1 -3) 4)
:passp (= (+ -1 -3) 4))))
(make-test-section :header "Subtraction"
:items (list (make-test-item :form '(= (- 1 2) 1)
:passp (= (- 1 2) 1))))))
(make-test-item :form '(= (sin 0) 0)
:passp (= (sin 0) 0)
:description "Sine of 0 equals 0"))))
(loop for test in tests
with total = 0
with passed = 0
do (display-test test 0 t)
do (multiple-value-bind (ttl p) (results test)
(incf total ttl)
(incf passed p))
finally (display-result total passed t)))
Here a list of tests is created; then we traverse it printing each test (0 denotes the zero level of indentation and t is as in format) and keeping track of the results, finally displaying the total results. I don't think explicit eval is needed here.
It may not be the most exquisite piece of code ever, but it seems manageable. I supply missing definitions below, they are rather trivial (and can be improved) and have nothing to do with macros.
Now we pass on to the macros. Consider both pieces of code as data, then we want a list processing function which would turn the first one into the second. A few auxiliary functions would come in handy.
The major task is to parse the body of ?? and generate the list of test to go inside the let.
(defun test-item-form (form description)
`(make-test-item :form ',form :description ,description :passp ,form))
(defun test-section-form (header items)
`(make-test-section :header ,header :items (list ,#items)))
(defun parse-test (forms)
(let (new-forms)
(loop
(when (null forms)
(return (nreverse new-forms)))
(let ((f (pop forms)))
(cond ((and (listp f) (eq (first f) '?))
(push (test-section-form (second f) (parse-test (nthcdr 2 f))) new-forms))
((stringp (first forms))
(push (test-item-form f (pop forms)) new-forms))
(t (push (test-item-form f nil) new-forms)))))))
Here parse-test essentially absorbs the syntax of ??. Each iteration consumes one or two forms and collects corresponding make-... forms. The functions can be easily tested in REPL (and, of course, I did test them while writing).
Now the macro becomes quite simple:
(defmacro ?? (&body body)
`(let ((tests (list ,#(parse-test body))))
(loop for test in tests
with total = 0
with passed = 0
do (display-test test 0 t)
do (multiple-value-bind (ttl p) (results test)
(incf total ttl)
(incf passed p))
finally (display-result total passed t))))
It captures a few symbols, both in the variable name space and in the function one (the expansion may contain make-test-item and make-test-section). A clean solution with gensyms would be cumbersome, so I'd suggest just moving all the definitions in a separate package and exporting only ?? and ?.
For completeness, here is an implementation of the test API. Actually, it's what I started coding with and proceeded until I made sure the big let-form works; then I passed on to the macro part. This implementation is fairly sloppy; in particular, it doesn't support terminal colours and display-test can't even output a section into a string.
(defstruct test-item form description passp)
(defstruct test-section header items)
(defun results (test)
(etypecase test
(test-item (if (test-item-passp test)
(values 1 1)
(values 1 0)))
(test-section (let ((items-count 0)
(passed-count 0))
(dolist (i (test-section-items test) (values items-count passed-count))
(multiple-value-bind (i p) (results i)
(incf items-count i)
(incf passed-count p)))))))
(defparameter *test-indent* 2)
(defun display-test-item (i level stream)
(format stream "~V,0T~:[(FAIL)~;(PASS)~] ~:['~S'~;~:*~A~]~%"
(* level *test-indent*)
(test-item-passp i)
(test-item-description i)
(test-item-form i)))
(defun display-test-section-header (s level stream)
(format stream "~V,0T[~A]~%"
(* level *test-indent*)
(test-section-header s)))
(defun display-test (test level stream)
(etypecase test
(test-item (display-test-item test level stream))
(test-section
(display-test-section-header test level stream)
(dolist (i (test-section-items test))
(display-test i (1+ level) stream)))))
(defun display-result (total passed stream)
(format stream "Results: ~D test~:P passed, ~D test~:P failed.~%" passed (- total passed)))
All the code is licenced under WTFPL.

Elisp Format specifier doesn't match argument type error

I am getting a "Format specifier doesn't match argument type" error when trying to run my main function interactively. My code is:
(defun average(grade)
(setq divide (/ grade 10))
(cond ((= divide 10) "A")
((= divide 9) "A")
((= divide 8) "B")
((= divide 7) "C")
((= divide 6) "D")
("F")))
(defun main(g)
(interactive "nGrade: ")
(message "%d" (average g )))
Can anyone help with what I am inputing/outputing wrong?
Thank you
The error is in the format line
(format "%d" (average g))
Wants to format an integer but you're returning a string, it should be:
(format "%s" (average g))
As an aside, M-x ielm is useful when testing elisp.

Illegal Function Call in Common Lisp

I'm working on making a two player tic-tac-toe game, and am in the phase where I work out all of the errors in my code. The current error i'm stuck on is an illegal function call error in the following code:
(cond
[...snip...]
((= CHOICE 3)
(IF (NUMBERP (AREF *BOARD* 0 2))
(SETF (AREF *BOARD* 0 2) *MARKER*)
(INVALID-SELECTION)))
What am I doing wrong?
EDIT The whole function looks like this:
(defun select (choice)
(cond ((= choice 1)
(if (numberp (aref *board* 0 0)) (setf (aref *board* 0 0) *marker*)
(invalid-selection))))
((= choice 2)
(if (numberp (aref *board* 0 1)) (setf (aref *board* 0 1) *marker*)
(invalid-selection))))
((= choice 3)
(if (numberp (aref *board* 0 2)) (setf (aref *board* 0 2) *marker*)
(invalid-selection))))
((= choice 4)
(if (numberp (aref *board* 1 0)) (setf (aref *board* 1 0) *marker*)
(invalid-selection))))
((= choice 5)
(if (numberp (aref *board* 1 1)) (setf (aref *board* 1 1) *marker*)
(invalid-selection))))
((= choice 6)
(if (numberp (aref *board* 1 2)) (setf (aref *board* 1 2) *marker*)
(invalid-selection))))
((= choice 7)
(if (numberp (aref *board* 2 0)) (setf (aref *board* 2 0) *marker*)
(invalid-selection))))
((= choice 8)
(if (numberp (aref *board* 2 1)) (setf (aref *board* 2 1) *marker*)
(invalid-selection))))
((= choice 9)
(if (numberp (aref *board* 2 2)) (setf (aref *board* 2 2) *marker*)
(invalid-selection))))
Your function only looks like that, only because it is not indented correctly.
Select the code and indent the region - any editor that understands a bit Lisp, should do that for you. In LispWorks this is done with the extended editor command 'Indent Region'.
You can also replace the COND with a simpler CASE:
(case choice
(1 ...)
(2 ...))
The whole function can be made smaller using CASE and a local function:
(defun select (choice)
(flet ((do-something (x y)
(if (numberp (aref *board* x y))
(setf (aref *board* x y) *marker*)
(invalid-selection))))
(case choice
(1 (do-something 0 0))
(2 (do-something 0 1))
(3 (do-something 0 2))
(4 (do-something 1 0))
(5 (do-something 1 1))
(6 (do-something 1 2))
(7 (do-something 2 0))
(8 (do-something 2 1))
(9 (do-something 2 2)))))
The first thing in a normally-evaluated form should almost always be a symbol that names a function, macro, or special operator. The first thing in your form is the list (= CHOICE 3). More context would help; as Cirno said, this looks like a disembodied COND clause.
edit I put your code in a function and added enough parentheses and variable definitions to evaluate it, and it evaluates fine. Still need more context.
I figured it out! I had too many parentheses in the function due to poor copy+pasting skills.