Reputation: 41
I am new to programming and started with the practical common lisp book. My challenge is in the third chapter.
The function
(defun save-db (filename)
(with-open-file (out filename
:direction :output
:if-exists :supersede)
(with-standard-io-syntax)
(print *db* out))))
When i go to the REPL and type (save-db "c:/my-cds.db")
, I get the following:
Permission denied : "c:/my-cds.db" Condition of type CCL::SIMPLE-FILE-ERROR
Could someone help me with the stage as I have been stuck for 2 days trying to understand what's wrong.
Thank you.
Upvotes: 2
Views: 113
Reputation: 58578
I use CCL on Windows. The Tankan application for learning Japanese characters is built using CCL.
This complete program writes the file successfully:
(defvar *db* 42)
(defun save-db (filename)
(with-open-file (out filename
:direction :output
:if-exists :supersede)
(with-standard-io-syntax)
(print *db* out)))
(save-db "c:\\Users\\kaz\\dbfile.lisp")
I get a file containing 42
.
It also works with single forward slashes: "c:/Users/..."
.
With single backslashes, I get that problem that CCL's parse-namestring
function tries to interpret the path as having a logical host name. Same error message that you saw.
I also get a permission error if I just use "c:/dbfile.lisp"
.
Note that the doubled backslashes are just an escaping notation:
CCL is free software. It is distributed under the terms of the Apache
Licence, Version 2.0.
? (length "\\")
1
? (length "\\a")
2
? (length "/a")
2
We can read a normal-looking path from the user, e.g. using read-line
. When CCL prints that back to us as a string object, it adds the escapes:
> (read-line)
c:\Users\kaz\dbfile.lisp
"c:\\Users\\kaz\\dbfile.lisp"
NIL
They are not part of the data, just like the "
quote characters are not.
Upvotes: 2
Reputation: 70267
As discussed in the comments, this is just the operating system protecting you from accidentally damaging your system. Even on a single-user system, the OS won't let ordinary user accounts modify system directories, including the root of the main drive.
In your case, since you're just testing things, I recommend simply working in your Documents
folder, which is probably C:\Users\<YourName>\Documents
, and you shouldn't run into permissions issues.
If you really do need to modify C:\
, you'll need to run your program as an administrator. On Linux, that's just sudo
. On Windows, I believe you just run the command line as administrator by right-clicking it and hitting "Run as Administrator".
Upvotes: 3