He's doing this only because Racket has the unusual feature of supporting images as "self-eval" values in the source code.
In other languages, all you'd want is the byte string (maybe BASE64-encoded, maybe with byte escape sequences), and you wouldn't need a fancy reader extension: just put a byte string literal.
A variation on the byte string literal you might see is when people create a minilanguage out of strings. For example, if you want to represent a 2x pixel map image with a fairly small color map... you might just have a string literal of ASCII characters for each row, where each ASCII character maps to an RGB color (or transparent) that you specify, with a simple function to translate it to binary. Then it looks like ASCII art in your source code.
Vector images, OTOH, are more likely to have a textual language already (e.g., SVG), so of course you can just embed that as strings in your source file.
perihelions 21 days ago [-]
I like these kinds of ideas. I've spent a lot of time thinking about similar ones. Here's my rough translation of this particular concept to Emacs:
This adaptation hooks onto an Emacs language mode—Emacs Lisp mode, in this snippet—and searches for, and translates, a regex syntax (%image) appearing in the comments section. This piggybacks on the language mode's own parser (the 'font-lock-comment-face thingy). The image-handling part is core Emacs functionality; like DrRacket it does support these things natively.
IshKebab 20 days ago [-]
I really wish IDEs would support showing images inline in code. I can't count the number of times I've wanted to include a nice diagram in a comment but I instead had to resort to describing the diagram with words, or a shitty ASCII art diagram.
There's a very long standing VSCode issue for this.
On a related note, one of the features in TempleOS was images embedded in source code along with an image editor within the code editor: https://www.youtube.com/shorts/196Dv3gFslU
Tempest1981 21 days ago [-]
Seems clean. Does the Racket IDE already support images?
I read the readme, I read all the links. I didn't see a single image. Why are developers like this.
gcmrtc 20 days ago [-]
Because the whole thing is about embedding images as text, so the interesting bit is not showing the image, but the resulting encoding in the racket source.
In other languages, all you'd want is the byte string (maybe BASE64-encoded, maybe with byte escape sequences), and you wouldn't need a fancy reader extension: just put a byte string literal.
A variation on the byte string literal you might see is when people create a minilanguage out of strings. For example, if you want to represent a 2x pixel map image with a fairly small color map... you might just have a string literal of ASCII characters for each row, where each ASCII character maps to an RGB color (or transparent) that you specify, with a simple function to translate it to binary. Then it looks like ASCII art in your source code.
Vector images, OTOH, are more likely to have a textual language already (e.g., SVG), so of course you can just embed that as strings in your source file.
There's a very long standing VSCode issue for this.
https://github.com/microsoft/vscode/issues/3220
https://www.youtube.com/watch?v=z18shcK6mhk