I want to save the result of any programming run on GNU/scheme. In order to do this I prepared the following test file(please see below). I was thinking that by running this, a scm file which just contains the word "01234" would be saved in the relevant directory under the name "testfile" but I couldn't find any file although GNU scheme says "done" after running this program. Could anybody kindly tell me what is wrong with this? I am running GNU scheme on windows (downloaded from; http://www.gnu.org/software/mit-scheme/ "I installed windows binary"
) and the directory on my pc where i think the file will be saved is;
C:\Program Files (x86)\MIT-GNU Scheme
Below is the content of the test program
(define outport (open-output-file "testfile"))
(display "abcde" outport)
(newline outport)
(display "01234" outport)
(newline outport)
(close-output-port outport)
Thank you.
Uselpa's explanation is spot on.
The manual has the following to say:
15.2 Working Directory
When MIT/GNU Scheme is started, the current working directory (or simply,
working directory) is initialized in an operating-system
dependent manner; usually, it is the directory in which Scheme was
invoked. The working directory can be determined from within Scheme by
calling the pwd procedure, and changed by calling the cd procedure.
Each REP loop has its own working directory, and inferior REP loops
initialize their working directory from the value in effect in their
superior at the time they are created.
This means that you can use
(pwd)
in the Scheme repl to see where your file is saved.
Related
I am currently trying to figure out how to install the Common Music library: http://commonmusic.sourceforge.net/cm2/doc/cm.html, to run on Portacle, an IDE that integrates Emacs among other implementations to run Common LISP.
I was able to successfully download Common Music's source tree to my Portacle installation directory following these steps, found at http://commonmusic.sourceforge.net/cm2/doc/install.html#cvs :
Change directories to your Lisp installation directory.
$ cd /usr/local/lisp
Set the shell variable CVSROOT to point to the CVS repository:
$ export CVSROOT=":pserver:anonymous#commonmusic.cvs.sourceforge.net:/cvsroot/commonmusic"
Use cvs login to connect to the Sourceforge CVS server, press Enter when prompted for a password:
$ cvs login
CVS password:
Use cvs checkout to restore CM's source tree to your Lisp installation directory:
$ cvs checkout -P cm
.
Opening my Common Lisp REPL, portacle, I typed in the equivalent of (load "/usr/local/lisp/cm/src/cm.lisp") for my specific pathname for cm.lisp.
I recieved the following errors.
READ error during LOAD:
Symbol "UNIX-FILE-KIND" not found in the SB-UNIX package.
Line: 116, Column: 47, File-Position: 4278
Stream: #<SB-INT:FORM-TRACKING-STREAM for "file /usr/local/lisp/cm/cm.asd" {1004108F23}>
[Condition of type SB-C::INPUT-ERROR-IN-LOAD]
.
If anyone is familiar with Common Lisp and integrating Common Music, any help would be greatly appreciated.
Thanks.
The problem is that this system was written for a different world. Unix-file-kind was removed from sb-unix over 10 years ago.
Here, it is used to determine whether a pathname names an existing directory.
I am not sure how using cl-fad in that system loading context would work (this could be made much simpler nowadays, but that's some work), so maybe you could either inline whatever cl-fad:directory-exists-p does, or maybe this works for you (it's a little hacky though):
#+sbcl (let ((truename (probe-file dir)))
(and truename
(string= (namestring truename)
(directory-namestring truename))))
You'd replace the line in cm.lisp that currently says #+sbcl (eq :directory (sb-unix:unix-file-kind (namestring dir))) with this.
… but I expect that this is only the tip of the iceberg. Good luck!
This question already has an answer here:
How to refer to the file currently being loaded in Emacs Lisp?
(1 answer)
Closed 3 years ago.
When I edit a file, say current-file-path.el
I can have the following code:
(message (format "Here is the path of the current file %s" (buffer-file-name)))
when execting the statement in the buffer of the file when the file is open in a buffer, I got the correct message
of the path of the file:
Here is the path of the current file /home/yubrshen/tmp/current-file-path.el
However, if I just load the file, then the message becomes:
Here is the path of the current file nil
What would be the proper way to find out the path of the file where my code is?
Actually, I'm interested in knowing the directory of the file of my program so that I can load the other files at the same directory through the program.
You seem to be looking for symbol-file.
Of course, not every symbol is defined in Lisp code loaded from a named file; some are defined in the C source code for Emacs, and some are defined interactively by yourself.
There is also no guarantee that your data files will be packaged in the same location as your source code, so what you are describing should probably be implemented with a package variable instead.
(defvar foo-directory (file-name-directory load-file-name)
"*Directory for data files belonging to package \`foo'.")
This should probably use defcustom actually, but I'd have to guess too many things about your code to create a meaningful example.
I use project-root to setup root directory of the project as:
(setq project-roots
`(("Git Project"
:root-contains-files (".gitignore"))))
Then I go into my git project directory (e.g ~/.emacs.d), and press M-x ag-project-files and enter some search string. It shows the files which contains the string. But when I push enter key on top of the file (in order to jump into that file), it shows error message like:
Find this error in (default File: lisp/ag.el): ~/.emacs.d/
I don't know how this error come out? It is all right when I use emacs in Linux, but no good in Mac. Have you ever met this problem?
I ran into this same problem using projectile-ag. It turned out that setting the "--nogroup" parameter for ag was causing this break (but only on macOS). To work around this I just set ag-arguments to not include the "--nogroup" param:
(setq ag-arguments (list "--smart-case" "--column"))
Is there any similar command such as cd, pwd which operate on current working directory in IronScheme? I want to get the directory which is used by (load "source.ss").
Besides, since IronScheme is a standard Scheme, I think the function works in other Scheme could also work here.
This is a not standard Scheme procedure, but in IronScheme you can do (one of) the following:
> (import (ironscheme environment))
> (current-directory) ; same as the present working dir
"C:\\Program Files\\IronScheme"
> (application-directory) ; where the IronScheme exe lives
"C:\\Program Files\\IronScheme"
>
I am using TinyScheme (actually Script-Fu in GIMP), and cannot find a good way to open a file and append a line of text to it.
I am trying to log some info to the file for debugging, and transcript-on doesn't seem to be implemented...
Right now I am scraping along by reading the entire file (one character at a time!), concatenating that into a string, concatenating my text to the end of that, then writing it all out to the file again.
There must be a better way!
It's going to be something like
(open-file "myfile" (file-options append))
You want to look up the file-options function.
Update
Here's the guile version:
(open-file "myfilename.dat" "a")
Just had the same exact problem in GIMP and decided to use open-input-output-file. My solution is something like this:
(let* ((out (open-input-output-file "file.txt") ))
(display "hello world" out)
(newline out)
(close-output-port out))
Went through the TinyScheme source and checked that this function actually calls fopen with "a+". The file is open for reading and writing. For our purposes we only want to write, so just ignore reading.
I am writing a Script-Fu to write the values of gimp-selection-bounds to a file.