pictures in code?

53 views
Skip to first unread message

Hendrik Boom

unread,
Aug 2, 2020, 10:07:18 PM8/2/20
to Racket Users
Is there any way to include pictures in Racket code?
Perhaps as constants or as prts of identifiers?
The idea is that when editing the program in the Racket editor,
the pictures are visible as part of the code,
making the code itself more visually self-evident,
not as file names to be read from elsewhere.

-- hendrik

Sorawee Porncharoenwase

unread,
Aug 2, 2020, 11:59:11 PM8/2/20
to Racket Users
For DrRacket, it's possible via "Insert > Insert Image". It's been used in HtDP. See https://htdp.org/2020-8-1/Book/part_prologue.html

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20200803020710.d2rvz6gojluubt5t%40topoi.pooq.com.

Hendrik Boom

unread,
Aug 3, 2020, 9:47:39 AM8/3/20
to Racket Users
On Sun, Aug 02, 2020 at 08:58:54PM -0700, Sorawee Porncharoenwase wrote:
> For DrRacket, it's possible via "Insert > Insert Image". It's been used in
> HtDP. See https://htdp.org/2020-8-1/Book/part_prologue.html

Yes! That's where I saw this many years ago.

Now that's presumably something that works nicely in the DrRacket editor.
When DrRacket saves it into a file, it presumably uses some notation that
won't look like a picture in, say, emacs.
But will it still be recognised as an image if I use Racket to run that file?
Can the image be used as a symbol or a constant or is it some other type
of object?

-- hendrik

>
> On Sun, Aug 2, 2020 at 7:07 PM Hendrik Boom <hen...@topoi.pooq.com> wrote:
>
> > Is there any way to include pictures in Racket code?
> > Perhaps as constants or as prts of identifiers?
> > The idea is that when editing the program in the Racket editor,
> > the pictures are visible as part of the code,
> > making the code itself more visually self-evident,
> > not as file names to be read from elsewhere.
> >
> > -- hendrik
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to racket-users...@googlegroups.com.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/racket-users/20200803020710.d2rvz6gojluubt5t%40topoi.pooq.com
> > .
> >
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CADcuegvJCAHQYwO-eCcqKfqwhrd%2BGr4PELie_e0%3DO9b2PJ_QAA%40mail.gmail.com.

Philip McGrath

unread,
Aug 3, 2020, 1:59:22 PM8/3/20
to Racket Users
On Mon, Aug 3, 2020 at 9:47 AM Hendrik Boom <hen...@topoi.pooq.com> wrote:
On Sun, Aug 02, 2020 at 08:58:54PM -0700, Sorawee Porncharoenwase wrote:
> For DrRacket, it's possible via "Insert > Insert Image". It's been used in
> HtDP. See https://htdp.org/2020-8-1/Book/part_prologue.html

Now that's presumably something that works nicely in the DrRacket editor.
When DrRacket saves it into a file, it presumably uses some notation that
won't look like a picture in, say, emacs.

Yes, that's all correct. My knowledge isn't very deep here, but to answer the questions you asked:
 
But will it still be recognised as an image if I use Racket to run that file?

Yes. The only difference is that the default printer (for example) doesn't know how to print pictures, so you will see some output like:
philip$ racket image-literal.rkt
(object:image% ... ...)
when DrRacket would actually print the image. In principle, this is just like DrRacket's ability to print `1/3` using barred decimal notation.

Can the image be used as a symbol or a constant or is it some other type
of object?

The idea, as I understand it, is that an image is a self-quoting literal datum like `42`, `"foo`", `#false`, or `#px"\\d+"`.

What kind of a datum is it? Alexis has explained in your other thread why that's a difficult question.

Practically, I know that image literals answer `#true` to `image?` from the `2htdp/image` library. That's the only way I can remember having worked with them, but I know they are also some other kinds of things: for example, an image literal is an instance of (a subclass of) `snip%` from `racket/gui`.

How is this implemented? My vague understanding is that there's some deep magic baked into `racket/gui` to support image literals, I think around `mrlib/image-core` and `mrlib/image-core-wxme`. I know there are some limitations to this approach (though I don't immediately remember what all of them are), and there have been some discussions about more general mechanism for languages to support new kinds of literal data. The most in-depth work I know of is from Lief's `#lang video`, where she's experimenting with non-linear video editor literals.

 Hope this helps.

-Philip
Reply all
Reply to author
Forward
0 new messages