Hello Brent,

The use case I had in mind was to keep a map readable during development.
Take a simple map: {:type QTDIR :path (hash "a string")}. It's easier to
play with this data if evaluation of certain symbols and functions is
delayed.

Thanks you both for your answer,
kind regards,
Dieter




On Mon, Nov 22, 2021 at 3:39 AM Brent Millare <brent.mill...@gmail.com>
wrote:

> I'm curious why you are saving hashmaps that have clojure code within it
> with the intention of evaluating this code as embedded in the hashmap? What
> is the use case? Are you trying to delay evaluation? Regardless, eval
> always incurs a cost and should generally be avoided if you can use
> "runtime" techniques instead. Is the embedded code trusted?
>
> Best,
> Brent
>
> On Sunday, November 21, 2021 at 9:22:47 AM UTC-5 dieter.v...@gmail.com
> wrote:
>
>> Hello,
>>
>> It seems to be a design decision that 0-arity invoke of a composite data
>> type gives an ArityException: the composite data type does not implement
>> the IFn when no arguments are given.
>> Is there a certain design decision behind this behavior? (or a certain
>> use-case)
>>
>>
>> repl> ;composite data type evaluates to itself
>> repl> {:a 1 :b (hash "word")}
>> {:a 1 :b -304538205}
>> repl> '{:a 1 :b (hash "word")}
>> {:a 1 :b (hash "word")}
>> repl> (def mydata '{:a 1 :b (hash "word")})
>> repl> mydata
>> {:a 1 :b (hash "word")}
>> repl> ;composite data type implements IFn for its keys
>> repl> (mydata :b)
>> (hash "word")
>> repl> ; there is no '0-arity' implementation of IFn for composite data
>> type
>> repl> ({})
>> ... (ArityException)...
>> repl> (mydata)
>> ... (ArityException)...
>> repl> ; instead i have to type eval
>> repl> ((eval mymap) :b)
>>  -304538205
>>
>> I know its only 4 letters and a space extra, but software composition is
>> supposed to avoid code duplication and perhaps the idea makes sense that
>> invoking a map without arguments evaluates it... Hence the question about
>> the choice made for the current behavior.
>>
>> A possible small workaround
>> (defrecord qid [qid]
>>      clojure.lang.IFn
>>      (invoke [this] (eval qid))
>> But expect this to throw alot of bugs: this record is not the same simple
>> map.
>> (issues with other protocols, reducers, transducers and much more I don't
>> know of.)
>>
>> I hope this is the right google group to ask this question.
>> kind regards,
>> Dieter
>>
>> --
> 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 with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Clojure" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/clojure/d16Ow0MvhPU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> clojure+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/clojure/ff296de8-ce0f-4798-a1cc-cd3e4b38c631n%40googlegroups.com
> <https://groups.google.com/d/msgid/clojure/ff296de8-ce0f-4798-a1cc-cd3e4b38c631n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/CAC2TPPhuLSWQ%2BoB0m1EqLOKrSouP-9oUTbhrs88ZyghChcj%3D9w%40mail.gmail.com.

Reply via email to