How to define constant like this in lisp?
common-lisp, python
Solution
It would be more idiomatic in Lisp to just use symbols. Typically as self-evaluating keyword symbols:
(defparameter *chess-pieces*
'(:EMPTY :PAWN :KNIGHT :BISHOP :ROOK :QUEEN :KING :BPAWN))
There are reasons to define numeric values - sometimes. Especially when you need to talk to foreign functions. In Lisp you would by default use symbols.
Common Lisp does not have a real enumeration type. Using symbols in a dynamically typed language has some advantages over using numeric variables. For example during debugging the variable contents are more descriptive:
Compare:
> (setf c4 queen)
> c4
6
vs.
> (setf c4 :queen)
> c4
:queen
In the latter example the symbol value is self-descriptive.
Problem
In python it's possible to do this ``` EMPTY, PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING, BPAWN = range(8) ``` How would you do equivalent in lisp?