Hello Racketeers,

I come seeking advice. I'm trying to implement a Lisp-2 in Racket, but I've 
been unsuccessful in my initial attempts.

My goal is to be able to do something like the following:

```
(defun example (sym)
  (symbol->string sym))

(defvar example 'an-arbitrary-symbol)

(example example)
;=> "an-arbitrary-symbol"
```

And my here was my first stab at a solution:

```
#lang racket

(define-for-syntax functions-ns (make-empty-namespace))
(define-for-syntax values-ns (make-empty-namespace))

(define-syntax (defun stx)
  (syntax-case stx ()
    [(_ name (arg ...) body0 body ...)
     (parameterize ([current-namespace functions-ns])
       #'(define (name arg ...)
           body0
           body ...))]))

(define-syntax (defvar stx)
  (syntax-case stx ()
    [(_ name value)
     (parameterize ([current-namespace values-ns])
       #'(define name value))]))

;; Let's see whether these work.
(defvar example 'an-arbitrary-symbol)
(defun example (sym) (symbol->string sym))
(example example)
;;=> symbol->string: contract violation
;;=>   expected: symbol?
;;=>   given: #<procedure:example>
;;=>   context...:
;;=>    /opt/homebrew-cask/Caskroom/racket/6.4/Racket 
v6.4/collects/racket/private/misc.rkt:87:7
```

I'll be deeply grateful for help you can provide.

Cheers,
Josh

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to