Some functions from McCarthy paper in Emacs Lisp

Some functions from McCarthy paper in Emacs Lisp
(defun sgn (x)
  "Signal of x."
  (cond ((< x 0)
         -1)
        (t
         1)))

(defun absx (x)
  "Absolute value of x."
  (cond ((< x 0)
         -x)
        (t
         x)))

(defun delta (i j)
  "Kronecker's delta."
  (cond ((= i j)
         1)
        (t
         0)))

(defun factorial (n)
  "Factorial function."
  (cond ((= n 1)
         1)
        (t
         (* n (factorial (- n 1))))))

(defun gcd (m n)
  "Euclidean algorithm for the greatest common divisor."
  (cond ((> m n)
         (gcd n m))
        ((= 0 (rem* n m))
         m)
        (t
         (gcd (rem* n m) m))))

(defun sqrt (a x tol)
  "Heron method for sqrt(a)."
  (cond ((< (abs (- (* x x) a)) tol)
         x)
        (t
         (sqrt a (* .5 (+ x (/ a x))) tol))))

(defun and. (p q)
  "Logical and."
  (cond (p q)
        (t nil)))

(defun or. (p q)
  "Logical or."
  (cond (p t)
        (t q)))

(defun neg (p)
  "Logical negation."
  (cond (p nil)
        (t t)))

(defun implies (p q)
  (cond (p q)
        (t t)))
Palavras chave/keywords: Lisp, McCarthy, Emacs Lisp

Criado/Created: NaN

Última actualização/Last updated: 10-10-2022 [14:26]


Voltar à página inicial.


GNU/Emacs Creative Commons License

(c) Tiago Charters de Azevedo