The old-fashioned way:

(require compatibility/defmacro)

(defmacro define-instruction (name&args body)
  (let ((name (car name&args)) (args (cdr name&args)) (body (cdr body)))
    `(define (,(string->symbol (format "~a-simulation" name)) ,@args)
      ,@body)))

(define-instruction (hello a b c)
  (sim (+ a b c)))

(hello-simulation 1 2 3)
;; > 6


--------------------------------------------
On Wed, 1/21/15, Peter Samarin <petrsama...@gmail.com> wrote:

 Subject: [racket] Define several procedures in a macro
 To: users@racket-lang.org
 Date: Wednesday, January 21, 2015, 3:21 PM
 
 
 
 Here is the construction of the simulator procedure:
 
 (define-syntax define-instruction
    (syntax-rules (sim)
      [(_ (name . args) (sim body-r
 ...))
       (begin
         (define name-string
 (symbol->string 'name))
         (define simulator-name
           (string->symbol
        
    (string-append
             name-string
 "-simulation")))
         (eval `(define (,simulator-name
 . args)
              
    body-r ...)))]))
 
 (define-instruction (hello a b c)
    (sim
     (+ a b c)))
 
 (hello simulation 1 2 3)
 ;; > 6
 
 

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

Reply via email to