How use Forward declaration in clojure and unbound variables across namespace

user1050817

I've this macro declared in a namespace named "helpers"

(defmacro reply [name-key & arguments] ;;macro use BUS, it needs to be declared in this namespace
   ~(<! (reply* (~name-key BUS) arguments)))

I need use it in other namespace "core" after initialized BUS in this namespace with a map

(def BUS {:something "a"})
(reply ...)

the namespace helpers only compile if BUS is declared in this namespace...I can declare it and then initialize it in my specific namespace

***helpers
(def BUS)
(declare BUS) ;;alternative
(defmacro reply... ) ;;using BUS in its body!

***other namespace
(def BUS {:a "b"})
(reply ...) ;; this macro use BUS

but this fails

BUS already refers to: #'yourvertxproject.helper-fun/BUS in namespace: test1.core, compiling:(test1/core.clj:13:1)

which is the correct way for do this?...

note: I've notice than some libs achieve this, for instance in korma db, you initialize the variable with the db path and configuration and then you can use the different functions which depends of this variable....

thanks!...

bsvingen

I believe you are looking for dynamic variables.

In your "helpers" namespace, declare *bus* (not "BUS") using

(def ^:dynamic *bus*)

before creating the macro.

Then, in the namespace where you are using this, do

(binding [*bus* {:a "b"}]
  ...)

(Be aware that binding is thread-local.)

In this case I would also refer the "helpers" using an :as shortcut with a qualified namespace to make it easier to see that *bus* is defined elsewhere.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to use $GLOBALS to share variables across php files?

분류에서Dev

Forward Declaration Stalls 앱

분류에서Dev

Scoped forward declaration

분류에서Dev

How to access variables and methods across controllers in Rails

분류에서Dev

How do you use a string across classes?

분류에서Dev

How to use XSLT to replace an element that is in a namespace?

분류에서Dev

how to use include_once() with namespace in laravel

분류에서Dev

How to use Monit Environment variables?

분류에서Dev

AngularJS - How to use includes with variables?

분류에서Dev

How to use find command with variables

분류에서Dev

How to properly use same text sections across multiple html pages?

분류에서Dev

How to use constant in class namespace as the array and template parameters?

분류에서Dev

Share variables internally across functions

분류에서Dev

Use LINQ XML with a namespace

분류에서Dev

Box iOS SDK - Receiver 'BoxSearchRequestBuilder' for class message is a forward declaration

분류에서Dev

Will forward slash work across platforms in Path.resolve?

분류에서Dev

How to use variables to create elements in an array in BASH?

분류에서Dev

how to use system environment variables in boto

분류에서Dev

How to use long variables name in Makefile?

분류에서Dev

How do I use URL directories as variables?

분류에서Dev

How to use variables inside back-quotes

분류에서Dev

Share variables across build pipelines in Azure devops

분류에서Dev

Global variables in Python across all modules

분류에서Dev

Accessing javascript variables across html files

분류에서Dev

Use php namespace inside function

분류에서Dev

How can I use unique hostnames across VMs with a shared root filesystem? Is this method even recommended?

분류에서Dev

How to parse XML with namespace

분류에서Dev

clojure use threading macro for equation

분류에서Dev

How to encapsulate in clojure?

Related 관련 기사

  1. 1

    How to use $GLOBALS to share variables across php files?

  2. 2

    Forward Declaration Stalls 앱

  3. 3

    Scoped forward declaration

  4. 4

    How to access variables and methods across controllers in Rails

  5. 5

    How do you use a string across classes?

  6. 6

    How to use XSLT to replace an element that is in a namespace?

  7. 7

    how to use include_once() with namespace in laravel

  8. 8

    How to use Monit Environment variables?

  9. 9

    AngularJS - How to use includes with variables?

  10. 10

    How to use find command with variables

  11. 11

    How to properly use same text sections across multiple html pages?

  12. 12

    How to use constant in class namespace as the array and template parameters?

  13. 13

    Share variables internally across functions

  14. 14

    Use LINQ XML with a namespace

  15. 15

    Box iOS SDK - Receiver 'BoxSearchRequestBuilder' for class message is a forward declaration

  16. 16

    Will forward slash work across platforms in Path.resolve?

  17. 17

    How to use variables to create elements in an array in BASH?

  18. 18

    how to use system environment variables in boto

  19. 19

    How to use long variables name in Makefile?

  20. 20

    How do I use URL directories as variables?

  21. 21

    How to use variables inside back-quotes

  22. 22

    Share variables across build pipelines in Azure devops

  23. 23

    Global variables in Python across all modules

  24. 24

    Accessing javascript variables across html files

  25. 25

    Use php namespace inside function

  26. 26

    How can I use unique hostnames across VMs with a shared root filesystem? Is this method even recommended?

  27. 27

    How to parse XML with namespace

  28. 28

    clojure use threading macro for equation

  29. 29

    How to encapsulate in clojure?

뜨겁다태그

보관