I am using common lisp for customizing CoCreate Cad software.
I am confused regarding the load function.

The following command will load the indicated file:
(load "c:\\temp\\testload")

The following will load the 2nd item but the 1st item exists:
(load "c:\\temp\testload"
if-does-not-exist
(load "c:\\temp\\testload2")
)

Could somebody please explain why the testload will not load, even though it exists?

The files do not have a file extension and I'd like to run it this way.

Thank You
Bill

Dani AI

Generated

Short diagnosis and a compact fix. The most likely cause here is not the backslash typo (that was pointed out by ) but the way the fallback was written: putting a (load ...) call as the value of the :if-does-not-exist keyword causes that inner (load ...) to be evaluated before the outer load call (Common Lisp evaluates argument subforms), so the second file will run unconditionally. was right to recommend using pathnames, and ’s permission check is also a good idea. (lispworks.com)

Practical, portable pattern to do what you want: test for the file first, then call load. For example:

(let ((a "c:/temp/testload")
      (b "c:/temp/testload2"))
  (if (probe-file a)
      (load a)
      (load b)))

probe-file is the standard way to check whether the Lisp runtime actually sees a file. Use forward slashes or real pathname objects to avoid escaping headaches. (lispworks.com)

Other checks and notes: load’s choice between source and compiled files, and how a missing extension is handled, is implementation-dependent, so naming files with a clear extension or using explicit pathname objects avoids ambiguity. Also verify the Lisp process has read access; file-system errors show up as file-error conditions. While debugging, *load-pathname* and *load-truename* are bound during a load and can help you see what the runtime is trying to open. (lispworks.com)

Checklist: 1) Check the exact string your Lisp sees (avoid single backslash escapes), 2) use probe-file/directory to confirm visibility, 3) prefer explicit pathnames or extensions, and 4) isolate permission/CoCreate embedding issues if the file is visible but still won’t load.

Recommended Answers

All 5 Replies

You're missing a slash. You mean \\testload.

When referring to file paths in Common LISP, it's best to either use the pathname directive: (load #p("/path/to/file") -or-
...better yet, just use the arbitrary pathname tricks in Common LISP:

(load (make-pathname
         :device "c"
         :directory '(:absolute "temp")
         :name "testload"))

Now, however, there's a problem with the syntax of your code; proper Common LISP code for your little snippet should read (NOTE: This example's using arbitrary pathnames.):

(load (make-pathname
         :device "c"
         :directory '(:absolute "temp")
         :name "testload")
  :if-does-not-exist (load (make-pathname :device "c" :directory '(:absolute "temp") :name "testload2"))

You're missing a slash. You mean \\testload.

This was a typing error in this message. The code has the proper backslash and it still will not work properly.

I am using common lisp for customizing CoCreate Cad software.
I am confused regarding the load function.

The following command will load the indicated file:
(load "c:\\temp\\testload")

The following will load the 2nd item but the 1st item exists:
(load "c:\\temp\testload"
if-does-not-exist
(load "c:\\temp\\testload2")
)

Could somebody please explain why the testload will not load, even though it exists?

The files do not have a file extension and I'd like to run it this way.

Thank You
Bill

Hi

click on following link. read lisp load function.

From
Hexagon software
[removed links]

It could very well be a permission error. Does your program have permission to read that file?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.