Re: Don't Laugh - How to Get the Name of an Anonymous Function

2017-10-24 Thread Beau Fabry
If I had to guess I'd say the name of the function isn't stored with it

nil
boot.user=> (clojure.reflect/reflect (fn foo [] nil))
{:bases #{clojure.lang.AFunction}, :flags #{:public :final}, :members 
#{#clojure.reflect.Constructor{:name boot.user$eval1530$foo__1531, 
:declaring-class boot.user$eval1530$foo__1531, :parameter-types [], 
:exception-types [], :flags #{:public}} #clojure.reflect.Method{:name 
invoke, :return-type java.lang.Object, :declaring-class 
boot.user$eval1530$foo__1531, :parameter-types [], :exception-types [], 
:flags #{:public


On Monday, October 23, 2017 at 10:57:42 PM UTC-7, Shantanu Kumar wrote:
>
> Not sure whether you can deterministically recover the exact name at all 
> times, but the following can get you started:
>
> (re-matches #".*\$(.*)__.*" (.getName (class (fn cool-func! [] (println 
> "hi")
>
> I have altered the name to `cool-func!` on purpose to show where it may 
> break.
>
>
> Shantanu
>
> On Tuesday, 24 October 2017 10:35:12 UTC+5:30, Nick Mudge wrote:
>>
>> Let's say I have this anonymous function:
>>
>> (fn cool [] (println "hi"))
>>
>> How can I extract the name from it?
>>
>> Obviously the name of the function is stored with the function. How can I 
>> get to it?
>>
>>
>>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: Don't Laugh - How to Get the Name of an Anonymous Function

2017-10-24 Thread Ravindra Jaju
It's a good start.

You could next import clojure.lang.Compiler and call the static method
demunge like so on the output "cool_func_BANG_"
(Compiler/demunge "cool_func_BANG_") ; => "cool-func!"

On Tue, Oct 24, 2017 at 11:27 AM, Shantanu Kumar 
wrote:

> Not sure whether you can deterministically recover the exact name at all
> times, but the following can get you started:
>
> (re-matches #".*\$(.*)__.*" (.getName (class (fn cool-func! [] (println
> "hi")
>
> I have altered the name to `cool-func!` on purpose to show where it may
> break.
>
>
> Shantanu
>
>
> On Tuesday, 24 October 2017 10:35:12 UTC+5:30, Nick Mudge wrote:
>>
>> Let's say I have this anonymous function:
>>
>> (fn cool [] (println "hi"))
>>
>> How can I extract the name from it?
>>
>> Obviously the name of the function is stored with the function. How can I
>> get to it?
>>
>>
>> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: Don't Laugh - How to Get the Name of an Anonymous Function

2017-10-24 Thread Sean Corfield
No need to import the compiler. Use clojure.repl/demunge

Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)
_
From: Ravindra Jaju mailto:ravindra.j...@gmail.com>>
Sent: Tuesday, October 24, 2017 01:51
Subject: Re: Don't Laugh - How to Get the Name of an Anonymous Function
To: clojure mailto:clojure@googlegroups.com>>


It's a good start.

You could next import clojure.lang.Compiler and call the static method demunge 
like so on the output "cool_func_BANG_"
(Compiler/demunge "cool_func_BANG_") ; => "cool-func!"

On Tue, Oct 24, 2017 at 11:27 AM, Shantanu Kumar 
mailto:kumar.shant...@gmail.com>> wrote:
Not sure whether you can deterministically recover the exact name at all times, 
but the following can get you started:

(re-matches #".*\$(.*)__.*" (.getName (class (fn cool-func! [] (println 
"hi")

I have altered the name to `cool-func!` on purpose to show where it may break.


Shantanu


On Tuesday, 24 October 2017 10:35:12 UTC+5:30, Nick Mudge wrote:
Let's say I have this anonymous function:

(fn cool [](println "hi"))

How can I extract the name from it?

Obviously the name of the function is stored with the function. How can I get 
to it?



--
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 
toclojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
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 
toclojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: Don't Laugh - How to Get the Name of an Anonymous Function

2017-10-24 Thread Alex Miller
Just to chime in and second what others have said, functions do not encode 
their name in an accessible way. The best option right now is to use 
clojure.repl/demunge on the class name. 

This is a best-effort function as the transformation from Clojure function 
name to Java class class name is not unambiguously reversible (both - and _ 
become _ in the Java name, so this is a lossy transformation). A related 
ticket is http://dev.clojure.org/jira/browse/CLJ-1278.

On Tuesday, October 24, 2017 at 7:36:56 AM UTC-5, Sean Corfield wrote:
>
> No need to import the compiler. Use clojure.repl/demunge
>
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: How to spec meta?

2017-10-24 Thread Alex Miller
(s/def ::o #(s/valid? ::meta-spec (meta %)))

should work.

On Saturday, October 21, 2017 at 3:57:20 PM UTC-5, Vitalie Spinu wrote:
>
>
> Hi,
>
> If my meta spec looks like
>
> (s/def ::meta-spec (s/keys :req [::xyz]))
>
>
> how do I define a spec for objects whose meta conforms to `::meta-spec`?
>
> Thanks!
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: How to spec meta?

2017-10-24 Thread Vitalie Spinu

Thanks Alex. But then

  (s/assert ::o {})

gives

 failed: (valid? ::meta-spec (meta %))

which is not quite satisfactory.

Is my understanding correct that for a more integrated approach one would need a
custom Spec implementation? And if so, shouldn't it be part of the core then?

>> On Tue, Oct 24 2017 06:12, Alex Miller wrote:

> (s/def ::o #(s/valid? ::meta-spec (meta %)))

> should work.

> On Saturday, October 21, 2017 at 3:57:20 PM UTC-5, Vitalie Spinu wrote:
>>
>>
>> Hi,
>>
>> If my meta spec looks like
>>
>> (s/def ::meta-spec (s/keys :req [::xyz]))
>>
>>
>> how do I define a spec for objects whose meta conforms to `::meta-spec`?
>>
>> Thanks!
>>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: How to spec meta?

2017-10-24 Thread Alex Miller
Yes, you would need to actually create a spec implementation to improve the
error message in this case.

We haven't ever talked about spec'ing meta. In one sense I'd say the
general philosophy in Clojure is that meta is *not* part of the data (as in
how equality ignores meta), and thus it's not the purview of spec. But in
another sense I can see users creating a DSL to expect more from it.

Feel free to file an enhancement ticket to keep track of it.

On Tue, Oct 24, 2017 at 10:45 AM, Vitalie Spinu  wrote:

>
> Thanks Alex. But then
>
>   (s/assert ::o {})
>
> gives
>
>  failed: (valid? ::meta-spec (meta %))
>
> which is not quite satisfactory.
>
> Is my understanding correct that for a more integrated approach one would
> need a
> custom Spec implementation? And if so, shouldn't it be part of the core
> then?
>
> >> On Tue, Oct 24 2017 06:12, Alex Miller wrote:
>
> > (s/def ::o #(s/valid? ::meta-spec (meta %)))
>
> > should work.
>
> > On Saturday, October 21, 2017 at 3:57:20 PM UTC-5, Vitalie Spinu wrote:
> >>
> >>
> >> Hi,
> >>
> >> If my meta spec looks like
> >>
> >> (s/def ::meta-spec (s/keys :req [::xyz]))
> >>
> >>
> >> how do I define a spec for objects whose meta conforms to `::meta-spec`?
> >>
> >> Thanks!
> >>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[ANN] com.walmartlabs/lacinia 0.22.0

2017-10-24 Thread Howard Lewis Ship
Lacinia is an open-source implementation of Facebook's GraphQL
specification, in Clojure.

GraphQL is an outstanding approach to getting diverse clients and servers
exchanging data cleanly and efficiently.

The GitHub repository is https://github.com/walmartlabs/lacinia

Documentation: http://lacinia.readthedocs.io/en/latest/

Featured changes in 0.22.0:

- Allow 'query', 'mutation', and 'subscription' as the name of fields,
variables, etc.
- New API for parsing GraphQL schema (rather than EDN schema)

-- 
Howard M. Lewis Ship

Senior Mobile Developer at Walmart Labs

Creator of Apache Tapestry

(971) 678-5210
http://howardlewisship.com
@hlship

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Minor bug in clojure.zip/path

2017-10-24 Thread Maxim Bazhenov
Hi,

the documentation for clojure.zip/path states that it *"Returns a seq of 
nodes leading to this loc". *But the following test will fail (seq? returns 
false):
(require '[clojure.zip :as z])

(def v [[1]])

(def vz (z/vector-zip v))

(seq? (z/path (z/down (z/down vz

The path actually returns a vector which is not a seq

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[ANN] lacinia-pedestal/0.4.0

2017-10-24 Thread Howard Lewis Ship
lacinia-pedestal provides the Pedestal support to expose web endpoints
backed by Lacinia's GraphQL.

The GitHub repository is https://github.com/walmartlabs/lacinia-pedestal

Documentation: http://lacinia-pedestal.readthedocs.io/en/latest/

Featured changes in 0.4.0:

- The compiled schema may, instead, be a function that returns the compiled
schema (useful for REPL oriented development)

-- 
Howard M. Lewis Ship

Senior Mobile Developer at Walmart Labs

Creator of Apache Tapestry

(971) 678-5210
http://howardlewisship.com
@hlship

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: Minor bug in clojure.zip/path

2017-10-24 Thread adrian . medina
clojure.core/seq?
([x])
  Return true if x implements ISeq

(seq? []) => false

because...

(instance? clojure.lang.ISeq []) => false

Vectors do not implement ISeq. That's all the seq? predicate cares about.

But vectors are `seqable?`:

clojure.core/seqable?
([x])
  Return true if the seq function is supported for x

(seqable? []) => true

Colloquially, it is normal to refer to any seqable collection as a "seq". 

On Tuesday, October 24, 2017 at 4:13:51 PM UTC-4, Maxim Bazhenov wrote:
>
> Hi,
>
> the documentation for clojure.zip/path states that it *"Returns a seq of 
> nodes leading to this loc". *But the following test will fail (seq? 
> returns false):
> (require '[clojure.zip :as z])
>
> (def v [[1]])
>
> (def vz (z/vector-zip v))
>
> (seq? (z/path (z/down (z/down vz
>
> The path actually returns a vector which is not a seq
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Got NullpointerException when using loop/recur/let together

2017-10-24 Thread yihao yang
Hi, all

  I want to do sth. like query until timeout. So I write a function below.
(defn wait-ls-ready
  []
  (let [pair-fn (fn [] (
 (Thread/sleep 1000)
 (let [ret (try
 (c/exec :ls)
 0
 (catch RuntimeException e -1)
   ),
   time-now (quot (System/currentTimeMillis) 
1000)]
   '(ret (- time-now start-time))
 )
   ))]
(loop [start-time (quot (System/currentTimeMillis) 1000)
   time-out 10]
  (let [[ret time-delta] (pair-fn)]
(info node "Waiting gsql works...")
(if (= 0 ret) 0
  (if (> time-delta time-out)
(throw (RuntimeException.
 (str "'ls' not working in " time-out "seconds.")))
(recur start-time time-out
)
  )
)

But it returns a NullpointerException after 1 seconds. Could anyone help me 
out?

Thanks,
Yihao

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: Got NullpointerException when using loop/recur/let together

2017-10-24 Thread Justin Smith
you wrap a call to Thread/sleep in parens, in clojure this means you want
to call it, Thread/sleep returns nil and calling nil gives a
NullpointerException

Parens are not for grouping or sequencing things in clojure, and you don't
need them here - fn has an implicit do block already, in other contexts
where there isn't a do block implicitly, you can use do to sequence
expressions

On Tue, Oct 24, 2017 at 5:26 PM yihao yang  wrote:

> Hi, all
>
>   I want to do sth. like query until timeout. So I write a function below.
> (defn wait-ls-ready
>   []
>   (let [pair-fn (fn [] (
>  (Thread/sleep 1000)
>  (let [ret (try
>  (c/exec :ls)
>  0
>  (catch RuntimeException e -1)
>),
>time-now (quot (System/currentTimeMillis)
> 1000)]
>'(ret (- time-now start-time))
>  )
>))]
> (loop [start-time (quot (System/currentTimeMillis) 1000)
>time-out 10]
>   (let [[ret time-delta] (pair-fn)]
> (info node "Waiting gsql works...")
> (if (= 0 ret) 0
>   (if (> time-delta time-out)
> (throw (RuntimeException.
>  (str "'ls' not working in " time-out "seconds.")))
> (recur start-time time-out
> )
>   )
> )
>
> But it returns a NullpointerException after 1 seconds. Could anyone help
> me out?
>
> Thanks,
> Yihao
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.