-1

I am new to Clojure. I am trying to understand clojure java interop. I have a java hashmap which I need to use in my Clojure program. I am trying to iterate on the hash map but it is giving me an error.

Main.java:

  package com.example;
  import java.util.HashMap;
  import java.util.Map;
  import clojure.java.api.Clojure;
  import clojure.lang.IFn;
  class Main {
       public static void main( String[] args ) {
          IFn require = Clojure.var("clojure.core", "require");
          require.invoke(Clojure.read("com.example.core"));
          IFn Print  = Clojure.var("com.example.core", "Print");
          Map<String, String> map = new HashMap<>();
          map.put("message", "hello world");
          Print.invoke(map);
   }
}

core.clj:

   (ns com.example.core
        (:gen-class))
   (defn Print [m]
       (doseq [[k v] map] (prn k v)))
   (defn -Print [m]
        (Print m))

When I am trying to run the program as a java application, it is saying- Exception in thread "main" java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.core$map.

When I am trying to run it as a clojure application it is saying- Exception in thread "main" clojure.lang.ArityException: Wrong number of args (0) passed to: core/-main.

I have tried to search for resources on the internet and everywhere it is being said that we need to use java hashmap in the same way as we use clojure map. But nothing is working for me and I don't know what am I doing wrong.

Any help would be appreciated.

ditri
  • 31
  • 3

1 Answers1

0

(defn Print [m] (doseq [[k v] map] (prn k v)))

I think map is support to be m I guess

Narendra Pinnaka
  • 205
  • 1
  • 2
  • 11