Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
79 views

Infinite loop with `counto` relation in core.logic

I am interested in expressing the number of occurrences of an element in a list as a relational goal in Clojure's core.logic library. (Note that this question is not a duplicate of clojure core.logic ...
oper0's user avatar
  • 11
0 votes
1 answer
54 views

Clojure core.logic on Finite Domain subtraction not working as expected and not documented

I have written a Clojure program to solve a fairly simple problem. Consider a vector of a fixed size that we need to fill with integers. We must abide by the following rules. Every integer must be ...
mmachenry's user avatar
  • 1,952
2 votes
2 answers
79 views

why the following clojure core.logic expression returns no solutions? `(run* [a b] (== {:a b} {a :b}))`

Why the first expression (involving maps) doesn't yield any solutions, whereas the second one (involving vectors) does? (run* [a b] (== {:a b} {a :b})) ;> () but (run* [a b] (== [:a b] [a :b])) ;...
Lambder's user avatar
  • 2,993
1 vote
2 answers
164 views

how to work with complex data in Clojure edn/map

(def dbSample { :person [{:person/id 1 :name "dan" :surname "stone" :joindate "01.06.2022" :experience :experience/starter :loyalitylevel :...
Barış Can Ateş's user avatar
0 votes
3 answers
130 views

How to Extract Clojure string to enumerable of strings?

Suppose I have a simple string that I want to parse into array of string: "add (multiply (add 1 2) (add 3 4)) (add 5 6)" How do I parse it into 3 strings (based on outer parentheses): add (...
Kevin Tanudjaja's user avatar
1 vote
0 answers
137 views

Is it possible to insert a Clojure statement in the middle of a series of core.logic calls, "à la Prolog"?

Prolog mixes logic (fallible) goals, and (infallible) processes like write/2 or assert/1. Is it possible to do so with Clojure's core.logic? For example: (pldb/with-db myFacts (l/run* [x y] ...
Hugolin Bergier's user avatar
1 vote
1 answer
247 views

passing optional :query-param in clojure request

I have started learning clojure and have one use case where I would want to call a downstream service with query-params. Now these query-params can vary and can be absent. I am stuck at how to ...
Yash Jain's user avatar
  • 315
3 votes
1 answer
174 views

Performance characteristics of core.logic with many finite domain constraints

I'm learning relational programming in miniKanren and I decided to implement a time scheduling system. Basically, it boils down to three relations over finite domain. First, there is a time strip that ...
tsuki's user avatar
  • 907
1 vote
1 answer
71 views

Extracting finite domain lvars from a map

I want to put fresh lvars with a finite domain into a map, and establish a relationship between them in another part of my code. Consider the snippet below: (l/run 1 [q] (l/fresh [x y z a b c] ...
tsuki's user avatar
  • 907
1 vote
1 answer
98 views

Non-termination when query variable is on a specific position

Consider this blog post where the author implements palindrome relation using reverso: (defn reverso [l r] (conde [(== l ()) (== r ())] [(fresh [la ld ldr] (conso la ld l) (...
tsuki's user avatar
  • 907
2 votes
1 answer
321 views

How does one simply write an interceptor that extracts json from a get/post request using Pedestal

I am making a simple API That will require to read body parameters from a json/edn request I am trying to get the program to echo the contents as edn objects but something seems to not work here is my ...
Pouriyatajmehrabi's user avatar
1 vote
0 answers
30 views

Invoke java method that accept variable args from clojure [duplicate]

I have code block in java where I am trying to add customCodecProvider for mongo (use 'clojure.reflect 'clojure.pprint) (pprint (reflect org.bson.codecs.configuration.CodecRegistries)) { :bases #{...
arjunsv3691's user avatar
1 vote
0 answers
75 views

clojure ubergraph compiling error - 'namespace 'ubergraph.core' not found

I have been using ubergraph last few weeks up until this morning, but now am having compiling problem. In my project.clj's dependencies, ubergraph is declared: (defproject graph-alg "0.1.0-...
freebirds's user avatar
2 votes
2 answers
1k views

logic programming - find synonyms of a given word

Task is to write a program that can decide whether two words are synonyms or not. I have pairs of synonymous words, E.g.: [big large] [large huge] [small little] We can derive the synonymous ...
Sharas's user avatar
  • 875
1 vote
0 answers
82 views

Set membership in core.logic without CLP(set) - defne behaviour

As CLP(set) seems to be stuck in the "immediate" roadmap for now 7 years and counting, I'm trying to make an incomplete, inefficient substitute to at least be able to reflect the semantics ...
AticusFinch's user avatar
  • 2,411
1 vote
1 answer
124 views

How do I use core.logic to search for valid nested maps in a database of maps?

I'm currently working on a problem that asks to look for certain vendors that can fulfill an order. The vendors are represented as maps, as is the order. A vendor can fulfill an order if it can serve ...
Derek Taylor's user avatar
1 vote
1 answer
222 views

Clojure backward chaining for facts

We are using a forward-chaining rule system where we have to spoon-feed the system the data it needs to make a decision. I'd prefer the rule system can ask the questions to obtain the data needed for ...
Joel's user avatar
  • 2,688
4 votes
1 answer
775 views

Is a "facts database" not a core feature of miniKanren?

I have been playing around with miniKanren, trying to understand it by converting very basic Prolog tutorials into it. I use Python habitually so I started with the LogPy library, which has since been ...
Anentropic's user avatar
  • 33.5k
1 vote
1 answer
366 views

Minimize/maximize possible in clojure / core.logic?

I'm looking for an idiomatic constraint satisfaction solver that can maximize or minimize a goal function, rather than producing a list of matching solutions. To be precise, I'm more interested in ...
vanhemt's user avatar
  • 165
0 votes
1 answer
63 views

Constrain results from core.logic query?

I am trying to model a graph using core.logic and would like to match all nodes that have edges to two other nodes. I have come up with the below but it returns two results instead of the desired one, ...
mac's user avatar
  • 10k
3 votes
1 answer
790 views

Simple Prolog to Clojure core.logic

I've been playing with Prolog recently and getting my head around how to represent some tasks I want to do with it, which are largely about having a database of facts and doing simple queries on it, ...
interstar's user avatar
  • 26.9k
0 votes
1 answer
64 views

Prevent symbol call on require in Clojure

So here is my problem, I have a file sample.clj in namespace abc.xyzin which i am calling db init method directly before doing any CRUD operation. (db/init some-config) When i require this ...
KshiTij SiNgh's user avatar
2 votes
3 answers
339 views

How does clojure bind variable parameters?

I am a newbie in Clojure.The problem originated when I once checked the source code of conj: (def conj (fn ^:static conj ([] []) ([coll] coll) ([coll x] (clojure....
两极化's user avatar
  • 133
0 votes
1 answer
71 views

Is there a way to provide hints to the solver, about which paths are better?

Is there a way to prefer certain paths over others during solving? This is really a performance question. When I put all my logic together, it generates 1000’s of solution and this takes exponentially ...
Marc's user avatar
  • 824
0 votes
2 answers
217 views

Clojure: How to get an exact answer in a function that calculates the average [duplicate]

How do I get the exact answer instead of just the number / count I can get the average of a list of numbers, but it will only add the total numbers and divide by the count (defn aver [numbers] ...
Ryan Jackson's user avatar
0 votes
1 answer
94 views

How to rewrite the core.logic snippet?

I'm trying to rewrite the below piece of core.logic code. (run* [x y] (fd/in x (fd/domain 1 2)) (fd/in y (fd/domain 1 2))) o/p, ([1 1] [2 1] [1 2] [2 2]) I tried the below versions but ...
Kannan Ramamoorthy's user avatar
2 votes
1 answer
130 views

pseudo-relation in core.logic

In core.logic of function, I see the below definition for clojure.core.logic/everyg. A pseudo-relation that takes a coll and ensures that the goal g succeeds on every element of the collection. ...
Kannan Ramamoorthy's user avatar
3 votes
1 answer
102 views

Need clarification in understanding a custom core.logic constraint

I was trying to understand a custom core.logic constraint as defined below, (defne lefto "x appears to the left of y in collection l." [x y l] ([_ _ [x . tail]] (membero y tail)) ([_ _ [_ . ...
Kannan Ramamoorthy's user avatar
-1 votes
2 answers
888 views

Can anyone explain me about the sh in clojure in order to execute the system command?

I'm using Mac OS. I want to execute a system command using (use '[clojure.java.shell :only [sh]]), like in How to execute system commands?. I have read https://clojuredocs.org/clojure.java.shell/sh ...
Vikram Shaw's user avatar
4 votes
1 answer
280 views

Using apply in core.logic Clojure (CLP) Cryptoarithmetic

(ns verbal-arithmetic (:require [clojure.core.logic :refer [all run* everyg lvar == membero fresh conde succeed fail conso resto]] [clojure.core.logic.fd :as fd])) (comment "Solving ...
Clojurevangelist's user avatar
3 votes
1 answer
270 views

Clojure core.logic. Can I use complex data-structures in facts and rules?

I'm trying to get to grips with core.logic. Can I use complex data-structures in facts and rules? For example, I'm trying to do this : (pldb/db-rel test a) (defn is-wibble? [a] (= true (:wibble a)...
interstar's user avatar
  • 26.9k
1 vote
1 answer
112 views

Synthesize smallest map satisfying featurec constraints in core.logic?

In core.logic, is there a way to translate the outputs of a program like (run 2 [q] (fresh [a] (featurec q {:foo a}) (membero a '(5)) (conde ((featurec q {:bar 2})) ((...
Alex Lew's user avatar
  • 2,104
0 votes
2 answers
194 views

Function not returning (Clojure)

I am new to clojure, my function elligble voters is not returning the vector, where am i going wrong. (def human-db [ {:name "Kanishk" :age 28 :sex "male"} {:name "Kanishk1" :age 29 :sex "...
user2114063's user avatar
0 votes
1 answer
277 views

Debugging a slow performing function in Clojure

I am trying to implement a solution for minimum-swaps required to sort an array in clojure. The code works, but takes about a second to solve for the 7 element vector, which is very poor compared to ...
zooes's user avatar
  • 1,428
3 votes
1 answer
149 views

Correct use of logic languages as a tool

I'm interested in the "use the right tool for the job" philosophy in programming, and I have a problem I thought might be solvable with logic programming. I mean this in a naive way, because I haven't ...
Bobby's user avatar
  • 41
2 votes
2 answers
313 views

How to write your own simple constraint function in core.logic?

I just read the primer for core.logic. It makes sense so far, but I'm not sure where to go to learn more. Let's say I wanted to write my own constraint, sort of like the membero shown in the primer. ...
Rob N's user avatar
  • 16k
1 vote
1 answer
119 views

Why does this implementation of sorto does not terminate?

I'm a beginner with logic programming. I'm trying to implement a sorting relation like this: (sorto [3 2 1][1 2 3]) -> #s I'am using clojure and core.logic: I don't understand why this can ...
szymanowski's user avatar
  • 1,379
1 vote
0 answers
91 views

core.logic incomplete results

I'm struggling with this simple relation, the results are incomplete, and I don't understand why. I'm beginning with core.logic I don't know if it is a bug or my bad understanding of it. (...
szymanowski's user avatar
  • 1,379
5 votes
2 answers
1k views

Does MiniKanren have the "not" operator?

Does MiniKanren have the "not" operator? For example, how would one represent Prolog's a :- b, not(c) a is true if b is true and c is not (Prolog uses negation as failure, i.e. not(c) is considered ...
MWB's user avatar
  • 12.2k
3 votes
1 answer
260 views

Is there a logical for-all in clojure.core.logic?

I'm trying to solve the first puzzle in Smullyan's To Mock a Mockingbird using clojure.core.logic, not because it is particularly hard, but rather as an exercise. The puzzle states that there's a ...
Sebastian Oberhoff's user avatar
4 votes
1 answer
153 views

How to operate on a sequence of lvars

Say I want to get all combinations of bill/coins denominations that amount to a given value, given also a set of available denominations. So for instance, for (change 14 #{1 2 5 10}) I'd expect ( ...
alepeino's user avatar
  • 9,731
1 vote
0 answers
68 views

Clojure core.logic conde; quit if condition fails/succeded

does anyone know how to quit / try the next condition in a conde, when a condition fails? As example: (run* q (conde [(conditionA) (conditionB) (conditionC)] [(conditionA) (conditionD) (...
GameYoker's user avatar
0 votes
1 answer
55 views

core.logic explain how `fresh` changes results

Just starting out with core.logic, version "0.8.11": (q/run* [q] (q/fresh [a] (q/membero a [2 3])) (q/membero q [1])) I don't understand the result: (1 1). My understanding is that ...
nha's user avatar
  • 17.9k
1 vote
1 answer
423 views

what algorithms does clojure's core.logic use for solving? [duplicate]

According to wikipedia, prolog uses SLD Resolution. What are the principle algorithms driving the solving in core.logic?
matanox's user avatar
  • 13.9k
1 vote
1 answer
201 views

Can core.logic be used from Java directly?

Is it possible to gainfully use core.logic from Java code? If so, would greatly appreciate a simple example. If not, could someone point to a pure-Java alternative?
Don's user avatar
  • 1,191
3 votes
1 answer
217 views

core.logic query for string contains

I'm curios if it is possible (and if so how should one implement) something like string-containso in core.logic. an example usage would be something like (db-rel person x) (def database (db ...
boogie666's user avatar
  • 650
0 votes
2 answers
204 views

Tree search in Clojure core.logic

I've been puzzled by a modelisation problem for some time and I have to confess I have no idea how I could "properly" solve it in core.logic. It is very easy to state: given a tree (acyclic ...
piotr-yuxuan's user avatar
4 votes
0 answers
55 views

unexpected behavior in core.logic conjo goal

I have hard time understanding the following behavior of the conjo goal in core.logic. First, everything seems fine. (l/run* [q] (l/conjo q 2 3 [1 2 3] )) => ([1]) The goal succeeds when q = [...
shaft's user avatar
  • 2,219
0 votes
1 answer
129 views

How do I model an order relation in core.logic?

I'm trying to model an order relation between a finite set of tasks using core logic. This is what I have so far: (def tasks [:t0 :t1 :t2]) (defn tasko [x] (membero x tasks)) (db-rel before-...
Setzer22's user avatar
  • 1,639
1 vote
1 answer
149 views

Using core.logic to make a simple matching function

Suppose we define a relation matches via the following table: |-----+-----+-----+-----+-----| | | *A* | *B* | *C* | *D* | |-----+-----+-----+-----+-----| | *A* | | X | X | | |-----+---...
George's user avatar
  • 7,267