Re: defmacro help

2015-03-13 Thread Tobias Kortkamp
 then the error is on the (schema.core/defn) call. But notice the fully
 qualified 'create' - I want 'create' to be a literal in the namespace of
 the caller, not the namespace the macro is defined in.
 
 Any ideas?

Quote-unquote the symbol: ~'create

Example:

  `(defn create []) = (clojure.core/defn user/create [])
  `(defn ~'create []) = (clojure.core/defn create [])

-- 
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: Newify java class dynamically

2015-03-09 Thread Tobias Kortkamp
On 03/09/2015 15:45, Juvenn Woo wrote:
 Hi all,
 
 I am writing a function that'll take a java class name as an arg,
 wherein I'll make instance of the class. Several approaches did I try:
 
 (let [klass Integer] (new klass 42)) ; this raises exception unable to
 resolve symbol: klass
 
 (let [klass Integer] (.new klass 42)) ; raises no matching method
 found: new for class java.lang. Class
 
 I'm running out of ideas currently. How do you deal the use case like
 this? And what's the idiomatic way to do this?

You can use Java reflection for this or use the Reflector from Clojure:

(let [klass Integer]
   (clojure.lang.Reflector/invokeConstructor klass (into-array [42])))


-- 
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] from-scala 0.2.0: An experimental Scala interop library for Clojure

2015-03-09 Thread Tobias Kortkamp
Hi,

I would like to announce from-scala, an experimental Scala interop
library for Clojure.

Its main feature is the $-macro, a version of Clojure's
.-form.  The $-macro uses Java reflection and a series of heuristics,
so that you will be able to write code like

  ($ ($ scala.collection.immutable.List/empty) :: 1)

instead of the equivalent but ugly

  (.$colon$colon (.empty scala.collection.immutable.List$/MODULE$) 1)

Additionally there are some utility functions for working with case
classes, tuples, options, Scala functions, and Scala collections.

The source code can be found at https://github.com/t6/from-scala and
there are more examples in the guide at
https://t6.github.io/from-scala

To use from Leiningen:

  [t6/from-scala 0.2.0]
  [org.scala-lang/scala-library 2.11.5]

You need to provide your own Scala library.  from-scala has been
tested with Scala 2.10 and 2.11.

If you encounter any bugs or road blocks, have a feature request, or
want to discuss if this is a good or a bad idea, please open an issue
on GitHub.

Thanks,
Tobias

-- 
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 find adjacent cells in a matrix with core.logic ?

2015-01-02 Thread Tobias Kortkamp

Move membero to the beginning (just after fresh, like in succo), it runs
in  100 ms on my machine then.

-- 
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 handle fn args in a macro ?

2014-12-31 Thread Tobias Kortkamp

On 12/31/2014 18:56, rogergl wrote:
 To make this work I had to replace the symbol 'topic in the body with
 the gensym symbol. Is this the right way to do this ?

Your macro is too complicated. You don't need to gensym a symbol in this
case. Instead just quote a symbol before unquoting it (note the ~'), so
that it appears as is in the resulting form:

  (defmacro listen
[topic expression]
`(on-message ~topic (fn [~'topic] ~expression)))

Your example then expands to

  (on-message topic-test (fn [topic] (println topic test)))







-- 
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: midje test : Can I only run 1 test

2014-10-22 Thread Tobias Kortkamp
Yes, you can tag your facts, and then only run the facts with a specific 
tag.
See https://github.com/marick/Midje/wiki/Lein-midje under the :filter 
section.


--
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: [Very newbie] invocation of java code.

2014-10-01 Thread Tobias Kortkamp
java.util.TimerTask is an abstract class, which you cannot instantiate 
directly. You can use proxy to create a subclass:


(proxy [java.util.TimerTask] []
  (run [] ...))

Instead of (new java.lang.Boolean ...) use true or false directly.

There is syntactic sugar for new, just append a dot to the class name:

(java.io.File. ...) instead of (new java.io.File ...)

--
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: clojure/data.json parsing

2014-09-27 Thread Tobias Kortkamp
I hope I understood you correctly. You basically don't want to use 
println if you want to print data in such a way that it can be read in 
again. For that you need to use pr, prn or pr-str.


Example:

(println {:a hi there}) will print {:a hi there}

(prn {:a hi there}) will print {:a hi there}

(println Ex:  (pr-str {:a hi there})) will print Ex: {:a hi there}

In other words I suspect that your example's :paymentStatus is the 
string QUEUED already. You can check if a value v is a string with 
(string? v).


--
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: Clojure beginner: angst about doing things right

2014-09-22 Thread Tobias Kortkamp

Using map and sets:

(defn days-number-maker
  [all-days day-string]
  (let [day-set (set day-string)]
(map (fn [day]
   (if (day-set day)
 1
 0))
 all-days)))

(defn days-to-numbers
  Change string like MTTH to (1 1 0 1 0 0 0)
  [day-string]
  (let [days (clojure.string/replace
   (clojure.string/replace day-string #TH R) #SU N)]
(days-number-maker MTWRFSN days)))

--
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: defrecord inside defmacro

2014-09-14 Thread Tobias Kortkamp

Hi,

you need to syntax-quote the list you return from your macro.

  (defmacro some-record
[some-name]
`(defrecord ~some-name ['in 'out]))

Note the backtick `. You then also have to explicitly quote your record 
field names (see 'in and 'out, try to remove the quotes to see why). 
Also see

http://clojure.org/reader#The%20Reader--Macro%20characters
and http://www.braveclojure.com/writing-macros/

HTH

--
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: Does lein midje also run tests written using expectations?

2014-09-08 Thread Tobias Kortkamp

That `lein midje` runs your expectations is just a side effect of
expectations' behavior to run its tests on JVM shutdown. Use 
`(expectations/disable-run-on-shutdown)` to disable that feature.


 Just need to confirm that the behaviour is intentional and not just by

chance.


I guess it's a little bit of both ;-)


--
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: IllegalArgumentException when running core.async example

2014-07-09 Thread Tobias Kortkamp
In judge try changing

  (let [out async/chan] ...)

to

  (let [out (async/chan)] ...)



On Wednesday, July 9, 2014 5:57:53 AM UTC+2, endbegin wrote:

 Just tried it with Clojure 1.6.0. Still no luck!



-- 
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: Any Previous Work on Javadoc to Docstring Conversion?

2014-03-05 Thread Tobias Kortkamp
I have just uploaded some code I wrote earlier this year, where I 
originally set out to generate some useful docstrings for Java classes and 
methods.
It currently uses javadoc on all Java source files on the classpath and 
creates a map with the extracted information. I never finished it, but
this may still be useful to you :)

Check it out here: 
https://bitbucket.org/tobik/nrepl-javadoc/src/cdbfe0873ef04ee583a39f0538610daf289eff42/src/tobik/nrepl/tools.clj?at=master#cl-343
 


-- 
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/groups/opt_out.