Quantcast
Viewing all articles
Browse latest Browse all 14319

Associative List with Strings and Spaces.

Hey everybody,

 

I'm making a program that reads a property file that follows the format:

"key=value"  for each line on the text file.

 

One specific line has the key "file" and the value is some file path that includes a space.

file=C:/my folder/my file.txt

 

Now I can extract what the key and value is for any given line in the file.

However, I want to put all of the data into an Associative List so that I will not need to keep opening the file each time I search for information.

 

I've been using the cons function in order to create a dotted list, which is succesful.  However I have an issue when I add this dotted list to the end of my associative list.

 

Suppose I have a key and a value already stored inside variables.  Below I have two lines of code, first the dotted list portion is printed, and works as expected.  The second line adds that dotted list to the associative list:

(princ "Cons: ")(princ (cons key val)) (princ "\n") ;Prints (file . C:/my folder/my file.txt)
(setq assocList (append assocList (cons key val))) ;Error message here.

 

The error that I receive says "; error: bad list: "C:/my folder/my file.txt"

 

 

EDIT:

As I was positing this I made a change to my code and resolved the error. I am still posting this for reference sake of somebody else with the same problem.

Here is the change:

(setq assocList (append assocList (list (cons key val))))

 Now, the dotted list is inserted properly and looks like this after printing the whole associative list:

((version . 1.0.1) (file . C:\my folder\my file.txt))

 

 

Hurray!

 

If you still have any comments or have a way of improving the code, I'm open for further discussion.

 

Thanks.

-Nicholas

 

 

 

 

Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 14319

Trending Articles