(mac def-with-prefix (prefix name args . body) `(eval (list 'def (read (+ (coerce ,prefix 'string) "-" (coerce ',name 'string))) ,args ,@body)))
(= prefix 'blub) (def-with-prefix prefix foo (x) (+ 1 x))
(def blub-foo (x) (+ 1 x)))
-----
(mac def-with-prefix (prefix name args . body) `(def (read (+ (coerce ,prefix 'string) "-" (coerce ',name 'string))) ,args ,@body))
(def-with-prefix 'blub 'foo (x) (+ 1 x))
(def (read (+ ...blah...blah...)) (x) (+ 1 x))
`(def ,(read (+ (coerce prefix 'string) "-" (coerce name 'string))) ,args ,@body)
(= pre 'blub) (your-def-with-prefix pre foo (x) (+ 1 x)) => #<procedure: pre-foo> (my-def-with-prefix pre foo (x) (+ 1 x)) => #<procedure: blub-foo>
`(def ,(read (+ (coerce (eval prefix) 'string) "-" (coerce name 'string))) ,args ,@body)
(let pre2 'blub (your-def-with-prefix pre2 foo (x) (+ 1 x))) => Error: "reference to undefined identifier: _pre2"
cchooper, did you actually ever run your version? I can't make your orginal version work.
arc> (def-with-prefix pre foo (x) (+ 1 x)) Error: "reference to undefined identifier: _x"
arc> (macex '(def-with-prefix pre foo (x) (+ 1 x))) (eval (list (quote def) ; my indentation (read (+ (coerce pre (quote string)) "-" (coerce (quote foo) (quote string)))) (x) (+ 1 x)))
(mac def-with-prefix (prefix name args . body) `(eval (list 'def (read (+ (coerce ,prefix 'string) "-" (coerce ',name 'string))) ',args ,@(map [list 'quote _] body))))
Here's a slightly less clunky version:
(mac def-with-prefix (prefix name args . body) `(eval (join (list 'def (sym (+ (coerce ,prefix 'string) "-" (coerce ',name 'string))) ',args) ',body)))
In Arc:
arc> (= foo 's) s arc> (set foo 4) 4 arc> foo 4 arc> s Error: "reference to undefined identifier: _s"
CL-USER> (setf foo 's) S CL-USER> (set foo 4) 4 CL-USER> foo S CL-USER> s 4