4 ms·
This reminds me of one of my biggest facepalm-ing moments when I first started using Lisp. I needed to serialise some data to disk, it was all in a list form -
by adwf 11y ago
This reminds me of one of my biggest facepalm-ing moments when I first started using Lisp. I needed to serialise some data to disk, it was all in a list form - (list (a b) (c d)) kinda thing. So I thought to use XML format to store it on disk as that's what I had experience with in other languages.
I was about halfway through writing the (write-to-xml) function when I realised I could just write the entire lisp expression to the file instead...
Not only was it smaller, it had the huge advantage of not needing to parse it back when I wanted to read from disk, I just called the inbuilt (read) function. Thankfully I only wasted an afternoon!
That's what really ingrained the whole "data is code, code is data" idea into me. I even went on to write the structure function to each file as well, so that no matter what I did to the data structure down the line, I would still have the actual code needed to understand it. Right next to the data itself. Not only was my code self-documenting, my data was as well ;)
- wodenokoto 11y agoWhy does everybody say it's lisp thing to save an expression to disc, or that "code is data in lisp" kind of things? Every language I've ever used has variable assignment and you can write those to a document and execute it.
- latiera 11y agoBecause code is data is code in lisp. That's not the case in C or Java or C# or Rust or whatever.