On this page:
pict-if
pict-cond
pict-case
show
hide
6.2.900.17

11 Conditional Combinations

 (require pict/conditional) package: pict-lib

These pict control flow operators decide which pict of several to use. All branches are evaluated; the resulting pict is a combination of the pict chosen by normal conditional flow with ghost applied to all the other picts. The result is a picture large enough to accommodate each alternative, but showing only the chosen one. This is useful for staged slides, as the pict chosen may change with each slide but its size and position will not.

syntax

(pict-if maybe-combine test-expr then-expr else-expr)

 
maybe-combine = 
  | #:combine combine-expr
Chooses either then-expr or else-expr based on test-expr, similarly to if. Combines the chosen, visible image with the other, invisible image using combine-expr, defaulting to lbl-superimpose.

Example:

> (let ([f (lambda (x)
             (pict-if x
                      (disk 20)
                      (disk 40)))])
    (hc-append 10
               (frame (f #t))
               (frame (f #f))))

image

syntax

(pict-cond maybe-combine [test-expr pict-expr] ...)

 
maybe-combine = 
  | #:combine combine-expr
Chooses a pict-expr based on the first successful test-expr, similarly to cond. Combines the chosen, visible image with the other, invisible images using combine-expr, defaulting to lbl-superimpose.

Example:

> (let ([f (lambda (x)
             (pict-cond #:combine cc-superimpose
               [(eq? x 'circle) (circle 20)]
               [(eq? x 'disk) (disk 40)]
               [(eq? x 'text) (text "ok" null 20)]))])
    (hc-append 10
               (frame (f 'circle))
               (frame (f 'disk))
               (frame (f 'text))))

image

syntax

(pict-case test-expr maybe-combine [literals pict-expr] ...)

 
maybe-combine = 
  | #:combine combine-expr
Chooses a pict-expr based on test-expr and each list of literals, similarly to case. Combines the chosen, visible image with the other, invisible images using combine-expr, defaulting to lbl-superimpose.

Example:

> (let ([f (lambda (x)
             (pict-case x
               [(circle) (circle 20)]
               [(disk) (disk 40)]
               [(text) (text "ok" null 20)]))])
    (hc-append 10
               (frame (f 'circle))
               (frame (f 'disk))
               (frame (f 'text))))

image

procedure

(show pict [show?])  pict?

  pict : pict?
  show? : any/c = #t

procedure

(hide pict [hide?])  pict?

  pict : pict?
  hide? : any/c = #t
These functions conditionally show or hide an image, essentially choosing between pict and (ghost pict). The only difference between the two is the default behavior and the opposite meaning of the show? and hide? booleans. Both functions are provided for mnemonic purposes.