Fork me on GitHub
#boot
<
2016-11-20
>
samedhi21:11:02

Is there a way in boot to eval a string?

samedhi21:11:24

Something like boot load-string “(+ 2 3)” => 5

micha21:11:16

@samedhi (eval (read-string "(+ 2 3)"))

samedhi21:11:09

Oops, I should have included, from the terminal.

samedhi21:11:21

So would print to stdout

micha21:11:31

how do you mean from the terminal

micha21:11:37

that works in the repl

micha21:11:39

for example

micha21:11:57

oh like from the command line

samedhi21:11:08

yep, that is what I meant.

samedhi21:11:19

I have a python script that I used to split up some clojure code, I then used the script to divide the code into segments. I want to evaluate the return value at every segment from the terminal.

samedhi21:11:58

So If I had 3 segments [0, 1, 2], I want to evaluate [0], then [0,1], then [0,1,2]

samedhi21:11:28

So I can insert the result of the last expressions return value between every segment.

samedhi21:11:31

If that makes sense.

micha21:11:39

like a threading macro

samedhi21:11:44

Hmm, More like if I had a file like so

(def x (+ 1 2))

(def y (+ x 4)

(* y x)

samedhi21:11:12

I want to generate another file that looks like this

(def x (+ 1 2))
=> x

(def y (+ x 4)
=> y

(* y x)
=> 10

samedhi21:11:40

Or something like that, I just want to know what the last expression up to each root expression evaluated to, so I can add my little thing (`=> XXX`) that says what the value was at that point.

micha21:11:11

hm yeah i'm not sure what the best way tod o that is

samedhi22:11:57

@micha (mostly just for those following at home). The following seems to work, the first task will not let you evaluate (ns …) declarations. The second seems to work fine.

(set-env!
 :source-paths #{"src/"}
 :dependencies
 '[[org.clojure/core.logic                  "0.8.10"]])

(deftask load-code-fails-to-load-namespaces
  "Loads and evaluates the string prints to STDOUT"
  [c code-to-eval VAL code "The code to be evaluated"]
  (-> code-to-eval println))

(deftask load-code
  "Loads and evaluates the string prints to STDOUT"
  [c code-to-eval VAL str "The code to be evaluated"]
  (-> code-to-eval load-string println))

samedhi22:11:06

Stephens-MacBook-Pro:reasoned stephen$ boot load-code -c "(ns reasoned.ch1
>   (:require
>    [clojure.core.logic :as logic :refer [run run* == u# s# fresh conde]])
>   (:refer-clojure :exclude [==]))
> ;; > Given
> (defn teacupo [x]
>   (conde
>    ((== :tea x) s#)
>    ((== :cup x) s#)))
> ;; > What is the value of
> (run* [r]
>   (teacupo r))
> "
(:tea :cup)

micha22:11:29

@samedhi you can try load-string, or write to a file and do load-file

micha22:11:39

for the ns issue