changing file type

This is a discussion on changing file type within the lisp forums in Programming Languages category; Hello, I was wondering whats the recommended way of changing a file type in lisp. Here is what I tried: [1]> (setf x (pathname "/home/noob/tmp.txt")) #P"/home/noob/tmp.txt" [2]> x #P"/home/noob/tmp.txt" [3]> (setf (pathname-type x) "doc") *** - FUNCTION: undefined function (SETF PATHNAME-TYPE) The following restarts are available: USE-VALUE :R1 You may input a value to be used instead of (FDEFINITION '(SETF PATHNAME-TYPE)). RETRY :R2 Retry STORE-VALUE :R3 You may input a new value for (FDEFINITION '(SETF PATHNAME-TYPE)). ABORT :R4 ABORT I tried the above in sbcl as well as clisp. I get the same error. Is 'pathname-type' not setf-able? This seems ...

Go Back   Application Development Forum > Programming Languages > lisp

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 06-17-2008, 12:18 PM
parth.malwankar@gmail.com
Guest
 
Default changing file type

Hello,

I was wondering whats the recommended way of changing a file
type in lisp. Here is what I tried:

[1]> (setf x (pathname "/home/noob/tmp.txt"))
#P"/home/noob/tmp.txt"
[2]> x
#P"/home/noob/tmp.txt"
[3]> (setf (pathname-type x) "doc")

*** - FUNCTION: undefined function (SETF PATHNAME-TYPE)
The following restarts are available:
USE-VALUE :R1
You may input a value to be used instead of (FDEFINITION
'(SETF PATHNAME-TYPE)).
RETRY :R2 Retry
STORE-VALUE :R3 You may input a new value for (FDEFINITION
'(SETF PATHNAME-TYPE)).
ABORT :R4 ABORT

I tried the above in sbcl as well as clisp. I get the same
error. Is 'pathname-type' not setf-able?

This seems to work but I am quite new to lisp and was wondering if
this is the correct way to do it.

Break 1 [4]> (setf x (make-pathname :defaults x :type "doc"))
#P"/home/noob/tmp.doc"
Break 1 [4]> x
#P"/home/noob/tmp.doc"
Break 1 [4]>

Thanks very much.
Parth
Reply With Quote
  #2  
Old 06-17-2008, 02:01 PM
Pascal J. Bourguignon
Guest
 
Default Re: changing file type

parth.malwankar@gmail.com writes:

> Hello,
>
> I was wondering whats the recommended way of changing a file
> type in lisp.


(rename-file path (make-pathname :type new-type))

Note however that you cannot _remove_ the type of a file with CL. You
could end up with a physical file name such as: "toto." but not "toto".


> Here is what I tried:
>
> [1]> (setf x (pathname "/home/noob/tmp.txt"))
> #P"/home/noob/tmp.txt"
> [2]> x
> #P"/home/noob/tmp.txt"
> [3]> (setf (pathname-type x) "doc")
>
> *** - FUNCTION: undefined function (SETF PATHNAME-TYPE)
> The following restarts are available:
> USE-VALUE :R1
> You may input a value to be used instead of (FDEFINITION
> '(SETF PATHNAME-TYPE)).
> RETRY :R2 Retry
> STORE-VALUE :R3 You may input a new value for (FDEFINITION
> '(SETF PATHNAME-TYPE)).
> ABORT :R4 ABORT
>
> I tried the above in sbcl as well as clisp. I get the same
> error. Is 'pathname-type' not setf-able?


CLHS says:
Function PATHNAME-HOST, PATHNAME-DEVICE, PATHNAME-DIRECTORY, PATHNAME-NAME, PATHNAME-TYPE, PATHNAME-VERSION
^^^^^^^^
not Accessor, so no, pathname-type may not be setf-able.


> This seems to work but I am quite new to lisp and was wondering if
> this is the correct way to do it.
>
> Break 1 [4]> (setf x (make-pathname :defaults x :type "doc"))
> #P"/home/noob/tmp.doc"
> Break 1 [4]> x
> #P"/home/noob/tmp.doc"
> Break 1 [4]>


Yes, that's the best way to do it.

--
__Pascal Bourguignon__ http://www.informatimago.com/
The rule for today:
Touch my tail, I shred your hand.
New rule tomorrow.
Reply With Quote
  #3  
Old 06-17-2008, 02:15 PM
parth.malwankar@gmail.com
Guest
 
Default Re: changing file type

On Jun 17, 11:01 pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> parth.malwan...@gmail.com writes:
> > Hello,

>
> > I was wondering whats the recommended way of changing a file
> > type in lisp.

>
> (rename-file path (make-pathname :type new-type))
>
> Note however that you cannot _remove_ the type of a file with CL. You
> could end up with a physical file name such as: "toto." but not "toto".
>
>
>
> > Here is what I tried:

>
> > [1]> (setf x (pathname "/home/noob/tmp.txt"))
> > #P"/home/noob/tmp.txt"
> > [2]> x
> > #P"/home/noob/tmp.txt"
> > [3]> (setf (pathname-type x) "doc")

>
> > *** - FUNCTION: undefined function (SETF PATHNAME-TYPE)
> > The following restarts are available:
> > USE-VALUE :R1
> > You may input a value to be used instead of (FDEFINITION
> > '(SETF PATHNAME-TYPE)).
> > RETRY :R2 Retry
> > STORE-VALUE :R3 You may input a new value for (FDEFINITION
> > '(SETF PATHNAME-TYPE)).
> > ABORT :R4 ABORT

>
> > I tried the above in sbcl as well as clisp. I get the same
> > error. Is 'pathname-type' not setf-able?

>
> CLHS says:
> Function PATHNAME-HOST, PATHNAME-DEVICE, PATHNAME-DIRECTORY, PATHNAME-NAME, PATHNAME-TYPE, PATHNAME-VERSION
> ^^^^^^^^
> not Accessor, so no, pathname-type may not be setf-able.
>


Thanks Pascal. Wasn't aware of this detail .. this should
certainly make life easier

> > This seems to work but I am quite new to lisp and was wondering if
> > this is the correct way to do it.

>
> > Break 1 [4]> (setf x (make-pathname :defaults x :type "doc"))
> > #P"/home/noob/tmp.doc"
> > Break 1 [4]> x
> > #P"/home/noob/tmp.doc"
> > Break 1 [4]>

>
> Yes, that's the best way to do it.
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
> The rule for today:
> Touch my tail, I shred your hand.
> New rule tomorrow.


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 09:59 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.