PasteRack.org
Paste # 24519
2015-05-21 05:57:00

Fork as a new paste.

Paste viewed 219 times.


Embed:

A non-recursive define

  1. #lang racket
  2. (define-syntax (define/nonrec so)
  3.   (syntax-case so ()
  4.     [(_define (id . args) . body)
  5.      #'(define (id . args)
  6.          (let-syntax ([id (lambda (stx)
  7.                             (syntax-case stx (id)
  8.                               #'(raise-syntax-error 'id "not in scope" stx)))])
  9.            . body))]))
  10.  
  11. (define/nonrec (foo x) (+ x 1))
  12. (foo 2)
  13.  
  14. (define/nonrec (bar x) (bar (+ x 1)))
  15. (bar 2)

=>

3

eval:4:0: bar: not in scope

  in: (bar (+ x 1))

bar: undefined;

 cannot reference an identifier before its definition

  in module: 'm