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 6753411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:09:28+00:00 2026-05-26T13:09:28+00:00

Ok, let’s try to get this straight: my final intent is to provide a

  • 0

Ok, let’s try to get this straight: my final intent is to provide a macro as an API to users which will look like:

(defscript [a b]
  (println a))

The result has to be an instance of a Script protocol, which looks like:

(defprotocol Script
  (run [this model]))

The idea being that the first argument to defscript is a list of symbols that needs to be bound to correspondent keys in the model:

(.run (defscript [a b] (println a)) {:a 1}) ;; yields 1

I can’t come up with any code that can effectively produce such effect, as I’m constantly hitting a wall when trying to use the model parameter, since at macro expansion time it’s just a symbol:

(defmacro invoke-
  [params model body]
  (let [p (flatten (map (fn [x] [x (model (keyword x))]) params))]
    `(let [~@p]
       ~body)))

(defmacro defscript
  [params & body]
  `(reify Script
    (run [~'this ~'model]
      (invoke- ~params ~'model ~@body))))

invoke- works fine if called directly:

(invoke- [a] {:a 1} (println a)) ;; prints 1

but it doesn’t work when used within defscript as model can’t be expanded correctly:

(.run (defscript [a] (println a)) {:a 1}) ;; prints nil

How can I get past this point and glue the pieces together?

  • 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-26T13:09:29+00:00Added an answer on May 26, 2026 at 1:09 pm

    It seems that basically, your argument vector is a shortcut for a destructuring binding:

    (defscript [a b] body)  -> (reify Script (run [this {:keys [a b]}] body))
    

    That way, model is destructured at run time, as it should be.

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

Sidebar

Related Questions

Let's say I can call a method like this: core::get() . What is the
Let's say you have a class called Customer, which contains the following fields: UserName
Let me try to explain what I need. I have a server that is
Let me preface this question by saying I use TextMate on Mac OSX for
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's assume that we are building a high traffic site that will be used
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have some text as follows: do this, do that, then this,
Let's suppose that we have multi-site CMS and every website in this CMS having
Let's say I have a main folder in my website named test which contains

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.