Re: How can I add meta to an object that doesn't implement IObj?

2014-08-31 Thread Atamert Ölçgen
On Mon, Sep 1, 2014 at 1:52 AM,  wrote:

> If you don't want to wrap the object in an atom, you can also reify an
> object that supports IDeref which returns your object. All reified objects
> support IObj out of the box.
>

As I said earlier:

... can't deref it since I can't change the functions that will use it
> later.


And again, later:

I can't really pass a list since the first function is expecting the object
> I am passing,


That was why I was asking how to attach metadata.



>
> On Sunday, August 31, 2014 4:55:58 AM UTC-4, Atamert Ölçgen wrote:
>
>> Hi Francis,
>>
>>
>> On Sat, Aug 30, 2014 at 1:34 PM, Francis Avila  wrote:
>>
>>> It would probably help if you said more about the source of this
>>> atom-holding object. Is it a plain Java class? A deftype/defrecord? Is it
>>> final?
>>>
>>
>> It's not an atom-holding object. The only guarantee is that this object
>> extends one (or two) of these protocols: http://clecs.muhuk.
>> com/api/0.2.1/clecs.world.html
>>
>> Other than that, it can be anything. A Java class, or a type or a
>> record...
>>
>>
>>
>>>
>>>
>>> If you can control the construction of this object and its class is not
>>> final, you can subclass it and add an IObj implementation. (Note that most,
>>> maybe all clojure ways of creating classes create final classes, so this
>>> technique won't work.) The easiest way to subclass is with `proxy`:
>>>
>>> (defn meta-AtomHolder [atom-value metadata]
>>>   (proxy [AtomHolderClass clojure.lang.IObj] ;; [superclass, new
>>> interfaces]
>>>  [atom-value] ;; constructor args
>>> (meta [] metadata) ;; subclass method
>>> (withMeta [newmeta] (meta-AtomHolder newmeta
>>> => (var user/meta-AtomHolder)
>>> (meta-AtomHolder (atom "x") {})
>>> => #>> IObj$40298964@302c28cc>
>>> (meta (meta-AtomHolder (atom "x") {}))
>>> => {}
>>> (meta (with-meta (meta-AtomHolder (atom "x") {}) {:a 1}))
>>> => {:a 1}
>>>
>>
>> This is really cool. So I can do (deref (meta-AtomHolder (atom "x") {}))
>> and it would return "x", right?
>>
>> I have actually managed to solve it using vars, had to move things around
>> a bit: https://github.com/muhuk/clecs/blob/master/src/clecs/
>> world/check.clj#L73
>>
>>
>>
>>>
>>> If the parent class is final or you can't construct the object yourself,
>>> you need to delegate method calls from one instance to this object
>>> instance. I think this is hard-but-not-impossible in java, but I'm not sure.
>>>
>>> (Clojurescript has `specify`, which does exactly what you want, but only
>>> exists because delegation between instances in javascript is trivial.)
>>>
>>> On Friday, August 29, 2014 10:16:05 PM UTC-5, Atamert Ölçgen wrote:

 Obviously I can't.

 But I need to add this capability to an object. During testing I attach
 meta to this object that contains an atom. Then I pass this object to other
 functions, known in runtime. I can't use a dynamic var because all this
 happens within a mock function that may be retried and run in different
 threads.

 I have seen this: http://stackoverflow.com/questions/20724219/simplest-
 possible-clojure-object-that-can-accept-a-primitive-and-metadata but
 can't deref it since I can't change the functions that will use it later.
 If I wrap this object I need to be able to delegate all of its
 functionality to the original object.

 I hope this all is not too vague. The code I'm working on is not online
 yet. But it's for clecs (https://github.com/muhuk/clecs/), I'm adding
 quickcheck to compare different world implementations.


 --
 Kind Regards,
 Atamert Ölçgen

 -+-
 --+
 +++

 www.muhuk.com

>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Kind Regards,
>> Atamert Ölçgen
>>
>> -+-
>> --+
>> +++
>>
>> www.muhuk.com
>>
>  --
> 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
> --

Howto Load Project Namespaces in Leiningen Plugins

2014-08-31 Thread Timothy Washington
Ok,

So I'm trying to write a leiningen plugin that takes some namespace
arguments. Let's call it **. This is a brand new plugin, so
everything else is empty, and this value is present: *{:eval-in-leiningen
true}*. My problem happens when, in the context of the project **
is acting on, the plugin code fails. I pass in some project-local namespace
that I want to eval (which is definitely present). And I get this
situation:

*Error*

java.lang.Exception: No namespace:  found


*Offending Code*

(defn check-foreach-namespace [namespaces]


  (let [fnss (filter #(= Fubar (type (var-get %)))

 (vals *(ns-publics (symbol (first namespaces)))*))]


(println "filtered-namespace [" fnss "]")))


(defn myplugin [project & args]

  (check-foreach-namespace args))



So then, if I try to require the namespace being passed in, that too fails
like so:

*Error: *

java.io.FileNotFoundException: Could not locate  on
classpath:


*Offending Code:*

(ns leiningen.chesk

  (:require [clojure.test.check :as tc]

[clojure.test.check.generators :as gen]

[clojure.test.check.properties :as prop]))


(defn check-foreach-namespace [namespaces]



  (let [nss (map *#(require (symbol %))* namespaces)

 fnss (filter #(= clojure.test.check.generators.Generator (type
(var-get %)))

 (vals (ns-publics (symbol (first nss)]


(println "filtered-namespace [" fnss "]")))


(defn myplugin [project & args]

  (check-foreach-namespace args))


Looking around, I thought I had found some relevant instruction on how to
handle this gilardi scenario
.
So I tried to use *eval-in-project* with and without namespace prefix, and
with several permutations of quoting. This is the error that occurs.

*Error: *

clojure.lang.Compiler$CompilerException: java.lang.ClassNotFoundException:
leiningen.core.eval


*Offending Code: *

(ns leiningen.chesk
  (:require [clojure.test.check :as tc]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop]))

(defn check-foreach-namespace [namespaces]

  (let [fnss (filter #(= clojure.test.check.generators.Generator (type
(var-get %)))
 (vals (ns-publics (symbol (first namespaces)]

(println "filtered-namespace [" fnss "]")))

(defn myplugin [project & args]
  (*leiningen.core.eval/eval-in-project* project
   (check-foreach-namespace args)
   (map #(require (symbol %)) args)))




So something that looks like it should be straightforward, is not working
out as planned. I also can't quite see how other plugins are doing this.
lein-midje seems a bit cryptic (see here

and here
).
Are there any clearer examples?


Tim Washington
Interruptsoftware.com 

-- 
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: Transducers are Coming

2014-08-31 Thread Niels van Klaveren
Great to see that it's on the cards. Really looking forward to be able to 
use this when stable. Also, wouldn't transducers also open up the way to 
define the chunking size of transduced lazy operations ? Something like 
(with-chunk-size 1 (xform data)) ? Or would this make chunking a non-issue 
anyway ?

On Thursday, August 7, 2014 2:05:33 PM UTC+2, Rich Hickey wrote:
>
> The integration with reducers is still todo. 
>
> On Aug 7, 2014, at 7:03 AM, Niels van Klaveren  > wrote: 
>
> > Will the new transducer abstraction also (partly) replace / incorporate 
> the reducer library ? 
> > So we could do something like (def xform (comp (fold +) (map inc) 
> (filter even?)))  to leverage parallelism ? 
> > 
> > On Wednesday, August 6, 2014 8:01:24 PM UTC+2, Rich Hickey wrote: 
> > I pushed today the initial work on transducers. I describe transducers 
> briefly in this blog post: 
> > 
> > http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming 
> > 
> > This work builds on the work done for reducers, bringing 
> context-independent mapping, filtering etc to other areas, such as 
> core.async. 
> > 
> > This is work in progress. We will be cutting alpha releases to help make 
> it easier to start using core's transducers together with core.async's new 
> support for them. 
> > 
> > I am very excited about this powerful technique and how we all might use 
> it. 
> > 
> > Please have a look. 
> > 
> > Feedback welcome, 
> > 
> > Rich 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Clojure" group. 
> > To post to this group, send email to clo...@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+u...@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+u...@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: clojure streams

2014-08-31 Thread Andy Fingerhut
Found it:

"Don't worry about streams - they lost to chunked seqs. Any vestiges just
need to be removed.   -- Rich"


https://groups.google.com/forum/#!msg/clojure-dev/VcHaPv0s_90/EkGmLyzV7ZoJ

It seems like at least marking the page http://clojure.org/streams near the
top with a message that it is obsolete, and chunked seqs wont out over
streams, would be a good idea for those who come across it.

Andy


On Sun, Aug 31, 2014 at 11:50 AM, Andy Fingerhut 
wrote:

> I have a note in a list of things to do that I have been maintaining that
> says " Remove now-obsolete http://clojure.org/streams
> and any links to it (RH said in 2009 that streams lost to chunked
> sequences)".  I don't have a link handy to that email that suggested this
> change, nor to a quote by Rich Hickey from 2009 saying that streams lost to
> chunked sequences, but they are probably findable via appropriate Google
> searches.
>
> Andy
>
>
> On Fri, Aug 29, 2014 at 11:56 AM, Greg MacDonald 
> wrote:
>
>> Hi Everyone,
>>
>> Does anyone know the status of clojure streams is? I would like to try
>> them out but I can't find the svn repository mentioned on the website:
>> http://clojure.org/streams. Thx!
>>
>> -Greg
>>
>> --
>> 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: clojure streams

2014-08-31 Thread Andy Fingerhut
I have a note in a list of things to do that I have been maintaining that
says " Remove now-obsolete http://clojure.org/streams
and any links to it (RH said in 2009 that streams lost to chunked
sequences)".  I don't have a link handy to that email that suggested this
change, nor to a quote by Rich Hickey from 2009 saying that streams lost to
chunked sequences, but they are probably findable via appropriate Google
searches.

Andy


On Fri, Aug 29, 2014 at 11:56 AM, Greg MacDonald 
wrote:

> Hi Everyone,
>
> Does anyone know the status of clojure streams is? I would like to try
> them out but I can't find the svn repository mentioned on the website:
> http://clojure.org/streams. Thx!
>
> -Greg
>
> --
> 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: How can I add meta to an object that doesn't implement IObj?

2014-08-31 Thread adrian . medina
If you don't want to wrap the object in an atom, you can also reify an 
object that supports IDeref which returns your object. All reified objects 
support IObj out of the box. 

On Sunday, August 31, 2014 4:55:58 AM UTC-4, Atamert Ölçgen wrote:
>
> Hi Francis,
>
>
> On Sat, Aug 30, 2014 at 1:34 PM, Francis Avila  > wrote:
>
>> It would probably help if you said more about the source of this 
>> atom-holding object. Is it a plain Java class? A deftype/defrecord? Is it 
>> final?
>>
>
> It's not an atom-holding object. The only guarantee is that this object 
> extends one (or two) of these protocols: 
> http://clecs.muhuk.com/api/0.2.1/clecs.world.html
>
> Other than that, it can be anything. A Java class, or a type or a record...
>
>  
>
>>
>>
>> If you can control the construction of this object and its class is not 
>> final, you can subclass it and add an IObj implementation. (Note that most, 
>> maybe all clojure ways of creating classes create final classes, so this 
>> technique won't work.) The easiest way to subclass is with `proxy`:
>>
>> (defn meta-AtomHolder [atom-value metadata]
>>   (proxy [AtomHolderClass clojure.lang.IObj] ;; [superclass, new 
>> interfaces]
>>  [atom-value] ;; constructor args
>> (meta [] metadata) ;; subclass method
>> (withMeta [newmeta] (meta-AtomHolder newmeta
>> => (var user/meta-AtomHolder)
>> (meta-AtomHolder (atom "x") {})
>> => #> user.proxy$AtomHolderClass$IObj$40298964@302c28cc>
>> (meta (meta-AtomHolder (atom "x") {}))
>> => {}
>> (meta (with-meta (meta-AtomHolder (atom "x") {}) {:a 1}))
>> => {:a 1}  
>>
>
> This is really cool. So I can do (deref (meta-AtomHolder (atom "x") {})) 
> and it would return "x", right?
>
> I have actually managed to solve it using vars, had to move things around 
> a bit: 
> https://github.com/muhuk/clecs/blob/master/src/clecs/world/check.clj#L73
>
>  
>
>>
>> If the parent class is final or you can't construct the object yourself, 
>> you need to delegate method calls from one instance to this object 
>> instance. I think this is hard-but-not-impossible in java, but I'm not sure.
>>
>> (Clojurescript has `specify`, which does exactly what you want, but only 
>> exists because delegation between instances in javascript is trivial.)
>>
>> On Friday, August 29, 2014 10:16:05 PM UTC-5, Atamert Ölçgen wrote:
>>>
>>> Obviously I can't.
>>>
>>> But I need to add this capability to an object. During testing I attach 
>>> meta to this object that contains an atom. Then I pass this object to other 
>>> functions, known in runtime. I can't use a dynamic var because all this 
>>> happens within a mock function that may be retried and run in different 
>>> threads.
>>>
>>> I have seen this: http://stackoverflow.com/questions/20724219/
>>> simplest-possible-clojure-object-that-can-accept-a-
>>> primitive-and-metadata but can't deref it since I can't change the 
>>> functions that will use it later. If I wrap this object I need to be able 
>>> to delegate all of its functionality to the original object.
>>>
>>> I hope this all is not too vague. The code I'm working on is not online 
>>> yet. But it's for clecs (https://github.com/muhuk/clecs/), I'm adding 
>>> quickcheck to compare different world implementations.
>>>
>>>
>>> -- 
>>> Kind Regards,
>>> Atamert Ölçgen
>>>
>>> -+-
>>> --+
>>> +++
>>>
>>> www.muhuk.com
>>>  
>>  -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Kind Regards,
> Atamert Ölçgen
>
> -+-
> --+
> +++
>
> www.muhuk.com
>  

-- 
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: Macro that modifies the body of a function

2014-08-31 Thread Isaac Zeng

;;; there is a simple, but not a good way
;;; (deftry foo [x] x)
;;; (:arglists (meta #'foo))  => ([& args__5399__auto__])
(defmacro deftry [name & fdecl]
  `(defn ~name [& args#]
 (try
   (apply (fn ~@fdecl) args#)
   (catch Error e#
 (println "err caught" e#)

;;; this is much more better
;;; (deftry foo [x] x)
;;; (:arglists (meta #'foo))  => ([x])
(defn wrap-try [f]
  (fn [& args]
(try
  (apply f args)
  (catch Error e
(println "err caught" e)

(defmacro deftry [& fdecl]
  `(doto
   (defn ~@fdecl)
 (alter-var-root wrap-try)))


On Sunday, August 31, 2014 6:26:12 PM UTC+8, Yehonathan Sharvit wrote:
>
> I tried to write a macro that wraps the code a function with a try/catch 
> statement. It works fine for regular functions but it doesn't work for 
> multimethods.  I understand the reason, but I don't know how to fix it. 
>
> Here is my code:
>
> (defmacro deftry [name args & body] "
> https://groups.google.com/forum/#!topic/clojurescript/To0AnQVC3lg";
>   `(defn ~name ~args
>  (try ~@body
>(catch Error e#
>  (println "error caught:" e#)
>
>
> Usage:
> 1. regular function => it works fine
>
> (deftry foo []
>   (throw (Error. "foo")))
>
>
> 2. multimethods => it breaks
> (deftry foo 
> ([a] 3)
> ([] 5))
>
>  

-- 
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: Macro that modifies the body of a function

2014-08-31 Thread Beau Fabry
> I am impressed that you were able to write a macro without any repl...

Pretty amazed myself. Never seems to happen when it's code that I'm trying 
to write for myself :-)

On Monday, September 1, 2014 12:06:45 AM UTC+10, Yehonathan Sharvit wrote:
>
> Thanks a lot Beau.
>
> Your code almost worked.
>
> This is the working code -- you just forgot the '&' between args and body 
> :)  
> I am impressed that you were able to write a macro without any repl...
>
>
>
> (defmacro deftry [& definition]
>   (if (vector? (second definition))
> (let [[name args & body] definition]
>   `(defn ~name ~args
>  (try ~@body
>(catch Error e#
>  (println "error caught:" e#)
> (let [[name & definitions] definition]
>   `(defn ~name ~@(map (fn [[args & body]] `(~args (try ~@body (catch 
> Error e# (println "err caught" e#)
>   definitions)
>
>
>
>
>
>
>
>
> On Sunday, 31 August 2014 13:56:03 UTC+3, Beau Fabry wrote:
>>
>> This isn't a multimethod, it's a multiple-arity function. Anyway, you 
>> just need to detect that someone has tried to define a multiple arity 
>> method and change your definition accordingly. Something like below. I 
>> haven't actually tried this code so it's almost definitely wrong but you 
>> get the gist.
>>
>> (defmacro deftry [& definition]
>>   (if (vec? (second definition))
>> (let [[name args & body] definition]
>> `(defn ~name ~args
>>(try ~@body
>>  (catch Error e#
>>(println "error caught:" e#)
>> (let [[name & definitions] definition]
>>   `(defn ~name ~@(map (fn [[args body]] `(~args (try ~@body (catch 
>> Error e# (println "err caught")
>>   definitions)
>>
>>
>> On Sunday, August 31, 2014 8:26:12 PM UTC+10, Yehonathan Sharvit wrote:
>>>
>>> I tried to write a macro that wraps the code a function with a try/catch 
>>> statement. It works fine for regular functions but it doesn't work for 
>>> multimethods.  I understand the reason, but I don't know how to fix it. 
>>>
>>> Here is my code:
>>>
>>> (defmacro deftry [name args & body] "
>>> https://groups.google.com/forum/#!topic/clojurescript/To0AnQVC3lg";
>>>   `(defn ~name ~args
>>>  (try ~@body
>>>(catch Error e#
>>>  (println "error caught:" e#)
>>>
>>>
>>> Usage:
>>> 1. regular function => it works fine
>>>
>>> (deftry foo []
>>>   (throw (Error. "foo")))
>>>
>>>
>>> 2. multimethods => it breaks
>>> (deftry foo 
>>> ([a] 3)
>>> ([] 5))
>>>
>>>  

-- 
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: Macro that modifies the body of a function

2014-08-31 Thread Yehonathan Sharvit
Thanks a lot Beau.

Your code almost worked.

This is the working code -- you just forgot the '&' between args and body 
:)  
I am impressed that you were able to write a macro without any repl...



(defmacro deftry [& definition]
  (if (vector? (second definition))
(let [[name args & body] definition]
  `(defn ~name ~args
 (try ~@body
   (catch Error e#
 (println "error caught:" e#)
(let [[name & definitions] definition]
  `(defn ~name ~@(map (fn [[args & body]] `(~args (try ~@body (catch 
Error e# (println "err caught" e#)
  definitions)








On Sunday, 31 August 2014 13:56:03 UTC+3, Beau Fabry wrote:
>
> This isn't a multimethod, it's a multiple-arity function. Anyway, you just 
> need to detect that someone has tried to define a multiple arity method and 
> change your definition accordingly. Something like below. I haven't 
> actually tried this code so it's almost definitely wrong but you get the 
> gist.
>
> (defmacro deftry [& definition]
>   (if (vec? (second definition))
> (let [[name args & body] definition]
> `(defn ~name ~args
>(try ~@body
>  (catch Error e#
>(println "error caught:" e#)
> (let [[name & definitions] definition]
>   `(defn ~name ~@(map (fn [[args body]] `(~args (try ~@body (catch 
> Error e# (println "err caught")
>   definitions)
>
>
> On Sunday, August 31, 2014 8:26:12 PM UTC+10, Yehonathan Sharvit wrote:
>>
>> I tried to write a macro that wraps the code a function with a try/catch 
>> statement. It works fine for regular functions but it doesn't work for 
>> multimethods.  I understand the reason, but I don't know how to fix it. 
>>
>> Here is my code:
>>
>> (defmacro deftry [name args & body] "
>> https://groups.google.com/forum/#!topic/clojurescript/To0AnQVC3lg";
>>   `(defn ~name ~args
>>  (try ~@body
>>(catch Error e#
>>  (println "error caught:" e#)
>>
>>
>> Usage:
>> 1. regular function => it works fine
>>
>> (deftry foo []
>>   (throw (Error. "foo")))
>>
>>
>> 2. multimethods => it breaks
>> (deftry foo 
>> ([a] 3)
>> ([] 5))
>>
>>  

-- 
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: Resources for intermediate/not-absolute-beginner Clojurians

2014-08-31 Thread Vladimir Bokov
Great idea Alex! I'll be waiting for the book

воскресенье, 31 августа 2014 г., 1:58:18 UTC+7 пользователь Alex Miller 
написал:
>
> Hi Sam,
>
> I am working on a book for Pragmatic Programmers with Ben Vandgrift called 
> "Clojure Applied" that is target specifically at people like yourself. Our 
> goal is to bridge the gap between knowing the syntax and basics of the 
> language to knowing how to apply it in building applications. The first 
> half of the book is in tech review now and it will likely be a beta book in 
> October or November with final release in early 2015. 
>
> I would also certainly encourage you to read code and understand the 
> libraries you use (or Clojure itself) at a deeper level! 
>
> Alex
>
> On Friday, August 29, 2014 7:14:36 PM UTC-5, Sam Raker wrote:
>>
>> I worked my way through *Clojure Programming* (Emerick, Carper, & Grand, 
>> O'Reilly), and I've started writing my own Clojure (porting over an 
>> unfinished Python project that seemed amenable to the Clojure treatment.) I 
>> really love the language, but I'm not sure where to go from here. 
>>
>> My other main language is Python, which I learned in school, and also 
>> found a bunch of intermediate/non-introductory resources for, like the 
>> awesome, short, topic-oriented monographs (for lack of a better term) by 
>> Matt Harrison (e.g., 
>> http://www.amazon.com/Guide-Learning-Iteration-Generators-Python-ebook/dp/B007JR4FCQ/ref=sr_1_3).
>>  
>> These really helped me understand some of the less-obvious/less-intro parts 
>> of Python, and the stuff I learned in school helped me learn what idiomatic 
>> Python looked/"felt" like. 
>>
>> I'm just not sure what to do at this point in my Clojure learning 
>> experience. I've probably written a few thousand lines of Clojure at this 
>> point, but I'm not sure that I'm doing things "right:" I don't know if my 
>> code is efficient, or even idiomatic. I've know next to nothing about Java, 
>> and Clojure is my first introduction to functional programming. There are 
>> so many fun, exciting, awesome-seeming things in Clojure that I want to 
>> take advantage of, like reference types and futures, but I have no point of 
>> reference for them and feel like I'm having trouble wrapping my head around 
>> them.
>>
>> I've come to realize that I learn best from books, and while code 
>> literacy is something I need to work on, "read the sourcecode [for library 
>> X]" isn't going to help me that much, unless it's aggressively 
>> commented/documented. I don't really want another intro book, since I'd 
>> rather not pay for too much overlap, and while I'll happily accept 
>> recommendations for application-/domain-specific books, I'm more looking 
>> for a deeper dive into the language itself. 
>>
>> I'm being really difficult about this, and I'm sorry in advance. Any and 
>> all suggestions are welcome. Thanks guys!
>>
>

-- 
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: Macro that modifies the body of a function

2014-08-31 Thread Beau Fabry
This isn't a multimethod, it's a multiple-arity function. Anyway, you just 
need to detect that someone has tried to define a multiple arity method and 
change your definition accordingly. Something like below. I haven't 
actually tried this code so it's almost definitely wrong but you get the 
gist.

(defmacro deftry [& definition]
  (if (vec? (second definition))
(let [[name args & body] definition]
`(defn ~name ~args
   (try ~@body
 (catch Error e#
   (println "error caught:" e#)
(let [[name & definitions] definition]
  `(defn ~name ~@(map (fn [[args body]] `(~args (try ~@body (catch 
Error e# (println "err caught")
  definitions)


On Sunday, August 31, 2014 8:26:12 PM UTC+10, Yehonathan Sharvit wrote:
>
> I tried to write a macro that wraps the code a function with a try/catch 
> statement. It works fine for regular functions but it doesn't work for 
> multimethods.  I understand the reason, but I don't know how to fix it. 
>
> Here is my code:
>
> (defmacro deftry [name args & body] "
> https://groups.google.com/forum/#!topic/clojurescript/To0AnQVC3lg";
>   `(defn ~name ~args
>  (try ~@body
>(catch Error e#
>  (println "error caught:" e#)
>
>
> Usage:
> 1. regular function => it works fine
>
> (deftry foo []
>   (throw (Error. "foo")))
>
>
> 2. multimethods => it breaks
> (deftry foo 
> ([a] 3)
> ([] 5))
>
>  

-- 
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.


Macro that modifies the body of a function

2014-08-31 Thread Yehonathan Sharvit
I tried to write a macro that wraps the code a function with a try/catch
statement. It works fine for regular functions but it doesn't work for
multimethods.  I understand the reason, but I don't know how to fix it.

Here is my code:

(defmacro deftry [name args & body] "
https://groups.google.com/forum/#!topic/clojurescript/To0AnQVC3lg";
  `(defn ~name ~args
 (try ~@body
   (catch Error e#
 (println "error caught:" e#)


Usage:
1. regular function => it works fine

(deftry foo []
  (throw (Error. "foo")))


2. multimethods => it breaks
(deftry foo
([a] 3)
([] 5))

-- 
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 can I add meta to an object that doesn't implement IObj?

2014-08-31 Thread Atamert Ölçgen
Hi Francis,


On Sat, Aug 30, 2014 at 1:34 PM, Francis Avila  wrote:

> It would probably help if you said more about the source of this
> atom-holding object. Is it a plain Java class? A deftype/defrecord? Is it
> final?
>

It's not an atom-holding object. The only guarantee is that this object
extends one (or two) of these protocols:
http://clecs.muhuk.com/api/0.2.1/clecs.world.html

Other than that, it can be anything. A Java class, or a type or a record...



>
>
> If you can control the construction of this object and its class is not
> final, you can subclass it and add an IObj implementation. (Note that most,
> maybe all clojure ways of creating classes create final classes, so this
> technique won't work.) The easiest way to subclass is with `proxy`:
>
> (defn meta-AtomHolder [atom-value metadata]
>   (proxy [AtomHolderClass clojure.lang.IObj] ;; [superclass, new
> interfaces]
>  [atom-value] ;; constructor args
> (meta [] metadata) ;; subclass method
> (withMeta [newmeta] (meta-AtomHolder newmeta
> => (var user/meta-AtomHolder)
> (meta-AtomHolder (atom "x") {})
> => # user.proxy$AtomHolderClass$IObj$40298964@302c28cc>
> (meta (meta-AtomHolder (atom "x") {}))
> => {}
> (meta (with-meta (meta-AtomHolder (atom "x") {}) {:a 1}))
> => {:a 1}
>

This is really cool. So I can do (deref (meta-AtomHolder (atom "x") {}))
and it would return "x", right?

I have actually managed to solve it using vars, had to move things around a
bit:
https://github.com/muhuk/clecs/blob/master/src/clecs/world/check.clj#L73



>
> If the parent class is final or you can't construct the object yourself,
> you need to delegate method calls from one instance to this object
> instance. I think this is hard-but-not-impossible in java, but I'm not sure.
>
> (Clojurescript has `specify`, which does exactly what you want, but only
> exists because delegation between instances in javascript is trivial.)
>
> On Friday, August 29, 2014 10:16:05 PM UTC-5, Atamert Ölçgen wrote:
>>
>> Obviously I can't.
>>
>> But I need to add this capability to an object. During testing I attach
>> meta to this object that contains an atom. Then I pass this object to other
>> functions, known in runtime. I can't use a dynamic var because all this
>> happens within a mock function that may be retried and run in different
>> threads.
>>
>> I have seen this: http://stackoverflow.com/questions/20724219/
>> simplest-possible-clojure-object-that-can-accept-a-primitive-and-metadata
>> but can't deref it since I can't change the functions that will use it
>> later. If I wrap this object I need to be able to delegate all of its
>> functionality to the original object.
>>
>> I hope this all is not too vague. The code I'm working on is not online
>> yet. But it's for clecs (https://github.com/muhuk/clecs/), I'm adding
>> quickcheck to compare different world implementations.
>>
>>
>> --
>> Kind Regards,
>> Atamert Ölçgen
>>
>> -+-
>> --+
>> +++
>>
>> www.muhuk.com
>>
>  --
> 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.
>



-- 
Kind Regards,
Atamert Ölçgen

-+-
--+
+++

www.muhuk.com

-- 
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: Why is this an Exception ?

2014-08-31 Thread Alex Baranosky
There is no pot of gold at the end of the no-namespacing rainbow. Only
sadness. :'(


On Sat, Aug 30, 2014 at 9:29 AM, Andy Fingerhut 
wrote:

> How would another Lisp avoid giving you an error when referring to a
> symbol that has no value?
>
> If you just want your entire program in a single namespace, and don't want
> to use any libraries in other namespaces, then simply don't use the "/"
> character in your symbol names.
>
> If you want to use the symbols in other namespaces without a "namespace/"
> prefix in front of them, you can use a declaration like this:
>
> (ns my.namespace.name
>   (:require [other.namespace :refer :all]
>  [yet.another.namespace :refer :all]))
>
> Then you can use the names of public symbols from other.namespace and
> yet.another.namespace in your code without the namespace prefix.
>
> Andy
>
>
> On Sat, Aug 30, 2014 at 1:02 AM, Sreeharsha Mudivarti <
> msreehar...@gmail.com> wrote:
>
>>
>>
>> On Saturday, August 30, 2014 12:34:24 AM UTC+5:30, Ashton Kemerling wrote:
>>>
>>> Bar/baz refers to the symbol baz in the namespace bar. If you haven't
>>> created and imported bar, that's an error.
>>>
>>>
>> This feels too java-ish for a lisp.
>> Can I avoid this by some form of declaration ?
>>
>>
>>  --
>> 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.
>

-- 
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.