/usr/share/common-lisp/source/clawk/utils.lisp is in cl-awk 1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ;;;; -*- Mode: Lisp -*-
(in-package #:clawk)
;; Code taken from Peter Norvig's _Paradigms of AI Programming_ book
(defun side-effect-free-p (exp)
(or (constantp exp) (atom exp) (starts-with exp 'function)
(and (starts-with exp 'the)
(side-effect-free-p (third exp)))))
(defmacro once-only (variables &rest body)
(assert (every #'symbolp variables))
(let ((temps (loop repeat (length variables) collect (gensym))))
`(if (every #'side-effect-free-p (list . ,variables))
(progn . ,body)
(list 'let
,`(list ,@(mapcar #'(lambda (tmp var)
`(list ',tmp ,var))
temps variables))
(let ,(mapcar #'(lambda (var tmp) `(,var ',tmp))
variables temps)
. ,body)))))
|