From: Giorgos Pontikakis
Subject: proclaim/declaim and multiple source files
Date: 
Message-ID: <1138483557.730855.152150@g43g2000cwa.googlegroups.com>
Hi,

I have some code spread over several files, and a file "load.lisp"
which loads everything with the following code:

(defun compile-files (files-list)
  (with-compilation-unit ()
    (mapcar #'(lambda (file)
		(compile-file (concatenate 'string file ".lisp")))
	    files-list)))

(defun load-files (files-list)
  (with-compilation-unit ()
    (mapcar #'(lambda (file)
		(load (concatenate 'string file ".x86f"))) ;; CMUCL
	    files-list)))

(let ((my-files
       '("/path/to/file1"
	 "/path/to/file2"
	 "/path/to/file3")))
  (compile-files my-files)
  (load-files my-files))

The beginning of file1, file2 and file3 is:

(declaim (optimize (speed 0) (space 0) (safety 3) (debug 3)))

I use declaim in every file because the CLHS says that:
"If a use of this macro appears as a top level form in a file being
processed by the file compiler, the proclamations are also made at
compile-time." The problem is, when I want to optimize for speed, I
have to change every file so that its first lines read, for example:

(declaim (optimize (speed 3) (space 0) (safety 0) (debug 0)))

which may be cumbersome in the case of tens of files, unless I use a
shell script. I suppose that a way to change optimization settings
from a single place is to use proclaim, which, according to CLHS,
refers to the global environment. But I am not so sure what is meant
by the global environment. Is it the current file? The current
package? Every package?

I think that I can ommit the declaim expressions from the files, and
use in the file "load.lisp":

(eval-when (:compile-toplevel :load-toplevel :execute)
  (proclaim '(optimize (speed 0) (space 0) (safety 3) (debug 3))))

(let ((my-files
       '("/path/to/file1"
	 "/path/to/file2"
	 "/path/to/file3")))
  (compile-files my-files)
  (load-files my-files))

Will this have the intended effect? Or maybe should I use, in the file
"load.lisp":

(defun optimizations ()
  '(optimize (speed 0) (space 0) (safety 3) (debug 3)))

and then, at the beginning of each file:

(proclaim (optimizations 0 0 3 3))

In this case, I am not sure what I should do if files 1 2 and 3 start
with a different in-package expression (and there is also a file named
"packages.lisp" that defines the packages).

Can anybody help?
Thank you very much in advance,

-- Giorgos
From: Barry Margolin
Subject: Re: proclaim/declaim and multiple source files
Date: 
Message-ID: <barmar-88337E.17220428012006@comcast.dca.giganews.com>
In article <························@g43g2000cwa.googlegroups.com>,
 "Giorgos Pontikakis" <·······@gmail.com> wrote:

> I think that I can ommit the declaim expressions from the files, and
> use in the file "load.lisp":
> 
> (eval-when (:compile-toplevel :load-toplevel :execute)
>   (proclaim '(optimize (speed 0) (space 0) (safety 3) (debug 3))))
> 
> (let ((my-files
>        '("/path/to/file1"
> 	 "/path/to/file2"
> 	 "/path/to/file3")))
>   (compile-files my-files)
>   (load-files my-files))
> 
> Will this have the intended effect? Or maybe should I use, in the file
> "load.lisp":

Yes, it should have the intended effect.  You also don't need the 
EVAL-WHEN, since it only affects what happens when you compile 
load.lisp, which doesn't really matter.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***