Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6070859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:58:53+00:00 2026-05-23T09:58:53+00:00

I am trying to use Stuart Sierra’s do-template macro inside a defprotocol and the

  • 0

I am trying to use Stuart Sierra’s do-template macro inside a defprotocol and the Clojure compiler complains that I am redefining do-template — not what I intend:

(defprotocol AProtocol
  (a-method [_])
  (do-template [name]
    `(~(symbol (str name "-method")) [this that])
    foo
    bar
    baz))

This should expand to:

(defprotocol AProtocol
  (a-method [_])
  (foo-method [this that])
  (bar-method [this that])
  (baz-method [this that]))

The problem (I believe) is that the do-template s-expression is getting passed to defprotocol unexpanded. Is there any way to cause it to evaluate before being passed?

BTW, do-template should actually expand to

(do
  (foo-method [this that])
  (bar-method [this that])
  (baz-method [this that]))

but I already tried that (with a hand-expanded version) and defprotocol is fine with the nested do.

How can I see the actual expansion of the do-template? I tried both (macroexpand '(do-template ...)) and (macroexpand-1 '(do-template ...)) and got:

(do (clojure.core/seq
(clojure.core/concat
(clojure.core/list (symbol (str foo
“-method”))) (clojure.core/list
(clojure.core/apply
clojure.core/vector (clojure.core/seq
(clojure.core/concat
(clojure.core/list (quote user/this))
(clojure.core/list (quote
user/that)))))))) (clojure.core/seq
(clojure.core/concat
(clojure.core/list (symbol (str bar
“-method”))) (clojure.core/list
(clojure.core/apply
clojure.core/vector (clojure.core/seq
(clojure.core/concat
(clojure.core/list (quote user/this))
(clojure.core/list (quote
user/that)))))))) (clojure.core/seq
(clojure.core/concat
(clojure.core/list (symbol (str baz
“-method”))) (clojure.core/list
(clojure.core/apply
clojure.core/vector (clojure.core/seq
(clojure.core/concat
(clojure.core/list (quote user/this))
(clojure.core/list (quote
user/that)))))))))

Not exactly easy to read :-).

Also, I probably want the this and that to be anaphora and expand to themselves: ~'this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:58:53+00:00Added an answer on May 23, 2026 at 9:58 am

    (1) defprotocol is not fine with a do form. It doesn’t raise an error, but it doesn’t work either.

    (2) You can’t do what you want in this way. defprotocol is the macro being called, so it has absolute authority about how sub-forms are expanded.

    (3) Item (2) suggests a solution, in fact the same one as at least one of your recent questions: define a new macro, say with-methods, that takes a list of method names, followed by whatever other defprotocol arguments, and expands into a defprotocol with the appropriate substitutions and splicing already done, so that defprotocol can expand in peace without needing to know anything about your do-template trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use php to generate a 9 digit number that does not
I am trying to use validates_timeliness to ensure that SliderImage.start is always before SliderImage.stop
I am trying to use an OpenFileDialouge control to select a folder, so that
Trying to use NUnit to test a method that adds an object to a
I'm trying to use Java regexps to match a pattern that spans multiple lines.
I'm trying to use a regular expression to find all substrings that start with
I'm trying to use autocomplete inside of jquery mobile and it is working good
I'm trying to use sfPDOSessionStorage and it seems that it disables auto-start. Question is
I'm trying to use timeIntervalSinceReferenceDate and I'm not quite sure if I understand it
I am trying to use JavaScript to start a marquee when a user puts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.