Question

In the Windows power shell I run lein repl and then evaluate some Clojure functions that I have written. The functions output large matrices or vectors that are not easily transcribed by hand. This is why I'd like to be able to copy the data from the REPL, if that is possible, or find some way to quickly transfer the data to a word document or Google doc. Is there a way to copy the output from these functions out of the REPL to a document, or some means that the output can be "copy and pasted"?

Was it helpful?

Solution

Automatic cut-and-paste from and to the REPL

Have a look at Sean Devlin's clipboard utilities. It has functions that:

  • Sends it's argument (string) to the OS clipboard
  • Reads the contents of the clipboard as string value
  • Evals an s-expression from the clipboard

It's pretty old code, but has only java dependencies, so still works if you copy it into a namespace of your own.

Import and Export as CSV

Use clojure.data.csv

OTHER TIPS

It is possible save data into text files while at the REPL. You can them use a text editor of your choice to process it further. For example

user=> (def v (into [] (range 100)))
#'user/v
user=> v
[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99]
user=> (spit "c:\\temp\\blah.txt" (with-out-str (prn *1)))
nil
user=> (slurp "c:\\temp\\blah.txt")
"[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99]\n"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top