File: nest.rkt

package info (click to toggle)
racket 6.1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 91,944 kB
  • ctags: 38,251
  • sloc: ansic: 265,507; sh: 32,501; asm: 12,747; lisp: 6,958; cpp: 2,906; makefile: 2,284; pascal: 2,134; exp: 484; python: 366; xml: 11
file content (28 lines) | stat: -rw-r--r-- 965 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#lang racket/base

(provide nest)

;; A form that makes it easy to combine many "right-drifting" nested
;; expressions into a single one, sort of like a generalized version of the `*'
;; from `let*' and similar forms.
(define-syntax nest
  (syntax-rules ()
    [(nest () body0 body ...)
     (let () body0 body ...)]
    ;; this allows putting definitions in the body
    [(nest ([form forms ...]) body0 body ...)
     (form forms ... (let () body0 body ...))]
    [(nest ([form forms ...] . more) body0 body ...)
     (form forms ... (nest more body0 body ...))]))

;; using this instead will allow splicing body expressions in the last form
;; whatever it happens to be, which can be (ab)used in strange ways
#;
(define-syntax nest
  (syntax-rules ()
    [(nest () body ...)
     (begin body ...)]
    [(nest ([form forms ...]) body ...)
     (form forms ... body ...)]
    [(nest ([form forms ...] . more) body ...)
     (form forms ... (nest more body ...))]))