LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-17-2007, 10:10 AM   #1
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Type Casting in Lisp


Is it possible to re-cast a variable type to another? I'm trying to cast the returned value of GET-UNIVERSAL-TIME to a string.

I am also trying to use CONCATENATE to...well...concatenate two pathnames, but I can't remember what the type is that I need to specify; 'STRING signals an error, and 'PATH or 'PATHNAME don't exist. I've already tried looking this up, and there doesn't seem to be any PATHNAME or PATH type or subtype.

Here's an example:
Code:
(defparameter *current-log-file* nil)
(setq *current-log-file*
      (make-pathname
       :directory '(:absolute "etc" "pkgsd" "logs")
       :name (get-universal-time) ; This is one of the offending lines
       :type "txt"))
...
(defparameter *base-dir* #p"/etc/pkgsd")
(defparameter *temp-dir* #p"/tmp")

; This is the other offending line
(defparameter *temp-path* (concatenate 'string *base-dir* *temp-dir*))
Should I perhaps just leave the two directory parameters as strings and work with them thusly?
 
Old 01-17-2007, 10:57 AM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
The first error results from GET-UNIVERSAL-TIME which returns an integer. To get this into a string, you can use WRITE-TO-STRING. The latter problem is because pathnames aren't sequences and thus can't be concatenated. But you can convert the pathnames into strings, then concatenate them, and convert them back into a pathname again. Here's some code:
Code:
(setq *current-log-file*
      (make-pathname
       :directory '(:absolute "etc" "pkgsd" "logs")
       :name (write-to-string (get-universal-time)) ; convert int -> string
       :type "txt"))
...
(defparameter *base-dir* #p"/etc/pkgsd")
(defparameter *temp-dir* #p"/tmp")

; convert pathname -> string -> pathname
(defparameter *temp-path*
  (parse-namestring
   (concatenate 'string
                (namestring *base-dir*)
                (namestring *temp-dir*))))

Last edited by taylor_venable; 01-17-2007 at 10:58 AM.
 
Old 01-17-2007, 11:51 AM   #3
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Original Poster
Rep: Reputation: 65
Thank you very much.

I've been doing some concurrent python programming, and it's totally messing up my Lisp abilities.

Last edited by indienick; 01-17-2007 at 11:53 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Type Casting problem C EmtYskY Programming 3 12-29-2006 06:01 PM
LISP or COMON LISP Compiler for Debian carspidey Programming 3 04-19-2006 07:46 AM
How to do type casting in Sparc Assembly Language foxele Programming 1 10-09-2004 04:40 PM
casting cynthia Programming 6 10-05-2004 03:58 AM
Lisp, emacs-lisp aizkorri Programming 1 09-04-2002 06:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration