4 ms·
A nice overview of how to modify the reader, but in my opinion the simple function call is more readable than the macro: (string-append "An error occured at " f
by fovc 9y ago
A nice overview of how to modify the reader, but in my opinion the simple function call is more readable than the macro: (string-append "An error occured at " file ":" line ".")
I don't have to know/infer/lookup/guess how the read table has been modified, and I find the @ syntax a little distracting.
- klibertp 9y ago> I find the @ syntax a little distracting. I guess that's a matter of personal preference. I can imagine arguing for both: the syntactic sugar reduces the number of characters needed and makes dealing with whitespace in the string easier (no " " in between vars). The function version reduces the need to visually parse the whole string every time to learn what forms are inside of it and makes the amount of things you need to keep in your head at one time lower. Personally, I have nothing against the plain `(string-append ...)` and I probably wouldn't use the extension from the post. I just wanted to show one way to write such an extension. There are very few examples of modifying Racket's reader or readtable because it's unnecessary to get most syntax extensions to work - the arithmetization's post is a great example of this. This is why I gave up (early in the process of writing this post) on finding an example actually useful or needed. I came up with something that is widely understood and missing from normal Racket and used that instead :)
- moron4hire 9y agoI thought that part was clear, that it was pedagogical example more than a useful one. But to anyone who still doesn't get it and might be thinking the fact that Racket lacking such a feature is evidence that it's a less well-developed language than others, the reason Racket doesn't have string interpolation is because it's not really needed. If you're going to do large amounts of string templating, the "Racket Way" is to use Scribble: https://docs.racket-lang.org/scribble/index.html https://docs.racket-lang.org/scribble/index.html Scribble is basically Literate Racket. And it's able to generate a very wide variety of document formats, far more than I've ever seen any documentation or string templating tool do. There is also quasi-quoting and un-quoting, for doing a very similar thing with Symbols: https://docs.racket-lang.org/reference/quasiquote.html https://docs.racket-lang.org/reference/quasiquote.html