how to dump a list to a file [SOLVED]

Discussion of Common Lisp
Post Reply
punchcard
Posts: 16
Joined: Fri Sep 26, 2014 5:50 pm

how to dump a list to a file [SOLVED]

Post by punchcard » Fri Sep 26, 2014 6:18 pm

Hi everyone,

OK... Sorry if its in poor taste to answer a question I already asked... But I have a followup..

I figured out (thanks to this forum) SET-DIFFERENCE was just the ticket! (with the :TEST #'EQUAL)

Code: Select all

(LOAD "WEB-LIST.LISP")
(LOAD "LOCAL-LIST.LISP")


(SETF OUTSTANDING-LIST (SET-DIFFERENCE WEB-LIST LOCAL-LIST :TEST #'EQUAL))

(WITH-OPEN-FILE (REMAINING-STREAM "REMAINING.LISP" :DIRECTION :OUTPUT)
(PRINT OUTSTANDING-LIST REMAINING-STREAM))
I have two lisp files with data structures (WEB-LIST and LOCAL-LIST)

Everything works great and I get a list that I want. - Even figured out the final portion of my question about dumping the file. Still not sure about WRITE-SEQUENCE but I just used PRINT and redirected the output to the stream. - at least I think thats how it works.

Conclusion:

Everything is fantastic. This is why I am so keen to master CLisp - even compaired to say Python I find it to be easyer to use and understand. Its like you are not constrained by someone elses idea about how to aproach a problem. Another thing I like is its very hard just to copy and paste solutions - It seems to my mind anyway a language that makes you think for yourself and come up with your own ways to solve a problem.

While this program was pretty trivial - the data was not - there were over 90,000 files to check and it handled it very respectably. I now have got more confidence to try more of my tasks with CLisp. :D Just wish there were more presentations/talks on youtube.

I
This way my orignal post...
What I would like to do is

take two seperate lists of strings LOCAL-LIST and WEB-LIST and write a procedure that makes a copy of LOCAL-LIST, STACK then pops a element off the stack and uses that in the REMOVE element WEB-LIST. The end result I want is WEB-LIST to have only elements that were not in the LOCAL-LIST.


But to my mind it seems very convoluted and un-lispy, further more I can't get it to loop right...

I tried

Code: Select all


(SETF LOCAL-LIST '("FILE0001.PDF" "FILE0014.PDF" "FILEOOO3.PDF" "FILE0034.PDF")
(SETF WEB-LIST '("FILE0001.PDF" "FILE0002.PDF" "FILEOOO3.PDF" "FILE0004.PDF")

(SETF OUTSTANDING-FILES '( REMOVE-DUPLICATES ( APPEND LOCAL-LIST WEB-LIST ) :TEST #'EQUAL ))
This works but what I want the procedure to do is leave a list with elements that were not in local list - as if i had gone through and (REMOVE <element LOCAL-LIST> WEB-LIST)

How can I do that? - I am guessing its a pretty standard thing to want to do. I assume that I am thinking about it in the wrong way and perhaps thats why its hard.

I am using CLISP and am a new person to lisp. Any pointers or sugestions on how to get this done would be great. I downloaded the free books I could find on Lisp from the net and also I had the good fortune to find Winston & Horns LISP 3rd Edition at my bookstore.

Actually the example from p.11

Code: Select all


( DEFUN NEWFRIEND ( NAME )
  ( SETF ENEMIES ( REMOVE NAME ENEMIES ))
  ( SETF FRIENDS ( CONS NAME FRIENDS ))

Made me think perhaps I could just use this but without adding an element to another list... The thing I cannot work out is how to get it to use all the elements of the other list in the procedure ...

like

(NEWFRIEND '<list element>)

how do I do that as part as a loop?

But now what I want to do is dump the contents of OUTSTANDING-LIST to a file.

I am having problems because CLISP is complaining I am not using a string for OUTSTANDING-LIST. I can write to the file when I just use strings but when I try and pass the list to the write function it does not like it.

So my followup question is. How do I use WRITE-SEQUENCE to dump the list to a file. I am guessing that this is the correct way to do it. Otherwise is there a way I can convince lisp to write the contents of the list to a file?

logxor
Posts: 20
Joined: Tue May 27, 2014 10:56 am
Location: Portland, OR

Re: how to dump a list to a file [SOLVED]

Post by logxor » Sat Sep 27, 2014 4:13 pm

That's a good way to put it—what makes Common Lisp unique. It gets rid of artificially imposed constraints that come either from ideology, or from a preoccupation with particular kinds of problems or ways of problem-solving, which tend to be encoded into other programming languages at the expense of both generality and creativity. Richard P. Gabriel wrote a nice article about this, The Art of Lisp & Writing.

Post Reply