Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I avoid package/character errors in (read) in Common Lisp?

I’m getting some surprising errors when I try to input a string using (read). Context: I’m building a mini language, with inputs deliminated using characters like {, }, :, etc.

Here’s what happens, I run (read) and enter {9.I:{8.II:hello}{8.III:hi}} (an example input string from my mini language).

I then get 2 errors:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

1:

too many colons in "{8.II"

2:

Package HELLO}{8.III does not exist.

It seems as though there’s something extra going on in the (read) function that’s tripping me up. Can someone point me in the right direction?

>Solution :

read is designed to read a valid Lisp S-expression. It’s going to use Common Lisp’s parser. If your language is sufficiently Lisp-like, you may be able to make it work for you, but given the example input you’ve shown, I doubt it’s what you want.

You’re probably looking for read-line, which reads a single line of text as a string and does not perform any additional parsing on it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading