Newbie: Setting definitions in pollen.rkt

40 views
Skip to first unread message

Jen Hutton

unread,
Jul 26, 2019, 4:24:12 PM7/26/19
to Pollen
I'm new to Pollen/Racket and I'm working on converting a small book project to an e-book as practice. The book is text and image, so I've been playing around with the pict and 2htdp libraries to draw the images for each page. 

The drawings are based on a shared library of simple geometric shapes, so I thought I could define all of the components and color palette in pollen.rkt and then call the ones I need in my html.pm pages (it's a long list for the entire book). I keep hitting a contract violation when I run the pages, and not sure why—tbh, contracts and how to troubleshoot them is a little out of my wheelhouse right now. 

Any help is appreciated—thanks.


pollen,rkt:

#lang racket/base

(require (prefix-in htdp: 2htdp/image)
         lang/posn
         pict
         racket/class pict)

; primary shape
(define rect (filled-rectangle 152 178))
(define bar-x (filled-rectangle 154 8))
(define bar-y (filled-rectangle 8 180))

; secondary shapes 
(define half-moon (clip-ascent (filled-ellipse 75 75)))
(define patch (filled-rectangle 73 83))

; spacers
(define gutter 15)
(define deg 0.2)

; the color palette
(define orange (list 255 102 51))
(define purple (list 38 13 38))
(define green (list 10 41 26))

(provide pict-as-png)

(define (pict-as-png pict)
  (let ([png-name (format "~a.png" (gensym))])
    (send (pict->bitmap pict) save-file png-name 'png)
    `(img ((src ,png-name)))))



#lang pollen

◊(pict-as-png
  (hbl-append ◊|gutter|
    (shear (colorize ◊|rect| ◊|orange|) 0 ◊|deg|)
    (shear (colorize ◊|rect| ◊|orange|) 0 -0.2))
)



pict->bitmap: contract violation
  expected: pict-convertible?
  given: '(hbl-append 15 (shear (colorize #<procedure:pollen-tag:filled-rectangle> "orange") 0 0.2) (shear (colorize #<procedure:pollen-tag:filled-rectangle> "orange") 0 -0.2))
...
  contract from: <pkgs>/pict-lib/pict/main.rkt




Evžen Wybitul

unread,
Jul 26, 2019, 5:09:35 PM7/26/19
to Pollen
It seems hbl-append isn’t recognized as a function, so it defaults to a pollen tag (quoted TXEXP). I’d recommend you to explicitly require the module which exports the hbl-append function in the .pm file, or explicit lying provide the function in pollen.rkt. I can’t test it myself right now, but that should help.

Jen Hutton

unread,
Jul 26, 2019, 6:03:37 PM7/26/19
to Pollen
Thanks. That fixed it, as well as adding (provide (all-defined-out)) to pollen.rkt. I seemed to have left that out too.

Matthew Butterick

unread,
Jul 26, 2019, 10:57:41 PM7/26/19
to Jen Hutton, Pollen

> On 07 26 19, at 3:03 PM, Jen Hutton <jenh...@gmail.com> wrote:
>
> Thanks. That fixed it, as well as adding (provide (all-defined-out)) to pollen.rkt. I seemed to have left that out too.



BTW though you can `require` any module within a Pollen source file, for instance:

#lang pollen
(require certain/module)
···

You can also propagate it via "pollen.rkt" with `all-from-out`, for instance:

#lang racket
(require certain/module)
(provide (all-from-out certain/module))
···


This has the same effect, because anything exported from "pollen.rkt" is implicitly available in a Pollen source file that relies on it.


Matthew Butterick

unread,
Jul 27, 2019, 12:30:15 AM7/27/19
to Jen Hutton, Pollen
Whoops that first example was missing a lozenge, should’ve been like so:

#lang pollen
◊(require certain/module)
···
--
You received this message because you are subscribed to the Google Groups "Pollen" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pollenpub+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pollenpub/2E381043-C583-4305-A59D-E097E6138DA3%40mbtype.com.

Jen Hutton

unread,
Jul 28, 2019, 3:34:06 AM7/28/19
to Pollen
That works too! I'll go with that so my source files stay cleaner. Thanks.


On Friday, July 26, 2019 at 9:30:15 PM UTC-7, Matthew Butterick wrote:
Whoops that first example was missing a lozenge, should’ve been like so:

#lang pollen
◊(require certain/module)
···


On Jul 26, 2019, at 7:57 PM, Matthew Butterick <m...@mbtype.com> wrote:


On 07 26 19, at 3:03 PM, Jen Hutton <jenh...@gmail.com> wrote:

Thanks. That fixed it, as well as adding (provide (all-defined-out)) to pollen.rkt. I seemed to have left that out too.



BTW though you can `require` any module within a Pollen source file, for instance:

#lang pollen
(require certain/module)
···

You can also propagate it via "pollen.rkt" with `all-from-out`, for instance:

#lang racket
(require certain/module)
(provide (all-from-out certain/module))
···


This has the same effect, because anything exported from "pollen.rkt" is implicitly available in a Pollen source file that relies on it.


--
You received this message because you are subscribed to the Google Groups "Pollen" group.
To unsubscribe from this group and stop receiving emails from it, send an email to poll...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages