dontexist
dontexist

Reputation: 5652

Function uses and is part of map (circular dependency?)

I'm writing a mini-shell thing for fun, and I'm trying to define a map of commands where one of the commands is help. help should print all available commands, and I (try to) do this by looping through the keys of the commands map, but since help is part of it, no matter which order I define them in, I always get a Use of undeclared variable-warning. How do I solve this?

(def commands {:help help})

(defn help []
  (echo! "The available commands are:")
  (doseq [available-command (keys commands)]
    (echo! (name available-command))))

Upvotes: 1

Views: 138

Answers (1)

Yuri Steinschreiber
Yuri Steinschreiber

Reputation: 2698

Add

(declare help)

at the beginning.

Upvotes: 4

Related Questions