Lesson44 – Converting Lists to Strings Using an External File



There is no predefined function to convert either a list or a symbol to a string. But we can create on using an inverse (read) function that converts data of any type to a string. Noting that (princ) will write any data type to a file, and that (read-line) returns a string, we can use a temporary file for conversion.

(defun XTOS (ARG / FILE)
(setq FILE (open “$temp” “w”))
(princ ARG FILE)
(close FILE)
(setq FILE (open “$temp” “r”))
(setq ARG (read-line FILE))
(close FILE)
)

Example

Command: (setq PT1 (list 1.0 3.0 0.0))
(1.0 3.0 0.0)
Command: (xtos PT1)
“(1.0 3.0 0.0)”
Command: (strcat “\nThis is a list of points: ” (xtos PT1))
“\nThis is a list of points: (1.0 3.0 0.0)”

  • A complete solution to this exercise is on your class disk as XTOS-A.LSP.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

Show Buttons
Hide Buttons
SUBSCRIBE TO OUR NEWSLETTER

It's FREE!

Sign up and receive an email every time a new tutorial is published