If I create file1.lisp with:
Code: Select all
(load "file2.lisp")
I also tried defpackage, but packages aren't loaded automatcally either. Is there a simple way do do that? (writing ADSF files seems way too much for a hello-world program)
Code: Select all
(load "file2.lisp")
Code: Select all
(defsystem "your-project-name"
:description "Some Description"
:version "..."
:author "you"
:license "quak"
:depends-on (#:package1 #:package2) ;you probably wont need this
:components ((:file "file1") (:file "file2") (:file "...")))
Well this should work:klkl wrote:If I create file1.lisp with:won't look for file2 in the same directory as file1.Code: Select all
(load "file2.lisp")
Code: Select all
(let ((*load-pathname* *default-pathname-defaults*))
(load "file2"))
I agree that ASDF is a lot of work for a hello-world program but if it really is a simple program, you might consider just using one file. It would keep things a lot simpler in the short term while you play with the language.klkl wrote: I also tried defpackage, but packages aren't loaded automatcally either. Is there a simple way do do that? (writing ADSF files seems way too much for a hello-world program)
If you just want to keep it simple and don't want to mess around with asdf etc, you can just do like this:klkl wrote:I'm trying to write my first lisp program and I've got a problem how to split it into multiple files. I can't figure out how to make CL automatically compile and load a few files.
If I create file1.lisp with:won't look for file2 in the same directory as file1.Code: Select all
(load "file2.lisp")
Code: Select all
(defun load-relative (filename)
(load (compile-file (format nil "~A~A"
(directory-namestring *load-truename*)
(pathname-name filename))))
Code: Select all
;; These can be placed into a separate file, like "load-deps.lisp"
(require :dep-1)
(require :dep-2)
(require :dep-3)
;; This can be put into a separate file too, like "packages.lisp"
(defpackage foo ... )
(load-relative "file1")
(load-relative "file2")
(load-relative "file3")
It is a good practice to create pathnames using MERGE-PATHNAMES and friends. Creating pathname strings and hoping they'd work is not advisable.WeYu wrote:If you just want to keep it simple and don't want to mess around with asdf etc, you can just do like this:klkl wrote: ...
Define the helper function load-relative:Code: Select all
(defun load-relative (filename) (load (compile-file (format nil "~A~A" (directory-namestring *load-truename*) (pathname-name filename))))
Right, the load-relative function should probably look something like this:marcoxa wrote: It is a good practice to create pathnames using MERGE-PATHNAMES and friends. Creating pathname strings and hoping they'd work is not advisable.
Code: Select all
(defun load-relative (filename)
(load (compile-file (merge-pathnames filename *load-truename*))))
Code: Select all
(load-relative "foo/bar/file4.lisp")