0

I'm trying to define a function (or macro) which should only accept as arguments functions from a certain namespace

(ns ns1)
  (defn high-function[f & params]
    (if (condition on f meta regarding namespace)
        (apply f params)
        (throw (Exception. "not allowed"))))

The function calling high-function should be in another namespace (ns2), and the argument function in yet another namespace (ns3). ns2 requires ns1 and ns3.

I've tried passing the var of the function instead of the function, as the function has no meta but the var has, but cljs.core has no var-get method for me to execute the function afterwards. I could pass both the var and the function, but that's ugly.

1 Answer 1

1

Pass the var and use deref to get the function:

(defn high-function [f & params]
  (if (= 'app.ns3 (ns-name (:ns (meta f))))
    (apply @f params)
    (throw (Exception. "Not allowed."))))

(high-function #'app.ns3/foo ...)
Sign up to request clarification or add additional context in comments.

1 Comment

Please note that this is easily faked. I don't know what the motivation for this is, but don't rely on it for anything security critical.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.