3 ms·
Following the $ thing for amount of values, a thing I like in Common Lisp is the way the reader can be customized, and maybe this is a bad idea but I would like
by junke 6y ago
Following the $ thing for amount of values, a thing I like in Common Lisp is the way the reader can be customized, and maybe this is a bad idea but I would like to have user-provided data-types formats and bind them to prefix characters, or pairs of delimiters, ... to avoid having to tag your values like this, as done in JSON:
(published
(type std.iso.8601
value 2020-02-26))
Or like this, where "date:" is something only your application knows:
(published date:2020-02-26)
Instead, you could rely on an externally specified format
(prefix @ is std.iso.8601)
And use it in your file to parse text so that your application can build values of the proper datatype:
(published @2020-02-26)
The application language would register lexers for those formats or fail the parsing step.
You could have fake parsers that just skip over the defined syntax if you don't need to process it in your code.
Or, the way the syntax is defined could be such that it tells the lexer how to skip over a token even if the type is not useful for a tool's purpose (skip until a space, or parse exactly N characters, or "read until this delimiter with backslash being an escape character").
(probably reinventing the wheel)
- dan-robertson 6y agoMy preferred solution looks like: (published 2021-02-26) The program will get a list of two atoms, “published”, and “2021-02-26”. It can complain if you’ve eg written “published” when you should have written “submission_date” and it can complain if the next atom isn’t a valid date. You don’t need to tell the reader to parse something as a date because the reader isn’t best placed to know what should and shouldn’t be a date. Whereas the program should know exactly where it expects dates to be so it might as well handle parsing them so you don’t need to tag dates when you write your config. Any human can read that date and know what it means so why bother tagging it if the machine can also know it should be a date.