1

I am trying to run the function membero as outlined by https://clojuredocs.org/clojure.core.logic/membero

(ns clojure-noob.core
  (:gen-class) 
  (:require [clojure.core.logic :as logic]))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))

(logic/membero :a [:a :b :c]) ; => Could not resolve symbol: logic/membero
(clojure.core.logic/membero  :a [:a :b :c]); => Could not resolve symbol: clojure.core.logic/membero

I am just starting out my clojure journey, please be gentle. I see 2 possibilities,

  • a) membero is deprecated or shifted to some other directory
  • b) something about my setup that is preventing me from running it.

a) seems to be ruled out since there are still membero mentions in recent post How do I use core.logic to search for valid nested maps in a database of maps? Set membership in core.logic without CLP(set) - defne behaviour

Teong Leong
  • 813
  • 1
  • 6
  • 9
  • 1
    Did you add dependency into `project.clj`? `[org.clojure/core.logic "1.0.1"]` – Martin Půda Jun 08 '22 at 11:17
  • 1
    And if you're just starting with Clojure and you were looking for basic function to check whether given element is in given sequence, `membero` is something entirely different. – Martin Půda Jun 08 '22 at 11:30
  • @MartinPůda adding the dependency seems to do the trick. but what should be the proper require call if I were doing it within repl? And yes I am aware membero probably isn't used like this, I am just trying to learn by calling with it. – Teong Leong Jun 08 '22 at 12:16
  • Require call in REPL is done like this: `(require '[clojure.core.logic :as logic])`. But again: `membero` is function for logical Prolog-like programming and if you're really starting, don't learn some random functions and check books like Getting Clojure, Living Clojure or Clojure for the Brave and True instead. – Martin Půda Jun 08 '22 at 12:48
  • To clarify that membero isn't the point of this post. I picked it because it is not something that you can call without adding the proper dependency. Something like (require '[clojure.core.logic :as logic]) in repl doesn't work. That is why I am curious what is the proper way to require it if clojure.core.logic isn't a namespace addressable without mentioning that it is in 1.0.1 – Teong Leong Jun 08 '22 at 13:23
  • We need to know your build tool first (e.g. is it Leiningen, the clojure CLI tools, ...). Then you always have to add the artifact so the build tool can find it. This includes the version (unless you use some sort of BOM) – cfrick Jun 08 '22 at 13:39

1 Answers1

1

Thank you to Martin Půda for pointing me to dependencies.

membero was not the point of this post. My problem is not knowing where to add dependencies when I start seeing "Could not resolve symbol:" errors.

Adding the dependency in project.clj like the following solves the issue.

(defproject clojure-noob "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "https://www.eclipse.org/legal/epl-2.0/"}
  :dependencies [[org.clojure/clojure "1.10.3"] 
                 [org.clojure/core.logic "1.0.1"]]
  :main ^:skip-aot clojure-noob.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all
                       :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}})

My next confusion that followed was why can't we do (require [org.clojure/core.logic "1.0.1"]) in repl to just change the dependencies without restarting repl.

Turns out this is something that is not supported out of the box but commonly requested https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357 Any way to add dependency to lein project without REPL restart? Any way to add dependency to lein project without REPL restart?

Promegranate https://github.com/clj-commons/pomegranate was proposed as a means to do it. Will post an update when I tried it.

Teong Leong
  • 813
  • 1
  • 6
  • 9