Re: Macros and deftype – usage question

2012-04-29 Thread Baishampayan Ghose
The problem is in embedding an actual function object instead of a
form which creates the function object. That results in a form which
can't be read properly and thus the cryptic error.

Regards,
BG

On Sat, Apr 28, 2012 at 9:13 PM, Shantanu Kumar
kumar.shant...@gmail.com wrote:
 Hi,

 I am running into error when using macros with deftype. For example,
 when I use the macro `foo` it works fine:

 (defmacro foo
  [a]
  (let [b (keyword a)]
    `(do ~b)))

 (foo alex)
 = :b
 whereas, when I use the macro `bar`:

 (defmacro bar
  [a]
  (let [b (keyword a)
        f (fn [ args] b)]
    `(deftype ~a []
       clojure.lang.ILookup
       (valAt [this# k#] (~f this# k#))
       (valAt [this# k# d#] (~f this# k# d#)

 (bar alex)

 I get the following error:
 CompilerException java.lang.ExceptionInInitializerError, compiling:
 (NO_SOURCE_PATH:87)

 Can somebody help me understand what am I doing wrong here.

 Shantanu

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



-- 
Baishampayan Ghose
b.ghose at gmail.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


Re: Any IObj implementation for deftype that doesn't take meta via ctor?

2012-04-29 Thread David Nolen
You need to pass in meta.

David

On Saturday, April 28, 2012, Shantanu Kumar wrote:

 Hi,

 Can somebody point me to an example that implements the IObj interface
 on deftype without needing to pass in meta via constructor? defrecord
 seems to be doing this by storing meta on the tag, but I don't
 completely understand it yet.

 Shantanu

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.comjavascript:;
 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 javascript:;
 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 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

Re: Light Table - a new IDE concept

2012-04-29 Thread Raju Bitter
ArsTechnica mentions Light Table now
http://arstechnica.com/business/news/2012/04/html5-bullets-innovative-clojurescript-ide-css-filter-effects-and-more.ars

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


Re: ClojureScript: can't (:use) protocol in another namespace

2012-04-29 Thread Stuart Campbell
It does. Ticket opened: http://dev.clojure.org/jira/browse/CLJS-216

Cheers,
Stuart

On 28 April 2012 01:30, David Nolen dnolen.li...@gmail.com wrote:

 Does this work in Clojure? If so file a ticket in JIRA.

 David

 On Fri, Apr 27, 2012 at 5:09 AM, Stuart Campbell stu...@harto.org wrote:

 Hello,

 I'm not sure if what I'm doing is supported or whether I'm doing it
 incorrectly.

 I have two ClojureScript namespaces:

 (ns foo)

 (defprotocol SomeProtocol
   (some-function [this]))

 (ns bar
   (:use [foo :only (SomeProtocol)]))

 (defrecord SomeRecord
   SomeProtocol
   (some-function [_] :quux))

 The protocol function is compiled as though SomeProtocol was defined in
 the bar namespace, e.g.:

 bar.SomeType.prototype.bar$SomeProtocol$ = true;
 bar.SomeType.prototype.bar$SomeProtocol$some_function = function(this$) {
   var this__14211 = this;
   return\ufdd0'quux
 };

 This causes an error at runtime.

 Should I be able to do this, or should I stick with (:require foo) and
 foo/SomeProtocol?

 Cheers,
 Stuart

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

LinkedHashMap not well supported

2012-04-29 Thread Kurt Harriger
I am using a groovy library that returns a LinkedHashMap containing ArrayLists 
and nested LinkedHashMaps.  I did not expect any issues working with this in 
clojure since this type implements java.util.Map I figured everything would 
just work. However the first thing I tried to do was apply 
clojure.set/keywordize-keys which didn't keywordize the keys as expected.  I 
then tried map? which returned false, I figured I would then try to convert to 
clojure map using apply hash-map which threw an illegalargumentexception. into 
{} however did work. I then attempted to use clojure.walk/postwalk to convert 
LinkedHashMaps to clojure maps which only visited the top node.  However using 
prewalk did work, so I ended up with the following helper function.  

(defn- convert-types
  [groovy-result]
  (walk/prewalk
   (fn [x]
 (cond (instance? java.util.LinkedHashMap x) (into {} x)
   (instance? java.util.ArrayList x)  (vec x)  ;; probably not required 
but I wanted to pr-str to print as vectors rather than #ArrayList ...
   :else x)) groovy-result))


clojure map? is defined as:
 (fn ^:static map? [x] (instance? clojure.lang.IPersistentMap x)))

Is there any reason map? checks explicitly for clojure.lang.IPersistentMap 
rather than java.util.Map? 

also clojure.walk/walk contains: 
..
  (instance? clojure.lang.IMapEntry form)
..

but (first m) returns java.util.LinkedHashMap$Entry which extends 
java.util.Map$Entry and java.util.HashMap$Entry.

I'm not sure why into {} works but apply hash-map doesn't, seems to have to do 
with first and next don't work on java.util.LinkedHashMap$Entry either.

Seems like many of these functions could be improved to work with java.util.Map 
and  java.util.Map$Entry?  
Should a JIRA be created for these?

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

Re: LinkedHashMap not well supported

2012-04-29 Thread Softaddicts
Obviously, LinkedHashMap is not a Clojure persistent data structure.
map? and alikes tests interfaces specific to Clojure, not Java ones.

Clojure data structures implement java.util.Map and cie to ease interop 
with Java but they are not the same as the persistent interfaces and do not
allow mutations contrary to Java data structures.

There is enough behavior differences (not withstanding the different hosts
running Clojure) to mandate a clean separation between both worlds.

Have a look at this:

http://grokbase.com/t/gg/clojure/11afb4wmb3/recursively-convert-java-map-to-clojure-map

It should get you started :)

Luc


 I am using a groovy library that returns a LinkedHashMap containing 
 ArrayLists and nested LinkedHashMaps.  I did not expect any issues working 
 with this in clojure since this type implements java.util.Map I figured 
 everything would just work. However the first thing I tried to do was apply 
 clojure.set/keywordize-keys which didn't keywordize the keys as expected.  I 
 then tried map? which returned false, I figured I would then try to convert 
 to clojure map using apply hash-map which threw an illegalargumentexception. 
 into {} however did work. I then attempted to use clojure.walk/postwalk to 
 convert LinkedHashMaps to clojure maps which only visited the top node.  
 However using prewalk did work, so I ended up with the following helper 
 function.  
 
 (defn- convert-types
   [groovy-result]
   (walk/prewalk
(fn [x]
  (cond (instance? java.util.LinkedHashMap x) (into {} x)
(instance? java.util.ArrayList x)  (vec x)  ;; probably not 
 required but I wanted to pr-str to print as vectors rather than #ArrayList ...
:else x)) groovy-result))
 
 
 clojure map? is defined as:
  (fn ^:static map? [x] (instance? clojure.lang.IPersistentMap x)))
 
 Is there any reason map? checks explicitly for clojure.lang.IPersistentMap 
 rather than java.util.Map? 
 
 also clojure.walk/walk contains: 
 ..
   (instance? clojure.lang.IMapEntry form)
 ..
 
 but (first m) returns java.util.LinkedHashMap$Entry which extends 
 java.util.Map$Entry and java.util.HashMap$Entry.
 
 I'm not sure why into {} works but apply hash-map doesn't, seems to have to 
 do with first and next don't work on java.util.LinkedHashMap$Entry either.
 
 Seems like many of these functions could be improved to work with 
 java.util.Map and  java.util.Map$Entry?  
 Should a JIRA be created for these?
 
 -- 
 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
--
Softaddictslprefonta...@softaddicts.ca sent by ibisMail!

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


Re: LinkedHashMap not well supported

2012-04-29 Thread kurtharriger
Ill agree that it may be approriate for map? to return false as it does perhaps 
imply a stricter contract then the jvm versions namely immutability.  However, 
I fully expected the return type of keywordize to be a new immutable clojure 
map and it would be extreamly helpful if walk, hash-map, first, next, rest 
supported map$entry. IMHO one of the best things about clojure is that it is 
very easy to interop with jvm libraries without a lot of type conversion and/or 
wrapper types.

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