add 'else' support to 2dcond

closes PR 13714

original commit: 4bef2987a9e0d03b97b1221f77b8c72ec0bde308
This commit is contained in:
Robby Findler 2013-04-26 08:16:17 -05:00
parent d2630cd78f
commit f33f96a838

View File

@ -1,4 +1,5 @@
#lang racket
#lang racket/base
(require (for-syntax racket/base))
(provide 2dcond)
(define-syntax (2dcond stx)
@ -7,6 +8,9 @@
[(cell ...) rhs ...] ...)
(let ()
(define last-col (- (length (syntax->list #'widths)) 1))
(define last-row (- (length (syntax->list #'heights)) 1))
;; coord-to-content : hash[(list num num) -o> (listof syntax)]
(define coord-to-content (make-hash))
(define let-bindings '())
@ -35,6 +39,16 @@
(cond
[(member (list 0 0) cells) (void)]
[(and (or (member (list 0 last-row) cells)
(member (list last-col 0) cells))
(syntax-case rhses (else)
[(else) #t]
[_ #f]))
;; found an 'else' (in a reasonable place)
;; => treat it like a #t in that cell
(hash-set! coord-to-content
(car cells)
(list #'#t))]
[(and
;; only one cell:
(null? (cdr cells))