#+:LISPWORKS  (in-package "CL-USER")

;; file boot-gpstar.lisp  for any version of LISP


;; can use :cl foo to compile and load in alload
(proclaim '(optimize (speed 3) (safety 3) (compilation-speed 0) (space 1)
		     ;;(debug 3)
		     ))

;; ------------------------- GLOBALS FOR COMPILATION ---------------------------
(defvar *current-experiment* 
  "holds name of current loaded experiment in terms of init function")

(defvar *myPath* "" )

(setq *mypath* "/home/mb2/unamay/gpstar/")
(defvar *scratchPath* "" )

(defvar *fasl-path*)
(setf *fasl-path* "/home/mb2/unamay/venus-scratch/")

(defvar *seedFile* "" )
(setq *seedFile* "myrng.seeds1")

(defvar *source-path* "")
(setq *source-Path* "/home/mb2/unamay/gpstar/")

;; ------------------------------- UTILITY ROUTINES ---------------------------
;(defmacro double-float (x) `(float ,x))  
;;(defun double-float (x) (float x))  APPEARS UN-NEEDED IN LW

(defun tenuring (X) ())
(defun promptThenReadFn (aString)
    (declare (string aString))
	(print aString *standard-output*)
	(read *standard-input*))

(defun yesNoPrompt (aString)
  "returns t or nil after converting yes or no response"
  (let (reply (quit nil))
    (do ()
        (quit)
      (setf reply (promptThenReadFn aString))
      (setf quit (or (string-equal reply "n")
                     (string-equal reply "no")
                     (string-equal reply "y")
                     (string-equal reply "yes")))
      (if quit 
        (setf reply (or (string-equal reply "y")
                        (string-equal reply "yes")))))
    reply))
 
;; ------------------------------- ROUTINES ---------------------------


(defun setup-scratch-path ()
  (let ((site-name (long-site-name))
	)
    (cond ((equal site-name "atalaya")
	   (setq *scratchpath* "/System/Users/unamay/a-scratch/"))

	  ((equal site-name "unspecified")   ;;mcl on macii
	   (setq *scratchpath* "LaCie 165-Q:Una-May:gpstar-may95:scratch-folder:"))

	  ((equal site-name "penitente")
	   (setq *scratchpath* "/System/Users/unamay/pen-scratch/"))
	  
	  ((equal site-name "santaclara")
	   (setq *scratchpath* "/System/Users/unamay/sc-scratch/"))

	  ((equal site-name "shabikeschee")
	   (setq *scratchpath* "/System/Users/unamay/shab-scratch/"))
	  
	  ((equal site-name "wupatki")
	   (setq *scratchpath* "/System/Users/unamay/wu-scratch/"))

	  ((equal site-name "pojoaque")
	   (setq *scratchpath* "/System/Users/unamay/poj-scratch/"))

	  ((equal site-name "winnetou")
	   (setq *scratchpath* "/System/Users/unamay/win-scratch/"))
	  
	  ((equal site-name "wijiji")
	   (setq *scratchpath* "/System/Users/unamay/wij-scratch/"))	  

	  ((equal site-name "coronado")
	   (setq *scratchpath* "/System/Users/unamay/c-scratch/"))	  

	  ((equal site-name "grasshopper")
	   (setq *scratchpath* "/System/Users/unamay/gr-scratch/"))

	  ((equal site-name "tsankawi")
	   (setq *scratchpath* "/System/Users/unamay/t-scratch/"))

	  ((equal site-name "MIT Artificial Intelligence Laboratory") 
	   ;;site-name should be the same for all sun-os machines at ai lab

#+:LUCID  (cond ((equal *this-host* "venus")
		   (setq *scratchpath* "/home/mb2/unamay/venus-scratch/")
		   (format t "LUCID: on venus: Set the scratch path to ~A~%" *scratchpath*)
		   (setf *fasl-path* "/home/mb2/unamay/venus-scratch/lucid-fasl-dir/")
		   (format t "LUCID: on venus: Set the fasl path to ~A~%" *fasl-path*))
		  ((equal *this-host* "saturn")
		   (setq *scratchpath* "/home/mb2/unamay/saturn-eyes-scratch/")
		   (format t "LUCID: on saturn: Set the scratch path to ~A~%" *scratchpath*)
		   (setf *fasl-path* "/home/mb2/unamay/saturn-eyes-scratch/lucid-fasl-dir/")
		   (format t "LUCID: on saturn: Set the fasl path to ~A~%" *fasl-path*))
		  );;cond
#+:LISPWORKS 
           (progn
	     (setq *scratchpath* "/home/mb2/unamay/saturn-eyes-scratch/")
	     (format t "LUCID: Set the scratch and fasl path to ~A~%" *scratchpath*)
	     (setf *fasl-path* "/home/mb2/unamay/saturn-eyes-scratch/lucid-fasl-dir/")
	   ) ;;progn

	   )  ;clause
	  ((and (null site-name) (equal *this-host* "saturn"));; this is solaris OS and LUCID
	   (setq *scratchpath* "/home/mb2/unamay/saturn-eyes-scratch/")
	   (setf *fasl-path* "/home/mb2/unamay/saturn-eyes-scratch/fasl-dir/")
	   (format t "Set the scratch and fasl path to ~A~%" *scratchpath*)
	   )
	  ((and (equal site-name "Unknown") (equal *this-host* "venus"));; this is solaris OS and LUCID
	   (setq *scratchpath* "/home/mb2/unamay/eyes-scratch/")
	   (setf *fasl-path* "/home/mb2/unamay/eyes-scratch/fasl-dir/")
	   (format t "Set the scratch and fasl path to ~A and ~A~%" *scratchpath* *fasl-path*)
	   )
          ((and (equal site-name "Unknown") (equal *this-host* "saturn"))
           (setq *scratchpath* "/home/mb2/unamay/saturn-eyes-scratch/")
	   (setf *fasl-path* "/home/mb2/unamay/saturn-eyes-scratch/so-fasl-dir/")
	   (format t "Set the scratch path to ~A~%" *scratchpath*)
	   (format t "Set the solaris fasl path to ~A~%" *fasl-path*)
	   (format t "The OSTYPE is ~A, " *this-os*)
	   )
;;; PLUTO
	  ((and (equal site-name "Unknown") (equal *this-host* "pluto"))
           (setq *scratchpath* "/home/mb2/unamay/pluto-scratch/")
	   (setf *fasl-path* "/home/mb2/unamay/pluto-scratch/so-fasl-dir/")
	   (format t "Set the scratch path to ~A~%" *scratchpath*)
	   (format t "Set the solaris fasl path to ~A~%" *fasl-path*)
	   (format t "The OSTYPE is ~A, " *this-os*)
	   )

          ((and (equal site-name "Unknown") (equal *this-host* "wonderbug"))
           (setq *scratchpath* "/home/mb2/unamay/bug-scratch/")
	   (setf *fasl-path* "/net/saturn/usr/unamay-scratch/so-fasl-dir/")
	   (format t "Set the scratch path to ~A~%" *scratchpath*)
	   (format t "Set the solaris fasl path to ~A~%" *fasl-path*)
	   (format t "The OSTYPE is ~A, " *this-os*)
	   )
          ((and (equal site-name "Unknown") (equal *this-host* "general-lee"))
           (setq *scratchpath* "/home/mb2/unamay/gl-scratch/")
	   (setf *fasl-path* "/net/saturn/usr/unamay-scratch/so-fasl-dir/")
	   (format t "Set the scratch path to ~A~%" *scratchpath*)
	   (format t "Set the solaris fasl path to ~A~%" *fasl-path*)
	   (format t "The OSTYPE is ~A, " *this-os*)
	   )
	  (t
	   (format t "Unrecognized site: ~A~% for setting scratch path" site-name) 
	   (setq *scratchpath* "/home/mb2/unamay/venus-scratch/"))
	  )
    (format t "LISP Host: ~A, Environment HOST ~A~%" site-name *this-host*)
    ))

#| (if (equal *which-Lisp* "acl")
    (progn
      (setf (sys:gsgc-switch :print) nil)
      (setf (sys:gsgc-switch :verbose) nil)
      ))  |#
;; --------------------------- MCL GARBAGE COLLECTION ---------------------------
#+:MCL(defun unaEgc ()
  (egc-configuration)
  (egc nil)
  (configure-egc 256 512 512)
  (egc t)
  (egc-configuration))

#+:MCL(defun systemEgc ()
  (egc-configuration)

  (egc nil)
  (configure-egc 64 128 256)
  (egc t)
  (egc-configuration)) 

(defun checkSpecialEgc ()
#+:MCL
(if (y-or-n-p "Special egc (else system default)?")
    (unaegc)
  (systemegc))
)  ;; check SpecialEgc


;; -----------------------------  TREE DISTANCE STUFF -----------------------

(defun load-tree-dist-c-stuff ()
  (format t "THe directories are from path: unamay/gpstar/c-code/Tree/~%")

#+:LUCID
  (cond ((y-or-n-p "Do you want to load the tree distance .o's?")
	 (let (subdir)
	   (do ((found nil) )
	       ((find subdir (list 'mult 'mult11 'bs 'sort2)) subdir)
	     (format t "Enter which subdirectory: mult mult11 bs sort2: ")
	     (setf subdir (read *standard-input*)))
	   (cond ((equal 'mult subdir)
		  (load-foreign-files  '("/home/mb2/unamay/gpstar/c-code/Tree/mult/treedist.o"
			  "/home/mb2/unamay/gpstar/c-code/Tree/mult/driver.o"))
		  (format t "Loaded treedist.o and driver.o from Tree/mult~%"))
		 ((equal 'mult11 subdir)
		  (load-foreign-files '("/home/mb2/unamay/gpstar/c-code/Tree/mult11/treedist.o"
			  "/home/mb2/unamay/gpstar/c-code/Tree/mult11/driver.o"))
		  (format t "Loaded treedist.o and driver.o from Tree/mult11~%"))
		 ((equal 'bs subdir)
		  (load-foreign-files  '("/home/mb2/unamay/gpstar/c-code/Tree/bs/treedist.o"
			  "/home/mb2/unamay/gpstar/c-code/Tree/bs/driver.o"))
		  (format t "Loaded treedist.o and driver.o from Tree/bs~%"))
		 ((equal 'sort2 subdir)
		  (load-foreign-files '("/home/mb2/unamay/gpstar/c-code/Tree/sort2/treedist.o"
			  "/home/mb2/unamay/gpstar/c-code/Tree/sort2/driver.o"))
		  (format t "Loaded treedist.o and driver.o from Tree/sort2~%"))
		 (t (format t "Error in tree distance .o load~%"))))));; end of cond
#+:LISPWORKS
  (cond  ((and (equal *which-lisp* "lispworks") (or (equal *this-host* "saturn")
						    (equal *this-host* "pluto")))

	  (let (subdir)
	    (do ((found nil) )
		((find subdir (list 'mult 'mult11 'bs 'sort2)) subdir)
	      (format t "Enter which subdirectory: mult mult11 bs sort2: ")
	      (setf subdir (read *standard-input*)))
	    (cond ((equal 'mult subdir)
		   (foreign:read-foreign-modules  "/home/mb2/unamay/gpstar/c-code/Tree/mult/treedist.o")
		   (foreign:read-foreign-modules  "/home/mb2/unamay/gpstar/c-code/Tree/mult/driver.o")
		   (format t "Loaded treedist.o and driver.o from Tree/mult~%"))
		  ((equal 'mult11 subdir)
		   (foreign:read-foreign-modules "/home/mb2/unamay/gpstar/c-code/Tree/mult11/treedist.o"
					 "/home/mb2/unamay/gpstar/c-code/Tree/mult11/driver.o")
		   (format t "Loaded treedist.o and driver.o from Tree/mult11~%"))
		  ((equal 'bs subdir)
		   (foreign:read-foreign-modules  "/home/mb2/unamay/gpstar/c-code/Tree/bs/treedist.o"
					  "/home/mb2/unamay/gpstar/c-code/Tree/bs/driver.o")
		   (format t "Loaded treedist.o and driver.o from Tree/bs~%"))
		  ((equal 'sort2 subdir)
		   (foreign:read-foreign-modules "/home/mb2/unamay/gpstar/c-code/Tree/sort2/treedist.o"
					 "/home/mb2/unamay/gpstar/c-code/Tree/sort2/driver.o")
		   (format t "Loaded treedist.o and driver.o from Tree/sort2~%"))
		  (t (format t "Error in tree distance .o load~%")))
	    )));

  )

;; ------------------------------- LOADING THE SA code written in C ------------
(defun load-sa-c-binaries ()

#+:LUCID
  (cond  ((and (equal *which-lisp* "lucid") (not (equal *this-host* "saturn")))
	  ;;(use-package :ff)
	  ;;(require :foreign)
	  (load-foreign-files  '("/home/mb2/unamay/gpstar/c-code/sa.o"))
	  (format t "Loaded sa.o from c-code~%") 
	  )
	 ((and (equal *which-lisp* "lucid") (equal *this-host* "saturn"))
	  (load-foreign-files '("/home/mb2/unamay/gpstar/c-code/solaris/sa.o"))
	  (format t "Loaded sa.o from c-code in solaris subdirectory~%") 
	  )  
	 (t (format "Check *which-lisp* and *this-host*, load-sa-binaries not sure what to load~%"))
);;end of cond for lucid

#+:LISPWORKS
(cond  ((and (equal *which-lisp* "lispworks") (not (equal *this-os* "solaris")))
          (foreign:read-foreign-modules "/home/mb2/unamay/gpstar/c-code/sa.o")
          (format t "~%Loaded SunOs binarysa.o from gpstar/c-code/ for lispworks~%")
          )
         ((and (equal *which-lisp* "lispworks") (equal *this-os* "solaris"))
          (foreign:read-foreign-modules "/home/mb2/unamay/gpstar/c-code/solaris/sa.o")
          (format t "~%Loaded solaris binary sa.o from gpstar/c-code/solaris (LISPWORKS)~%")
          )
	 (t (format t "WARNING No foreign load of SA code, check *which-lisp* and *this-host*~%")))  ;; end of cond for lispworks
);; end of defun
(load-sa-c-binaries)


(defun load-fasl-list (file-list)
  (let (loadfile)
    (setf *print-pretty* t)
  #+:MCL  (setf *backtrace-on-break* t)
  #+:MCL  (setf *save-local-symbols* t)
  #+:MCL  (setf *fasl-save-local-symbols* t)
    (checkSpecialEgc)
    (tenuring 
     (dolist (fname file-list)
	   (setf loadfile (concatenate 'string *fasl-Path* (string fname) ".wfasl"))
	   (load loadfile :verbose nil :print nil))
     ) ;end of tenuring
    )) ;;end of load-fasl-list

(defun load-lisp-list (file-list)
  (let (loadfile)
    (setf *print-pretty* t)
    #+:MCL(setf *backtrace-on-break* t)
    #+:MCL(setf *save-local-symbols* t)
    #+:MCL(setf *fasl-save-local-symbols* t)
    (checkSpecialEgc)
    (setf *load-verbose* t)
    ;;(checkForDebug)
    (dolist (fname file-list)
	   (setf loadfile (concatenate 'string *source-Path* (string fname) ".lisp"))
	   (load loadfile))
    )) ;;end of load-lisp-list

(defun compile-file-list (file-list &optional (verbose-flag t) (print-level 1))
  (let (compile-file fasl-file)
    (setf *print-pretty* t)
    #+:MCL(setf *backtrace-on-break* t)
    #+:MCL(setf *save-local-symbols* t)
    #+:MCL(setf *fasl-save-local-symbols* t)
    (dolist (fname file-list)
	    (setf compile-file (concatenate 'string *source-Path*  (string fname) ".lisp"))
	    (setf fasl-file (concatenate 'string *fasl-Path*  (string fname) ".wfasl"))	    
	    (compile-file compile-file :output-file fasl-file :load t
			  :verbose verbose-flag :print print-level)
	    ;;(break)
	    )))

(defun cl-random ()
  (let (compile-file fasl-file)
  (setf compile-file (concatenate 'string *source-Path*  "random.lisp"))
  (setf fasl-file (concatenate 'string *fasl-Path* "random.wfasl"))
  (compile-file compile-file :output-file fasl-file :load t
	      :verbose t) 
  ));;let and defun

;; to load the lisp use (load "random.lisp")


(defvar *gp-file-list* 
'("random" "utils" "ifmacro" "du" "du-new" "structs" "dependMCLUna" "gp-hc-decls"
		  "dgadefs" "mgdefs" "initvars" 
#+:LISPWORKS		  "flip" 
                  "shuffle"
		  "rotation"  "driver" "dga" "sga2" "koza" "experiments"
		  "fitness" "reports" "gp-hc" 
		  "lc"  "mgprint" "mgutils" "mgxo" "mggen"
		  "regression" "hash" "pipe-blt" "adfs-and-typing" "c-to-blt" "eyes-1-regression" "distance"
		  ))


;; NOTE LEFT OUT MGINIT
#|
(setf *gp-file-list* '("structs" "dependMCLUna" "gp-hc-decls"
		  "dgadefs" "mgdefs" "initvars" "flip" "rotation"  "driver" "dga" "sga2" "koza" "experiments"
		  "fitness" "reports" "gp-hc" 
		  "lc"  "mgprint" "mgutils" "mgxo" "mggen"
		  "regression" "hash" "pipe-blt" "adfs-and-typing" "c-to-blt" "eyes-1-regression"))
|#
(defun loadgpstar ()  
  "load gpstar fasl's from gp.mcl folder"
  (setup-scratch-path) 	
  ;(setq *fasl-path* *scratchpath*)
  (load-fasl-list *gp-file-list*)
  (help-message)
)

(defun loadgpstarL ()  
  "load source from folder gpstar.cl except for MCL dependent stuff"
    (load-lisp-list *gp-file-list*)
    (loadmgl)
    (load-lisp-list *landscape-stuff-file-list*)
    (help-message)
  ) ;; end of loadgpstarl
  
(defun compilegpstar ()
  "compile code into gpstar.MCL fasl's"
  (setup-scratch-path) 	
  (compile-file-list *gp-file-list*)
)

(defun compileAndloadgpstar ()
  (setup-scratch-path) 	
  ;(setq *fasl-path* *scratchpath*)
  ;;(compilegpstar)
  (format t "Performing silent compile of gpstar code~%")
  (compile-file-list *gp-file-list* nil -1)  ;; nil and -1 make the compile silent
  (loadgpstar)
  (help-message)
)

(defun compileAndloadgpstartwice ()
  (compileandloadgpstar)
  (compileandloadgpstar)
  (help-message)
)

(defvar *gp-mg-file-list* '("mgdefs" "mgutils" "mgxo" "mggen"))
;(defvar *gp-mg-file-list* '("mgdefs" "mginit" "mgprint" "mgutils" "mgxo" "mggen"))

(defun loadmgl ()
    (load-lisp-list *gp-mg-file-list*))

(defun loadmg ()
    (load-fasl-list *gp-mg-file-list*))

(defun loadMultl () 
  (load (concatenate 'string *source-Path* "multiplexor.lisp"))
  (load (concatenate 'string *source-Path* "mult-gen.lisp")))
(defun loadMult () 
  (load (concatenate 'string *fasl-Path* "multiplexor.wfasl"))
  (load (concatenate 'string *fasl-Path* "mult-gen.wfasl")))

(defun compileMult () 
  (compile-file (concatenate 'string *source-Path* "multiplexor.lisp")
                :output-file (concatenate 'string *fasl-Path* "multiplexor.wfasl") :verbose nil :print -1)
  (compile-file (concatenate 'string *source-Path* "mult-gen.lisp")
		:verbose nil :print -1
                :output-file (concatenate 'string *fasl-Path* "mult-gen.wfasl")))
(defun loadMult11l () 
  (load (concatenate 'string *source-Path* "mult11.lisp")))
(defun loadMult11 () 
  (load (concatenate 'string *fasl-Path* "mult11.wfasl")))

(defun compileMult11 () 
  (compile-file (concatenate 'string *source-Path* "mult11.lisp")
		:verbose nil :print -1
                :output-file (concatenate 'string *fasl-Path* "mult11.wfasl")))

(defvar *gp-histo-file-list* '("hist1" "hist2" "histFac" "paths"))

(defun loadHist ()
    (load-lisp-list *gp-histo-file-list*))
  

(defvar *sortexpold-file-list* '("sortfn" "sorttest" "sort" "sortexpold"))
(defvar *sortexpa-file-list* '("sortfn" "sorttest" "sort" "sortexpa" "sort-gen"
                               "sort-coaching"))

(defun loadSortExpoldL ()
    (load-lisp-list *sortexpold-file-list*))

(defun loadSortExpAL ()
    (load-lisp-list *sortexpa-file-list*))


(defun loadSortExpOld ()
    (load-fasl-list *sortexpold-file-list*))

(defun loadSortExpA ()
    (load-fasl-list *sortexpa-file-list*))


(defun compileSOrtexpold ()
    (compile-file-list *sortexpold-file-list*))
 
(defun compileSOrtexpa ()
    (compile-file-list *sortexpa-file-list* nil -1))
                  ;;nil and -1 are verbose and print-level

(defun compileANdLoadSortexpa ()
       (compileSortexpa)
       (loadsortexpa))

(defun compileANdLOadSortexpOld ()
       (compileSortexpold)
       (loadsortexpold))

(defun compile-5-parity ()
  (compile-file (concatenate 'string *source-Path* "5-parity.lisp")
		:verbose nil :print -1
                :output-file (concatenate 'string *fasl-Path* "5-parity.wfasl")))

(defun load-5-parity ()
  (load (concatenate 'string *fasl-Path* "5-parity.wfasl")))

(defun load-5-parityl ()
  (load (concatenate 'string *source-Path* "5-parity.lisp")))

(defun compile-6-parity ()
  (compile-file (concatenate 'string *source-Path* "6-parity.lisp")
		:verbose nil :print -1
                :output-file (concatenate 'string *fasl-Path* "6-parity.wfasl")))

(defun load-6-parity ()
  (load (concatenate 'string *fasl-Path* "6-parity.wfasl")))

(defun load-6-parityl ()
  (load (concatenate 'string *source-Path* "6-parity.lisp")))

(defun compile-7-parity ()
  (compile-file (concatenate 'string *source-Path* "7-parity.lisp")
		:verbose nil :print -1
                :output-file (concatenate 'string *fasl-Path* "7-parity.wfasl")))

(defun load-7-parity ()
  (load (concatenate 'string *fasl-Path* "7-parity.wfasl")))

(defun load-7-parityl ()
  (load (concatenate 'string *source-Path* "7-parity.lisp")))


(defun loadUMORdeltaL ()
  #+:MCL(setf *backtrace-on-break* t)
  #+:MCL(setf *save-local-symbols* t)
  #+:MCL(setf *fasl-save-local-symbols* t)
  ;(load "Macintosh HD:Users:Una-May:gp:changedfiles->UM:deltas.lisp")
)


#|   I DON'T KNOW WHERE THIS FILE IS!!!
(defun compileAndloadFib ()
  (compile-file (concatenate 'string *source-Path* "fib.koza"))
  (print "Loading fib.koza")
  (load (concatenate 'string *source-Path* "fib.wfasl")))

(defun loadgpstarAndFib ()
  (loadgpstar)
  (loadFib))

|#
(defun addDebugFlags ()
  (if (not (find 'ga-Debug *features*))
    (setf *features* (cons 'ga-debug *features*)))
  *features*)

(defun delDebugFlags ()
  (if (find 'ga-Debug *features*)
    (setf *features* (delete 'ga-debug *features*)))
    *features*)

(defun checkForDebug ()
(if (y-or-n-p " debug statements to be compiled?")
  (addDebugFlags)
  (delDebugFlags)))

(defun compileAndLoadBS ()
  (compileBS)
  (loadBS))
(defun compileBS ()
  (compile-file (concatenate 'string *source-Path* "BlockStacking.lisp")
		:verbose nil :print -1
                :output-file (concatenate 'string *fasl-Path* "BlockStacking.wfasl")))

(defun loadBS ()
  (load (concatenate 'string *fasl-Path* "BlockStacking.wfasl"))
  )

(defun loadlandscapesl ()
  (load (concatenate 'string *source-Path* "landscapes.lisp")))

(defun compileLandscapes ()
  (compile-file (concatenate 'string *source-Path* "landscapes.lisp")
                :output-file (concatenate 'string *fasl-Path* "landscapes.wfasl")))

(defun loadLandscapes ()
  (tenuring
  (load (concatenate 'string *fasl-Path* "landscapes.wfasl")))
  )

(defun compileAndLoadlandscapes ()
  (compileLandscapes)
  (loadLandscapes))

(defun loadresumel ()
  (load (concatenate 'string *source-Path* "resume.lisp")))


(defun compileresume ()
  (compile-file (concatenate 'string *source-Path* "resume.lisp")
                :output-file (concatenate 'string *fasl-Path* "resume.wfasl")))

(defun loadresume ()
  (tenuring
  (load (concatenate 'string *fasl-Path* "resume.wfasl")))
  )

(defun compileAndLoadresume ()
  (compileresume)
  (loadresume))

(defun compilemutate ()
  (compile-file (concatenate 'string *source-Path* "mutate.lisp")
                :output-file (concatenate 'string *fasl-Path* "mutate.wfasl")))

(defun loadmutate ()
  (tenuring
  (load (concatenate 'string *fasl-Path* "mutate.wfasl")))
  )

(defun compileAndLoadmutate ()
  (compilemutate)
  (loadmutate))

(defun loadmutatel ()
  (load (concatenate 'string *source-Path* "mutate.lisp")))


(defun loadsal ()
  (load (concatenate 'string *source-Path* "sa.lisp")))


(defun compilesa ()
  (compile-file (concatenate 'string *source-Path* "sa.lisp")
                :output-file (concatenate 'string *fasl-Path* "sa.wfasl")))

(defun loadsa ()
  (load (concatenate 'string *fasl-Path* "sa.wfasl"))
  )

(defun compileAndLoadsa ()
  (compilesa)
  (loadsa))
(defvar *landscape-stuff-file-list* 
  '("landscapes" "xosa" "xosa-output" "mutate" "sa" "resume"))

(defun compileLandscapeStuff (&optional (silent nil))
  (if silent
      (compile-file-list *landscape-stuff-file-list* nil -1)
    (compile-file-list *landscape-stuff-file-list*)))

(defun loadLandscapeStuff ()
    (load-fasl-list *landscape-stuff-file-list*))

(defun compileAndLoadLandscapeStuff (&optional (silent nil))
  (compileLandscapeStuff silent)
  (loadLandscapeStuff))

(defun loadLandscapeStuffl ()
    (load-lisp-list *landscape-stuff-file-list*))

(defun compileANdloadTheWholeWorks ()
  "compiles and load all the gpstar code and landscape code"
  (setup-scratch-path) 	
  ;;(setq *fasl-path* *scratchpath*)
  (compileandLoadgpstar)
  (compileAndLoadLandscapeStuff t) ;;silent is true
  (help-message)
)

(defun LoadTheWholeWorks ()
  (setup-scratch-path)
  ;;(setq *fasl-path* *scratchpath*)
  (loadgpstar)(loadlandscapestuff)
  (help-message)
)

(defun loadthewholeworksl ()
  (setup-scratch-path)
  ;;(setq *fasl-path* *scratchpath*)
  (loadgpstarl) (loadlandscapestuffl)
  (help-message)
)


;;first time ever?? use loadthewholeworksl, compileandloadthewholeworks
;;  /*  prompt stuff  */
;;;
(defun gpstar-prompt			()
  (setup-scratch-path)
  ;;(setq *fasl-path* *scratchpath*)
  (cond ((yesNoPrompt "Load gpstar binaries? (Y/N) -> ")
         (loadgpstar)))
  (cond ((yesNoPrompt "Recompile and load gpstar? (Y/N) -> ")
         (compileandloadgpstar)))
  (cond ((yesNoPrompt "Recompile and load landscape files (landscapes, mutate, sa, resume) ? (Y/N) -> ")
         (compileandloadlandscapeStuff)))
  (format t "Use load-experiment to compile and load experiment files~%~%")
)

(defun gpstarl-prompt ()
  (cond ((yesNoPrompt "Load gpstar lisp files? (Y/N) -> ")
         (loadgpstarl)))
  (cond ((yesNoPrompt "Load gpstar lisp files again? (Y/N) -> ")
         (loadgpstarl)))
  (cond ((yesNoPrompt "Load landscape stuff lisp files? (Y/N) -> ")
         (loadLandscapeStuffL)))        
  (format t "Use load-experiment to compile and load experiment files~%~%")
)

 (defun loadBSl ()
  (load (concatenate 'string *source-Path* "BlockStacking.lisp")))

(load "experiments.lisp")

(defun compile-3-parity ()
  (compile-file (concatenate 'string *source-Path* "3-parity.lisp")
		:verbose nil :print -1
                :output-file (concatenate 'string *fasl-Path* "3-parity.wfasl")))

(defun load-3-parity ()
  (load (concatenate 'string *fasl-Path* "3-parity.wfasl")))

(defun load-3-parityl ()
  (load (concatenate 'string *source-Path* "3-parity.lisp")))

(defun compile-3p-typing ()
  (compile-file (concatenate 'string *source-Path* "3p-typing.lisp")
		:verbose t :print 1
                :output-file (concatenate 'string *fasl-Path* "3p-typing.wfasl")))

(defun load-3p-typing ()
  (load (concatenate 'string *fasl-Path* "3p-typing.wfasl")))

(defun load-3p-typing ()
  (load (concatenate 'string *source-Path* "3p-typing.lisp")))


(defun compile-4-parity ()
  (compile-file (concatenate 'string *source-Path* "4-parity.lisp")
		:verbose nil :print -1
                :output-file (concatenate 'string *fasl-Path* "4-parity.wfasl")))

(defun load-4-parity ()
  (load (concatenate 'string *fasl-Path* "4-parity.wfasl")))

(defun load-4-parityl ()
  (load (concatenate 'string *source-Path* "4-parity.lisp")))


(defun compile-no-adfs-3-parity ()
  (compile-file (concatenate 'string *source-Path* "3-parity-no.lisp")
		:verbose t :print 1
                :output-file (concatenate 'string *fasl-Path* "3-parity-no.wfasl")))

(defun load-no-adfs-3-parity ()
  (load (concatenate 'string *fasl-Path* "3-parity-no.wfasl")))

(defun load-no-adfs-3-parityl ()
  (load (concatenate 'string *source-Path* "3-parity-no.lisp")))


(defun compile-no-adfs-4-parity ()
  (compile-file (concatenate 'string *source-Path* "4-parity-no.lisp")
                :output-file (concatenate 'string *fasl-Path* "4-parity-no.wfasl")))

(defun load-no-adfs-4-parity ()
  (load (concatenate 'string *fasl-Path* "4-parity-no.wfasl")))

(defun load-no-adfs-4-parityl ()
  (load (concatenate 'string *source-Path* "4-parity-no.lisp")))

(defun compile-no-adfs-5-parity ()
  (compile-file (concatenate 'string *source-Path* "5-parity-no.lisp")
                :output-file (concatenate 'string *fasl-Path* "5-parity-no.wfasl")))

(defun load-no-adfs-5-parity ()
  (load (concatenate 'string *fasl-Path* "5-parity-no.wfasl")))

(defun load-no-adfs-5-parityl ()
  (load (concatenate 'string *source-Path* "5-parity-no.lisp")))

(defvar *eyes-1-files* 
  '("images-globals" "eyes-globals" "eyes-training-data" "eyes-data" "eyes-prims" "show-prims" "eyes-1-dcl"
    "eyes-1-fitness" "eyes-1" "eyes-1-testing" "eyes-edges" "eyes-report"
    "p5-output" "eyes-risk" "p5-tcl" "eyes-1-gen" "overlap"))

(defvar *face-loc-files* 
  '("images-globals" "face-locate-globals" "face-locate-training-data" "eyes-data" "eyes-prims" "show-prims" "overlap"  "face-locate-dcl"
    "face-locate-1" "face-locate-1-fitness" "eyes-edges" "face-locate-report" "face-locate-gen" "face-locate-1-regression"
    "p5-output"  "p5-tcl"))

(defvar *expParms*)
(defvar *runParms*)
(defvar *reportParms*)

(defun load-eyes-l ()
  (load-lisp-list *eyes-1-files*)
  (format t "initializing eye datafill via eyes-1~%")
  (setf *expParms* (make-expParms))
  (setf *runParms* (make-runParms)) (setf *reportParms* (make-reportParms))
  ;;(setf *filestuff* nil)
  ;;(set-fitness-coefficients)
  ;;(eyes-1 *expParms* *reportParms* *runParms*)
 ) 
(defun compile-and-load-eyes-1 ( &optional (silent nil) )
  (if silent
      (compile-file-list *eyes-1-files* nil -1)
    (compile-file-list *eyes-1-files*))

  ;;(load-fasl-list *eyes-1-files*) ;; compile-file-list loads the fasl
  ;;(format t "initializing eye datafill via eyes-1~%")
  ;; WATCH STUFF BELOW when this function is compiled
  (setf *expParms* (make-expParms))
  (setf *runParms* (make-runParms)) (setf *reportParms* (make-reportParms))
  ;;(setf *filestuff* nil)
  ;;(set-fitness-coefficients)
  ;;(eyes-1 *expParms* *reportParms* *runParms*)
  );;defun
(defun load-face-locate-l ()
  (load-lisp-list *face-loc-files*)
  (setf *expParms* (make-expParms))
  (setf *runParms* (make-runParms)) (setf *reportParms* (make-reportParms))
 ) 
(defun compile-and-load-face-locate ( &optional (silent nil) )
  (if silent
      (compile-file-list *face-loc-files* nil -1)
    (compile-file-list *face-loc-files*))

  ;;(load-fasl-list *eyes-1-files*) ;; compile-file-list loads the fasl
  ;;(format t "initializing eye datafill via eyes-1~%")
  ;; WATCH STUFF BELOW when this function is compiled
  (setf *expParms* (make-expParms))
  (setf *runParms* (make-runParms)) (setf *reportParms* (make-reportParms))
  ;;(setf *filestuff* nil)
  ;;(set-fitness-coefficients)
  ;;(eyes-1 *expParms* *reportParms* *runParms*)
  );;defun

(defun help-message ()
#+:LISPWORKS (format t "Current directory is ~A~%" system::*current-working-directory*)
(format t "Use loadthewholeworksl or ~%    compileAndLoadTheWholeWorks or ~%")
(format t "    loadthewholeworks  to get going~%")

(format t "~%Use (setf foreign::*unresolved-messages* nil) to suppress ffi load warnings~%~%")
(format t "Use run-all-regression ~%")
(format t "    gpstar-regression-testing~%")
(format t "    landscape-regression-testing~%")
(format t "    run-eyes-1-regression :load-exp-twice t~%")
(format t "    sa-hc-tc-rotation-test to run regression~%~%")
(format t "Use (compile-and-load-face-locate t) to compile and load all face location code~%~%")

  )

;; ************  SIZING AND STRUCTURE AND TEMPORAL EXPERIMENTS STUFF********

(defvar *sizing-base-files* nil)
(setf *sizing-base-files* '("sz-globals" "sz-base" "sz-reports" "sz-test" "sz-xx"))

(defun cl-sizing-base (&optional (silent nil) )
  (if silent
      (compile-file-list *sizing-base-files* nil -1)
    (compile-file-list *sizing-base-files*))
  );;defun

(defun load-sizing-base-l ( &optional (silent nil) )
  (load-lisp-list *sizing-base-files*)
  (format t "loading sizing base code for interp~%")
)

;; --------------------  F2 --------------------
;; code for problem where expressed leaf sequence is computed as first
;; occurence of either X_i or N_i but solution is the collection of all X_i

(defvar *sizing-f2-files* nil)

(setf *sizing-f2-files* '("sz-f2-0" ))

(defun cl-sizing-f2 ( &optional (silent nil) )
  (cl-sizing-base silent)
  (if silent
      (compile-file-list *sizing-f2-files*  nil -1)
    (compile-file-list *sizing-f2-files*))
  );;defun

(defun load-sizing-f2-l  ( &optional (silent nil) )
  (load-sizing-base-l silent)
  (if silent
      (load-list-list *sizing-f2-files*  nil -1)
    (load-lisp-list  *sizing-f2-files*))
  );;defun

;; the fitness functions: uniform, linear and exp are
;; in different files and can be loaded via (load-sizing-fitness-function)
;; after *current-experiment* and *current-sizing-ff* have been set
;; to f2-uniform, f2-exp-0 f1-linear-0

;; --------------------  Exponential  --------------------

;; code for problem where majority of N_i vs X_i dictates which is expressed
;; solution is the collection of all X_i   (Sept 12, 97)

(defvar *sizing-f1-files* nil)

(setf *sizing-f1-files* '( "sz-f1-0"))

(defun cl-sizing-f1 ( &optional (silent nil) )
  (cl-sizing-base silent)
  (if silent
      (compile-file-list *sizing-f1-files*  nil -1)
    (compile-file-list *sizing-f1-files*))
  );;defun

(defun load-sizing-f1-l  ( &optional (silent nil) )
  (load-sizing-base-l silent)
  (if silent
      (load-list-list *sizing-f1-files*  nil -1)
    (load-lisp-list  *sizing-f1-files*))
  );;defun

;; fitness function names 'f1-uniform 'f1-linear-0 'f1-exp-0
;; fitness function files are loaded via 

;; ******************** BUILDING BLOCK STUFF *******************


;; -------------------  BASE -----------------------

(defvar *bb-base-files* nil)
(setf *bb-base-files* '("bb-ds" "bb-pm-2" "bb-pm"))

(defun compileAndLoad-bb-base ( &optional (silent nil) )
  (if silent
      (compile-file-list *bb-base-files* nil -1)
    (compile-file-list *bb-base-files*))
  );;defun

(defun load-bb-base ()
    (load-fasl-list *bb-base-files*)
    );;defun
  

(defun load-bb-base-l 
  (load-lisp-list *bb-base-files*)
  (format t "loading building block base code~%")
)


;; ---------------------------- 0 ----------------------------------

(defvar *bb-a-0-files* nil)
(setf *bb-a-0-files* '("bb-datafill" "bb-a-0" "bb-a-0-fitness" "bb-a-0-test" "bb-a-0-regression"))

(defun compileAndLoad-bb-a-0 ( &optional (silent nil) )
  (compileandLoad-bb-base silent)
  (if silent
      (compile-file-list *bb-a-0-files*  nil -1)
    (compile-file-list *bb-a-0-files*))
  );;defun


(defun load-bb-a-0-l  ( &optional (silent nil) )
  (load-bb-base-l silent)
  (if silent
      (load-list-list *bb-a-0-files*  nil -1)
    (load-lisp-list *bb-a-0-files* ))
  );;defun

;; ---------------------------- 1 ----------------------------------

(defvar *bb-a-1-files* nil)
(setf *bb-a-1-files* '("bb3-datafill" "bb-a-1" "bb-a-1-fitness" "bb-a-1-test" "bb-a-1-report"))

(defun compileAndLoad-bb-a-1 ( &optional (silent t) )
  (compileandLoad-bb-base silent)
  (if silent
      (compile-file-list *bb-a-1-files*  nil -1)
    (compile-file-list *bb-a-1-files*))
  );;defun

(defun load-bb-a-1 ()
  (load-bb-base)
  (load-fasl-list *bb-a-1-files*)
);;defun

(defun load-bb-a-1-l  ( &optional (silent nil) )
  (load-bb-base-l silent)
  (if silent
      (load-list-list *bb-a-1-files*  nil -1)
    (load-lisp-list *bb-a-1-files* ))
  );;defun

;; ---------------------------- 2 ----------------------------------

(defvar *bb-a-2-files* nil)
(setf *bb-a-2-files* '("bb-datafill" "bb-a-2" "bb-a-2-fitness" "bb-a-2-test" "bb-a-2-regression"))

(defun compileAndLoad-bb-a-2 ( &optional (silent nil) )
  (compileandLoad-bb-base silent)
  (if silent
      (compile-file-list *bb-a-2-files*  nil -1)
    (compile-file-list *bb-a-2-files*))
  );;defun

(defun load-bb-a-2-2  ( &optional (silent nil) )
  (load-bb-base-l silent)
  (if silent
      (load-list-list *bb-a-2-files*  nil -1)
    (load-lisp-list *bb-a-2-files* ))
  );;defun

;; ---------------------------- 3 ----------------------------------

(defvar *bb-a-3-files* nil)
(setf *bb-a-3-files* '("bb-datafill" "bb-a-3" "bb-a-3-fitness" "bb-a-3-test" "bb-a-3-regression"))

(defun compileAndLoad-bb-a-3 ( &optional (silent nil) )
  (compileandLoad-bb-base silent)
  (if silent
      (compile-file-list *bb-a-3-files*  nil -1)
    (compile-file-list *bb-a-3-files*))
  );;defun

(defun load-bb-a-3-l  ( &optional (silent nil) )
  (load-bb-base-l silent)
  (if silent
      (load-list-list *bb-a-3-files*  nil -1)
    (load-lisp-list *bb-a-3-files* ))
  );;defun

;; ---------------------------- 4 ----------------------------------

(defvar *bb-a-4-files* nil)
(setf *bb-a-4-files* '("bb-datafill" "bb-a-4" "bb-a-4-fitness" "bb-a-4-test" "bb-a-4-regression"))

(defun compileAndLoad-bb-a-4 ( &optional (silent nil) )
  (compileandLoad-bb-base silent)
  (if silent
      (compile-file-list *bb-a-4-files*  nil -1)
    (compile-file-list *bb-a-4-files*))
  );;defun

(defun load-bb-a-4-l  ( &optional (silent nil) )
  (load-bb-base-l silent)
  (if silent
      (load-list-list *bb-a-4-files*  nil -1)
    (load-lisp-list *bb-a-4-files* ))
  );;defun

;; ---------------------------- 5 ----------------------------------

(defvar *bb-a-5-files* nil)
(setf *bb-a-5-files* '("bb-datafill" "bb-a-5" "bb-a-5-fitness" "bb-a-5-test" "bb-a-5-regression"))

(defun compileAndLoad-bb-a-5 ( &optional (silent nil) )
  (compileandLoad-bb-base silent)
  (if silent
      (compile-file-list *bb-a-5-files*  nil -1)
    (compile-file-list *bb-a-5-files*))
  );;defun

(defun load-bb-a-5-l  ( &optional (silent nil) )
  (load-bb-base-l silent)
  (if silent
      (load-list-list *bb-a-5-files*  nil -1)
    (load-lisp-list *bb-a-5-files* ))
  );;defun

;; ---------------------------- 6 ----------------------------------

(defvar *bb-a-6-files* nil)
(setf *bb-a-6-files* '("bb-datafill" "bb-a-6" "bb-a-6-fitness" "bb-a-6-test" "bb-a-6-regression"))

(defun compileAndLoad-bb-a-6 ( &optional (silent nil) )
  (compileandLoad-bb-base silent)
  (if silent
      (compile-file-list *bb-a-6-files*  nil -1)
    (compile-file-list *bb-a-6-files*))
  );;defun

(defun load-bb-a-6-l  ( &optional (silent nil) )
  (load-bb-base-l silent)
  (if silent
      (load-list-list *bb-a-6-files*  nil -1)
    (load-lisp-list *bb-a-6-files* ))
  );;defun


;; ---------------------------- 7 ----------------------------------

(defvar *bb-a-7-files* nil)
(setf *bb-a-7-files* '("bb-datafill" "bb-a-7" "bb-a-7-fitness" "bb-a-7-test" "bb-a-7-regression"))

(defun compileAndLoad-bb-a-7 ( &optional (silent nil) )
  (compileandLoad-bb-base silent)
  (if silent
      (compile-file-list *bb-a-7-files*  nil -1)
    (compile-file-list *bb-a-7-files*))
  );;defun

(defun load-bb-a-7-l  ( &optional (silent nil) )
  (load-bb-base-l silent)
  (if silent
      (load-list-list *bb-a-7-files*  nil -1)
    (load-lisp-list *bb-a-7-files* ))
  );;defun


(defun cfl (l)
  (let (s-list)
    (dolist (filename l)
	    (if (not (typep filename 'string))
		(setf s-list (cons (string-downcase (prin1-to-string filename)) s-list))
	      (setf s-list (cons filename s-list)))
	    )
    (compile-file-list (reverse s-list))
    ));;let and defun
