LISP Tutorial
LISP Useful Resources
Selected Reading
- LISP - CLOS
- LISP - Error Handling
- LISP - Packages
- LISP - Structures
- LISP - File I/O
- LISP - Input & Output
- LISP - Hash Table
- LISP - Tree
- LISP - Set
- LISP - Vectors
- LISP - Symbols
- LISP - Lists
- LISP - Sequences
- LISP - Strings
- LISP - Arrays
- LISP - Characters
- LISP - Numbers
- LISP - Predicates
- LISP - Functions
- LISP - Loops
- LISP - Decisions
- LISP - Operators
- LISP - Constants
- LISP - Variables
- LISP - Macros
- LISP - Data Types
- LISP - Basic Syntax
- LISP - Program Structure
- LISP - Environment
- LISP - Overview
- LISP - Home
LISP Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
LISP - Constants
LISP - Constants
In LISP, constants are variables that never change their values during program execution. Constants are declared using the defconstant construct.
Example
The following example shows declaring a global constant PI and later using this value inside a function named area-circle that calculates the area of a circle.
The defun construct is used for defining a function, we will look into it in the Functions chapter.
Create a new source code file named main.psp and type the following code in it.
(defconstant PI 3.141592) (defun area-circle(rad) (terpri) (format t "Radius: ~5f" rad) (format t "~%Area: ~10f" (* PI rad rad))) (area-circle 10)
When you cpck the Execute button, or type Ctrl+E, LISP executes it immediately and the result returned is.
Radius: 10.0 Area: 314.1592Advertisements