Skip to main content
gamedev.net
🔒 Locked

Lisp Problem *problem solved*

Started by Lord Hen 2 replies 200+ views
Original Post
Lord Hen
Lord Hen
For fun(and learning), Im writing a function that outputs a list to a file, without parenthesis...I dont know if there is an easier way to do it, but I would like to figure out what my problem is:
(defun foList(f l)
    (let 
        ((ostream (open f :direction :output)))
        (loop for I from 0 to (- (length l) 1) 
            do (
                (prin1 (concatenate 'string (elt l I) " ") ostream) 
               )
        (close ostream)))
  
so.. foList stands for fileOutputList...or something... (foList "holycrap.txt" (list 'WOW 'IM 'RETARDED)) should output in the file "holycrap.txt": WOW IM RETARDED Before I had tried to add the space in between each one, it would output this: WOWIMRETARDED ...no good... the line (prin1 (concatenate 'string (elt l I) " ") crashes in Corman Lisp, yet (prin1 (concatenate "abc" " ")) works fine... Any Ideas? Lord Hen [edited by - Lord Hen on October 20, 2003 1:04:03 AM] [edited by - Lord Hen on October 20, 2003 1:47:22 AM]
Lord Hen
Lord Hen
Ignore the code above,
use this:

(defun foList(f l)
(let
((ostream (open f :direction :output)))
(loop for I from 0 to (- (length l) 1)
do (prin1 (concatenate 'string (elt l I) " ") ostream)
(close ostream))

)
)


The error now says that OH is not a string...argh...


Lord Hen

[edited by - Lord Hen on October 20, 2003 1:13:23 AM]
Lord Hen
Lord Hen
Maybe I should just go away, I keep getting closer by myself:


(defun foList(f l)
(let
((ostream (open f :direction :output)))
(loop for I from 0 to (- (length l) 1)
do
(prin1 (elt l I) ostream)
(prin1 " " ostream)
)
(close ostream)

)
)

outputs
WOW" "IM" "RETARDED" "

Lord Hen
Lord Hen
Lord Hen
Not that anyone cares, but I figured it out...


(defun foList(f l)
(let
((ostream (open f :direction :output)))
(loop for I from 0 to (- (length l) 1)
do
(prin1 (elt l I) ostream)
(write-char #\Space ostream)
)
(close ostream)

)
)



Later,
Lord Hen

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.