|
Prev: How best to teach newbie at algorithms (was: coerce for arbitrary types)
Next: CMUCL 18b coredumped unexpectedly
From: joker on 13 Apr 2008 22:28 in the book common lisp a gentle introduction to lisp there is an example like this... file name: timber.dat includes: "The North Slope" ((45 redwood) (12 oak) (43 maple)) 100 code: (defun get-tree-data () (with-open-file (stream "/usr/dst/timber.dat") (let* ((tree-loc (read stream)) (tree-table (read stream)) (num-trees (read stream))) (format t "~&There are ~S trees on ~S." num-trees tree-loc) (format t "~&They are: ~S" tree-table)))) > (get-tree-data) There are 100 trees on "The North Slope". They are: ((45 REDWOOD) (12 OAK) (43 MAPLE)) NIL now i can not reach this file in this example it is not clear where the file is... for example my path is E:\timber.dat how must i change this code in order to reach my file i am using win xp(in E:) thank you very much for your help.
From: Brian on 13 Apr 2008 23:16 joker wrote: > now i can not reach this file in this example it is not clear where > the file is... > for example my path is E:\timber.dat > how must i change this code in order to reach my file > i am using win xp(in E:) Look around WITH-OPEN-FILE :) And you probably want to write the pathname as "E:/timber.dat" because you would need to do "E:\\timber.dat" to escape the backslash otherwise.
From: Marco Antoniotti on 14 Apr 2008 04:35 On Apr 14, 5:16 am, Brian <quickbasicg...(a)gmail.com> wrote: > joker wrote: > > now i can not reach this file in this example it is not clear where > > the file is... > > for example my path is E:\timber.dat > > how must i change this code in order to reach my file > > i am using win xp(in E:) > > Look around WITH-OPEN-FILE :) > > And you probably want to write the pathname as "E:/timber.dat" because > you would need to do "E:\\timber.dat" to escape the backslash > otherwise. The actual syntax that can be fed to WITH-OPEN-FILE is eventually the pathname syntax that can be fed PARSE-NAMESTRING; i.e. it is implementation dependent. Most likely, the safest string to pass PARSE-NAMESTRING on a DOS/Windows/MS file system is the quoted one "E: \\timber.dat". I hear that Windows now accepts Unix like pathnames, YMMV. Cheers -- Marco
From: Pascal J. Bourguignon on 14 Apr 2008 05:01
Brian <quickbasicguru(a)gmail.com> writes: > joker wrote: >> now i can not reach this file in this example it is not clear where >> the file is... >> for example my path is E:\timber.dat >> how must i change this code in order to reach my file >> i am using win xp(in E:) > Look around WITH-OPEN-FILE :) > > And you probably want to write the pathname as "E:/timber.dat" because > you would need to do "E:\\timber.dat" to escape the backslash > otherwise. Either that, or you can use logical pathnames, with which you could leave that detail out of the scope of your program (thus rendering it "portable"). ;;; 100% portable code follows. (load-logical-pathname-translations "DATA") ;; Note that which file is loaded, and what format it must have, are ;; implementation specific (==> read your implementation ;; documentation). But the net result will be that the following: (with-open-file (data #P"DATA:TIMBER.DAT") #|...|#) ;; will access the right file. -- __Pascal Bourguignon__ |