Skip to content

Commit 7afb307

Browse files
committed
various fixes
1 parent f4286d4 commit 7afb307

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

redex-pict-lib/redex/private/pict-interface.rkt

+37-25
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@
3737
[p:pict-width pict-width]
3838
[p:pict-height pict-height]
3939
[p:pict-descent pict-descent]
40-
[p:pict? pict?]
4140
[p:draw-pict draw-pict]
4241
[p:text-style/c text-style/c]
4342
[p:dc-for-text-size dc-for-text-size]))
4443

44+
(provide pict?)
45+
(define (pict? p)
46+
(choose
47+
(p:pict? p)
48+
(r:is_pict p)))
49+
4550
(define (to-rhm-pict p)
4651
(choose p (r:from_handle p)))
4752

@@ -70,16 +75,15 @@
7075
#:border-color [border-color #f]
7176
#:border-width [border-width #f])
7277
(to-rhm-pict
73-
(filled-rectangle w h
74-
#:draw-border? draw-border? #:color color
75-
#:border-color border-color #:border-width border-width)))
78+
(p:filled-rectangle w h
79+
#:draw-border? draw-border? #:color color
80+
#:border-color border-color #:border-width border-width)))
7681

7782
(define-rhombus
7883
(lib "pict/main.rhm")
7984
beside
8085
stack
81-
overlay
82-
line)
86+
overlay)
8387

8488
(define-rhombus
8589
rhombus/dot
@@ -101,9 +105,8 @@
101105

102106
(provide horizontal-line)
103107
(define (horizontal-line w)
104-
(choose
105-
(p:frame (p:blank w 0))
106-
(r:line #:dx w)))
108+
(to-rhm-pict
109+
(p:frame (p:blank w 0))))
107110

108111
(define-syntax-rule
109112
(define-simple name p:name r:name args ...)
@@ -143,19 +146,26 @@
143146
[(_ name racket-name rhombus-name rhombus-kwd rhombus-kwd-value)
144147
#'(begin
145148
(provide name)
146-
(define (name arg1 . args)
149+
(define (name . in-args)
147150
(choose
148-
(apply racket-name arg1 args)
149-
(keyword-apply rhombus-name
150-
(if (keyword<? 'rhombus-kwd '#:sep)
151-
(list 'rhombus-kwd '#:sep)
152-
(list '#:sep 'rhombus-kwd))
153-
(if (keyword<? 'rhombus-kwd '#:sep)
154-
(list rhombus-kwd-value (if (number? arg1) arg1 0))
155-
(list (if (number? arg1) arg1 0) rhombus-kwd-value))
156-
(if (number? arg1)
157-
args
158-
(cons arg1 args))))))]))
151+
(apply racket-name in-args)
152+
(call-rhombus-append rhombus-name 'rhombus-kwd rhombus-kwd-value in-args))))]))
153+
154+
(define (call-rhombus-append rhombus-fn rhombus-kwd rhombus-kwd-value in-args)
155+
(define-values (sep args)
156+
(cond
157+
[(and (pair? in-args) (number? (car in-args)))
158+
(values (car in-args) (cdr in-args))]
159+
[else
160+
(values 0 in-args)]))
161+
(keyword-apply rhombus-fn
162+
(if (keyword<? rhombus-kwd '#:sep)
163+
(list rhombus-kwd '#:sep)
164+
(list '#:sep rhombus-kwd))
165+
(if (keyword<? rhombus-kwd '#:sep)
166+
(list rhombus-kwd-value sep)
167+
(list sep rhombus-kwd-value))
168+
args))
159169

160170
(define-append ht-append
161171
p:ht-append
@@ -212,26 +222,28 @@
212222

213223
(define-namespace-anchor ns-anchor)
214224
(define ns (namespace-anchor->namespace ns-anchor))
215-
(define-values (r:find r:from_handle)
225+
(define-values (r:find r:from_handle r:is_pict)
216226
(cond
217227
[(rhombus-present?)
218228
(parameterize ([current-namespace ns])
219229
(namespace-require '(all-except rhombus #%top))
220230
(namespace-require 'rhombus/parse)
221231
(namespace-require 'redex/private/rhombus-bridge)
222232
(values (eval 'find)
223-
(eval 'from_handle)))]
233+
(eval 'from_handle)
234+
(eval 'is_pict)))]
224235
[else
225236
(values "dummy value that's not rhombus's find"
226-
"dummy value that's not rhombus's find_handle")]))
237+
"dummy value that's not rhombus's find_handle"
238+
"dummy value that's not rhombus's is_a Pict")]))
227239
(define-syntax (define-finder stx)
228240
(syntax-parse stx
229241
[(_ name racket-name horiz vert)
230242
#`(begin
231243
(provide name)
232244
(define (name pict subpict)
233245
(unless (pict? subpict)
234-
(error 'name "the version in pict-interface.rkt supports only picts, not pict paths"))
246+
(error 'name "the version in pict-interface.rkt supports only picts, not pict paths\n ~s" subpict))
235247
(choose
236248
(racket-name pict subpict)
237249
(r:find pict subpict horiz vert)))

redex-pict-lib/redex/private/rhombus-bridge.rkt

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
// racket code that does the same thing
88

99
import: pict open
10-
export: find from_handle
10+
export: find from_handle is_pict
1111

1212
fun find(pict,sub,h,v):
1313
Find(sub, ~horiz: h, ~vert: v).in(pict)
1414

1515
fun from_handle(p):
1616
Pict.from_handle(p)
17+
18+
fun is_pict(pict): pict is_a Pict

0 commit comments

Comments
 (0)