gcl
Implementation of programming language Lispgcl is a short name for GNU Common Lisp compiler, which is included in GNU Compiler Collection. As its name implies, it implements Common Lisp dialect of Lisp.
Its first version was released in 1984 as Kyoto Common Lisp. After it in 1987 next version followed, called Austin Kyoto Common Lisp. It was added to GNU Collection under GNU GPL in 1994.
Its last version was released in 2005.
GCC logo
Links:
Examples:
Fibonacci numbers:
Example for versions Corman Common Lisp 3.0, clisp 2.47, gcl 2.6.6This example uses iterative definition of Fibonacci numbers, though expressed through recursive calls of fibiter
.
(defun fibonacci (n)
(defun fibiter (a b count)
(if (zerop count)
b
(fibiter (+ a b) a ( count 1)) ) )
(fibiter 1 0 n) )
(loop for i from 1 to 16
do (format t "~D, " (fibonacci i))
finally (format t "...~%") )
Factorial:
Example for versions Corman Common Lisp 3.0, SBCL 1.0.1, SBCL 1.0.29, clisp 2.47, gcl 2.6.6This example uses recursive factorial definition (which is natural for Lisp). Features:

math operators:
( n 1)
is prefix notation equivalent ton1
in infix notation; 
comparison operators:
(= n 0)
evaluates toT
if n is zero, and tonil
(used as false) otherwise; 
conditional operator
if
: Lisp expressions are evaluated using brackets, so they can be written in several lines; 
function definition using
defun
; 
Common Lisp macro
loop
; 
format specifiers in
format
:~D
corresponds to printing an integer, and~%
is endofline.
(defun factorial (n)
(if (= n 0)
1
(* n (factorial ( n 1))) ) )
(loop for i from 0 to 16
do (format t "~D! = ~D~%" i (factorial i)) )
Fibonacci numbers:
Example for versions Corman Common Lisp 3.0, SBCL 1.0.1, SBCL 1.0.29, clisp 2.47, gcl 2.6.6This example uses recursive definition of Fibonacci numbers and expands use of loop
macro to finally
clause (expression evaluated after the loop is done).
(defun fibonacci (n)
(if (< n 3)
1
(+ (fibonacci ( n 1)) (fibonacci ( n 2))) ) )
(loop for i from 1 to 16
do (format t "~D, " (fibonacci i))
finally (format t "...~%") )
Factorial:
Example for versions Corman Common Lisp 3.0, SBCL 1.0.1, SBCL 1.0.29, clisp 2.47, gcl 2.6.6In this example the inner loop with collect
clause produces a list of numbers from 1 to n
. After this operation *
is applied to this list, and the product of the numbers is printed.
(loop for n from 0 to 16
do (format t "~D! = ~D~%" n
(apply '* (loop for i from 1 to n
collect i)) ) )
Hello, World!:
Example for versions Corman Common Lisp 3.0, SBCL 1.0.1, SBCL 1.0.29, clisp 2.47, gcl 2.6.6When executed in interactive mode, program output looks as follows:
Hello, World!
NIL
First line contains standard output, second — the result of expression evaluation (in this case there is none).
(format t "Hello, World!~%")
Quadratic equation:
Example for versions Corman Common Lisp 3.0, SBCL 1.0.1, SBCL 1.0.29, clisp 2.47, gcl 2.6.6Common Lisp provides complex numbers as datatype, printed as #C(real imag)
. writetostring
converts a number into a string.
Note that for interactive evaluation it’s enough to add (quadraticroots2 1 0 1)
to see the result of calculation, while for compiled execution you’ll have to wrap call of this function in printing command, like (format t (quadraticroots2 1 0 1))
.
(defun quadraticroots2 (A B C)
(cond ((= A 0) (string "Not a quadratic equation."))
(t
(let ((D ( (* B B) (* 4 A C))))
(cond ((= D 0) (concatenate 'string "x = " (writetostring (/ (+ ( B) (sqrt D)) (* 2 A)))))
(t
(values (concatenate 'string "x1 = " (writetostring (/ (+ ( B) (sqrt D)) (* 2 A))))
(concatenate 'string "x2 = " (writetostring (/ ( ( B) (sqrt D)) (* 2 A)))))))))))
Comments
]]>blog comments powered by Disqus
]]>