[racket] Exposition via macro

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Fri Jan 4 15:06:48 EST 2013

If you want to always have the shorthand be the variable tt, then this is a case for syntax parameters.

You would write

(require racket/stxparam)
(define-syntax-parameter tt (lambda (stx) (raise-syntax-error #f "Meant to be used within a with-* form" stx)))
(define-syntax-rule (with-timesten body ...)
  (syntax-parameterize ([tt (make-rename-transformer #'timesten)])
    body ...))

-Ian
----- Original Message -----
From: "Philipp Dikmann" <philipp at dikmann.de>
To: users at racket-lang.org
Sent: Friday, January 4, 2013 2:52:36 PM GMT -05:00 US/Canada Eastern
Subject: [racket] Exposition via macro

Hello everybody,

I'm trying to expose a module's functionality to the user via a macro 
that will let them use 'short-hand' names for the provided functions. 
Yet I want to keep the 'long' names inside the original code for 
clarity. The code below will not work - because of macro hygiene - but 
demonstrates the intention. How would you approach this?

#lang racket

(provide with-timesten)

(define (timesten x)
   (* x 10))

(define-syntax with-timesten
   (syntax-rules ()
     [(_ body ...) (let ([tt timesten])
                     (begin
                       body ...))]))

;; ... so the user can do:
(with-timesten
  (tt 1)
  (tt 2)
  (tt 3))

Best regards,
Philipp

____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Posted on the users mailing list.