A remark from someone who's not a clojure expert, and isn't familiar with
4clojure or its goals:
IMO eval isn't bad. It's a tool, and it can be abused like any tool. You
have a choice. Using eval with your original code would be a lot simpler,
but there are tradeoffs.
--
You received this m
After the above discussion, I suspect that the point of this 4clojure
question is that using eval or resolve opens up the possibility for a user
of the function to inject arbitrary code into the 'Universal Computation
Engine', whereas using a map necessarily restricts the operations to the
'all
my bad, the above example is wrong it is meant to return a function of the
environment mappings :
(fn !! [c]
(fn [m] (let [ [f & as]
(map
#(if (sequential? %)
((!! %) m)
(let [x (m %)] (if x x %))) c)]
(apply ({'/ / '+ + '- - '* *} f) as
--
Secondly, 4clojure tells me use of resolve is bad as well :
i.e. the following is my latest code
(fn evaluate [c m]
(let [ [f & as]
(map
#(if (sequential? %)
(evaluate % m)
(let [x (m %)] (if x x %))) c)]
(apply (resolve f) as)))
--
You receive
Ah I think I get it. 'x is a symbol pointing to a var which is a box that
contains some value (i.e. which could be a function)
i.e. the following def creates a var, puts 1 into it, then creates a symbol
'x and finally adds it to the user namespace :
user=> (def x 1)
#'user/x
we can see it in t
This happens because a Symbol is a "function that looks itself up in its
argument" much like Keywords do:
user=> ('a {'a 2 'b 3})
2
user=> ('b {'a 2 'b 3})
3
user=> ('b 42)
nil
And the two argument version provides a default value to return if the symbol
is not found:
user=> ('c {'a 2 'b 3} ::
On Fri, Mar 21, 2014 at 4:44 PM, John Mastro wrote:
>
> That's interesting. It seems it's the last form in the list that's being
> returned, and it doesn't matter what function you apply
>
Sigh, clearly sometimes I type faster than I think. That should be "it
doesn't matter what symbol you apply",
On Fri, Mar 21, 2014 at 4:44 PM, John Mastro wrote:
>
> (let [f '(+ 1 1)]
> (apply (resolve (first f) (rest f
> ;=> 2
>
Sorry, I have a typo in there. It should be:
(let [f '(+ 1 1)]
(apply (resolve (first f)) (rest f)))
--
John Mastro
--
You received this message because you are subsc
On Fri, Mar 21, 2014 at 3:55 PM, Andy Smith wrote:
> I came across the following issue when doing problem
>
> user=> (let [f '(+ 1 1)] (apply (first f) (rest f)))
> 1
That's interesting. It seems it's the last form in the list that's being
returned, and it doesn't matter what function you apply
(
Andy Smith writes:
> I came across the following issue when doing problem
>
> user=> (let [f '(+ 1 1)] (apply (first f) (rest f)))
> 1
>
> I could use eval but eval is bad (apparently)...
>
> Investigating this further I can see that :
>
> user=> (let [f '(+ 1 1)] (type (first f)))
> clojure.lan
that is 'problem 121 from 4clojure'
http://www.4clojure.com/problem/121
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient
11 matches
Mail list logo