clojure

Why does leiningen make a directory hierarchy? Can I dispense with it?

穿精又带淫゛_ 提交于 2019-12-13 13:18:01
问题 If I create a new clojure project with leiningen, it makes a directory tree like so: . |-- doc | `-- intro.md |-- project.clj |-- README.md |-- src | `-- hello_friend | `-- core.clj `-- test `-- hello_friend `-- core_test.clj Often, all I want is a single clojure file, and I want to use leiningen to handle libraries and start a repl. I've got two questions: (1) Is is possible to get leiningen to work properly with this structure . |-- project.clj `-- hello.clj which I'd greatly prefer. (In

Partitioning in clojure with a lazy collection of strings

与世无争的帅哥 提交于 2019-12-13 13:14:06
问题 Starting with a collection of strings like: (def str-coll ["abcd" "efgh" "jklm"]) The goal is to extract off a specific number of characters from the head of the string collection, generating a partitioned grouping of strings. This is the desired behavior: (use '[clojure.contrib.str-utils2 :only (join)]) (partition-all 3 (join "" str-coll)) ((\a \b \c) (\d \e \f) (\g \h \j) (\k \l \m)) However, using join forces evaluation of the entire collection, which causes memory issues when dealing with

Parent eval (reader) function in Clojure source?

柔情痞子 提交于 2019-12-13 13:13:06
问题 In Peter Norvig's epic tome Paradigms of Artifical Intelligence Programming in Chapter 7 - he describes a function interp which is effectively a simple eval function used when interpreting a bare-bones Scheme in a REPL. (defun interp (x &optional env) "Interpret (evaluate) the expression x in the environment env." (cond ((symbolp x) (get-var x env)) ((atom x) x) ((case (first x) (QUOTE (second x)) (BEGIN (last1 (mapcar #'(lambda (y) (interp y env)) (rest x)))) (SET! (set-var! (second x)

How to run/debug compojure web app via counterclockwise (or la clojure)

拥有回忆 提交于 2019-12-13 13:01:17
问题 I'm trying to write my first web app in compojure. I'm using ccw, and I File-New-Project, Clojure Project and use the "compojure" leiningen template. End up with project.clj looking like (defproject asdf "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :dependencies [[org.clojure/clojure "1.4.0"] [compojure "1.1.5"]] :plugins [[lein-ring "0.8.2"]] :ring {:handler asdf.handler/app} :profiles {:dev {:dependencies [[ring-mock "0.1.3"]]}}) src/asdf/handler

Update matrix in-place in Clojure

白昼怎懂夜的黑 提交于 2019-12-13 12:42:56
问题 Suppose I have a Clojure matrix A as such (formatted for clarity) [[1 4 3] [1 7 3] [1 8 3]] Now suppose I want to update the first column in place, by e.g. multiplying it by a factor of two, so that the new matrix becomes [[2 4 3] [2 2 3] [2 8 3]] How would one do this in clojure? I have tried things like assoc and stuff like (join-along 1 (* (slice A 1 0) 2) (select A [0 1 2] [2 3])) Naturally that did not work. It would be great if there was something like assoc for matrices e.g. (massoc A

Make String from Sequence of Characters

微笑、不失礼 提交于 2019-12-13 12:08:53
问题 This code does not work as I expected. Could you please explain why? (defn make-str [s c] (let [my-str (ref s)] (dosync (alter my-str str c)))) (defn make-str-from-chars "make a string from a sequence of characters" ([chars] make-str-from-chars chars "") ([chars result] (if (== (count chars) 0) result (recur (drop 1 chars) (make-str result (take 1 chars)))))) Thank you! 回答1: You pass a sequence with one character in it to your make-str function, not the character itself. Using first instead

Use of Clojure macros for DSLs

房东的猫 提交于 2019-12-13 11:56:29
问题 I am working on a Clojure project and I often find myself writing Clojure macros for DSLs, but I was watching a Clojure video of how a company uses Clojure in their real work and the speaker said that in practical use they do not use macros for their DSLs, they only use macros to add a little syntactic sugar. Does this mean I should write my DSL in using standard functions and then add a few macros at the end? Update : After reading the many varied (and entertaining) responses to this

Abstracting away from data structure implementation details in Clojure

谁说我不能喝 提交于 2019-12-13 11:40:07
问题 I am developing a complex data structure in Clojure with multiple sub-structures. I know that I will want to extend this structure over time, and may at times want to change the internal structure without breaking different users of the data structure (for example I may want to change a vector into a hashmap, add some kind of indexing structure for performance reasons, or incorporate a Java type) My current thinking is: Define a protocol for the overall structure with various accessor methods

How To Do Clojure Program? [closed]

点点圈 提交于 2019-12-13 11:25:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I am learner, just now started learning regarding this.. Can anyone help me out??? Write a clojure program a function, most-frequent-word, which has two arguments. The first argument is a string, the second argument is an integer, call it n. most-frequent-word returns a sequence word(s) of length n that occurs

Rewriting java if statements in clojure syntax

流过昼夜 提交于 2019-12-13 10:19:12
问题 I have a set of recursive if statements written in Java and I tried taking it to clojure syntax but got the ArrayOutOfBound error. The functions accepts row = 0, col = 0 and a multidimensional array of characters. This is the Java Code: public static boolean solveMaze(int r, int c, char[][] maze) { //check for boundaries if(r < 0 || c < 0 || r >= maze.length || c >= maze[0].length) return false; //base case, did i reach the finish? if(maze[r][c] == '@') return true; //check if I'm at a valid