PC-LISP

From HandWiki

PC-LISP is an implementation of the Franz Lisp dialect by Peter Ashwood-Smith.[1][2][3]

Version 2.07 was released on 1 February 1986,[4] and version 3.00 was released on 1 February 1990.[1] A current version is available through GitHub.[2]

Currently, PC-LISP runs under 32 & 64 bit versions of Linux, Mac, Windows,[2] and NetBSD.[5] For NetBSD there also exists ports for AArch64, ARMv5/6/7, PowerPC, Motorola 68000, SPARC/SPARC64, Alpha and VAX.[5]

Note that the Franz LISP dialect was the immediate, portable successor to the ITS version of Maclisp[6] and is perhaps the closest thing to the LISP in the Steven Levy book Hackers as is practical to operate. PC-LISP is written primarily in the C programming language, with some parts now also written in Common Lisp.[2] Because PC-LISP implements Franz LISP, it is a dynamically scoped predecessor to modern Common Lisp.

Example

;; Demonstration of dynamic scoping

;; This is a "global" variable
(setq myglobal "this is my global variable")

;; Another global variable
(setq yourglobal "this is my global variable")

;; a function which prints the symbols
(defun dosomething (mine yours)
  (princ " * Mine is  - ")
  (princ mine)
  (princ "\n")
  (princ " * Yours is - ")
  (princ yours)
  (princ "\n"))

;; override the symbols
(defun nolocals ()
  (setq mine "I have set mine to a new value")
  (setq yours "I have set yours to a new value")
  (dosomething mine yours))

(defun main ()
  ;; define two symbols
  (setq mine myglobal)
  (setq yours yourglobal)
  
  ;; print them
  (princ "calling dosomething\n")
  (dosomething mine yours)
  (princ "calling nolocals\n")
  (nolocals)
  (princ "calling dosomething again\n")
  (dosomething mine yours))
; D(e,X) -
;          Will compute the symbolic derivative of expression e with respect
; to variable X. We take the expression in standard lisp prefix form and will
; use the following rules of differentiation.
;
;         D(x)    = 1
;         D(a)    = 0
;         D(ln u) = D(u)/u 
;         D(u+v)  = D(u)+D(v)
;         D(u-v)  = D(u)-D(v)
;         D(u*v)  = D(u)*v + u*D(v)
;         D(u/v)  = D(u)*v + (u*D(v))/v^2
;         D(v^u)  = (v^u)*(u*D(v)/v + D(u)*ln(v))
;
(defun  D(e X &aux u v)
 (cond ((equal e X) 1) 
       ((atom e) 0)           
       (t (setq u (cadr e) v (caddr e))
	  (caseq (car e)
		 (ln `(/ ,(D u X) ,u)) 
		 (+  `(+ ,(D u X) ,(D v X)))
		 (-  `(- ,(D u X) ,(D v X)))
		 (*  `(+  (* ,(D u X) ,v) (* ,(D v X) ,u)))
		 (/  `(-  (/ ,(D u X) ,v)
			  (/ (* ,u ,(D v X)) (^ ,v 2))))
		 (^  `(* ,e  (+ (/ (* ,v ,(D u X)) ,u)
				   (* ,(D v X) (ln ,u)))))
		 (t (princ "ERROR") (exit)]

References