Re: not= counterintuitive?

2011-09-03 Thread Vijay Lakshminarayanan
ax2groin  writes:

> This code doesn't return the value I intuitively expect:
>
>   user=> (not= 1 2 1)
>   true
>
> When I write that, I was expecting the equivalent of (and (= 1 2) (= 1
> 1)), but the macro expansion is essentially (not (= 1 2 1)).

If you were expecting (not (and (= 1 2) (= 1 1))) then it would match
your expectations.

-- 
Cheers
~vijay

-- 
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: Eval in future ... Bug or feature?

2011-09-02 Thread Vijay Lakshminarayanan
Nils Bertschinger  writes:

> Hi everyone,
>
> it appears that eval works differently when used inside a future. The
> following example REPL session shows what I mean:
>
> user> (clojure-version)
> "1.2.0-master-SNAPSHOT"
> user> (defn my-inc [x] (+ x 1))
> #'user/my-inc
> user> (eval '(my-inc 1))
> 2
> user> (future (eval '(my-inc 1)))
> #
> user> (deref *1)
> java.lang.Exception: Unable to resolve symbol: my-inc in this context
> (NO_SOURCE_FILE:1)
>   [Thrown class java.util.concurrent.ExecutionException]
>
> I found this rather strange. Does anyone know why this happens and
> whether it is actually intended? Is it a bug or a feature ;-).

I don't have any problems...

$ java -jar clojure-1.3.0-alpha8.jar
Clojure 1.3.0-alpha8
user=> (defn my-inc [x] (+ x 1))
#'user/my-inc
user=> (eval '(my-inc 1))
2
user=> (future (eval '(my-inc 1)))
#
user=> (deref *1)
2

> Best,
>
> Nils

-- 
Cheers
~vijay

-- 
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: slime+clojure problem

2008-12-03 Thread Vijay Lakshminarayanan

On Thu, Dec 4, 2008 at 2:33 AM, Dimitre Liotev <[EMAIL PROTECTED]> wrote:
>
> Vijay Lakshminarayanan wrote:
>> If you've got enough time to spare, I'd recommend trying out the
>> clojurebox that was released a few days ago.  I installed it, ensured
>> it worked and then replicated that in my .emacs.
>>
>> Once you have a basic setup working you can easily make the needed
>> changes to run the latest version.
>>
>>
>
> I am not sure if you are replying to me - my clojure setup works, as
> described below.
> I guess Clojurebox is good for people who are not familiar with Emacs.

I'm sorry, I subscribe to the emails so I just replied to the last
thread.  My reply was to Peter Eddy.  I guess when seeing it as a tree
it must seem weird.  I'll be more careful the next time.

Thanks
Vijay

>> On Wed, Dec 3, 2008 at 6:19 PM, Dimitre Liotev <[EMAIL PROTECTED]> wrote:
>>
>>> If you have set "slime-lisp-implementations", make sure the entry for
>>> clojure looks like this:
>>>
>>> (clojure ("clojure") :init swank-clojure-init)
>>>
>>> For example, my slime-lisp-implementations is:
>>>
>>>   (setq slime-lisp-implementations
>>> `(
>>>   (sbcl ("sbcl"))
>>>   (ccl ("ccl"))
>>>   (clojure ("clojure") :init swank-clojure-init)
>>>   (clisp ("clisp"))
>>>   (abcl ("abcl"))
>>>   (cmucl ("lisp"))
>>>   (s48 ("scheme48") :init slime48-init-command)
>>>
>>>
>>>
>>> If I specify (clojure ("clojure")) instead of (clojure (clojure") :init
>>> swank-clojure-init), I get the same error as you.
>>>
>>> --
>>> dl
>>>
>
> --
> Dimitre Liotev
>
> >
>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: fix imports

2008-12-03 Thread Vijay Lakshminarayanan

On Tue, Dec 2, 2008 at 1:53 AM, Stuart Sierra
<[EMAIL PROTECTED]> wrote:
>
> On Nov 28, 7:41 am, lpetit <[EMAIL PROTECTED]> wrote:
>> The "fix import" action could try to resolve an unknown symbol by
>> first searching the symbol in one of the classpath available
>> namespaces, and then search for java classes in the classpath.
>> It could then add an import/require command for each found resolution
>> (and if several resolutions found, ad all, letting the user solve
>> manually the conflict).
>>
>> This could be provided as an IDE action, and also, I think, as a
>> clojure function that could work directly on files.
>
> JDEE  does this, for Java source code.

This is far from complete and should be expanded but I got this from a
few hours of hacking:

(import '(java.util.jar JarFile JarEntry)
'(java.io File IOException))

(defn find-all
  "(for [x coll :when (test-fn item (key-fn x))] x)"
  ([item coll test-fn key-fn]
 (filter #(test-fn item (key-fn %)) coll))
  ([item coll test-fn]
 (find-all item coll test-fn #'identity))
  ([item coll]
 (find-all item coll #'= #'identity)))

(defn find-reg-in-seq
  ([reg coll key]
 (find-all reg coll #'re-find key))
  ([reg coll]
 (find-reg-in-seq reg coll #'identity)))

(defn dir-or-jar->seq
  [path-entity]
  (cond (instance? File path-entity)
(if (.isDirectory #^File path-entity)
  (file-seq path-entity)
  (throw (IOException. "Cannot search within a file.")))
(instance? JarFile path-entity)
(enumeration-seq (.entries #^JarFile path-entity))
true
(throw (UnsupportedOperationException.
(str "Cannot handle " (class path-entity))

(defn find-re-in-path-entity [reg path-entity]
  (find-reg-in-seq reg
   (dir-or-jar->seq path-entity)
   #(.getName %)))

(defn find-class-in-path-entity [class-name path-entity]
  (find-re-in-path-entity (re-pattern (str #"[^A-Za-z0-9$]" class-name
".class$"))
  path-entity))

(def *rt-jar* (.toString
   (File.
(File. (.getProperty System "java.home") "lib") "rt.jar")))

(defn find-java-class-in-classpath [class-name]
  (let [cpath (cons *rt-jar* (.split (.getProperty System "java.class.path")
 (.getProperty System "path.separator")))]
   (mapcat #'identity
   (filter #(not (nil? %))
   (for [#^String path cpath]
 (find-class-in-path-entity class-name
(if (.endsWith path ".jar")
  (JarFile. path)
  (File. path

(defn find-java-class [class-name]
  (map (fn [o] (let [#^String s (.toString #^Object o)
 l (.length s)]
 (.. s (substring 0 (- l 6)) (replace "/" "."
   (find-java-class-in-classpath class-name)))

;;; *eof*

It looks inside all jar files and at all .class files inside
directories in the classpath and rt.jar -- the java runtime library
and returns the list of classes that exist on the classpath.

I haven't written it inside a namespace etc.  It's saved in a file
named "stuff.clj" because I couldnt' think of a good name.

user> (load "stuff")
nil
user> (find-java-class "List")
("com.sun.xml.internal.bind.v2.schemagen.xmlschema.List"
"java.awt.List" "java.util.List")
user> (find-java-class "URL")
("java.net.URL")
user> (find-java-class "NonExistent")
("com.sun.corba.se.impl.protocol.NonExistent")
user> (find-java-class "NonExistentClass")
nil

;; I never expected there'd be a class named "NonExistent" ;-)

The above code is released under public domain so anyone may do what
they wish with it.

Cheers
Vijay

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: slime+clojure problem

2008-12-03 Thread Vijay Lakshminarayanan

If you've got enough time to spare, I'd recommend trying out the
clojurebox that was released a few days ago.  I installed it, ensured
it worked and then replicated that in my .emacs.

Once you have a basic setup working you can easily make the needed
changes to run the latest version.

On Wed, Dec 3, 2008 at 6:19 PM, Dimitre Liotev <[EMAIL PROTECTED]> wrote:
>
> Peter Eddy wrote:
>>> How are you attempting to start slime? Are you doing:
>>>
>>> 1. C-u M-x slime RET clojure RET
>>>
>>> OR
>>>
>>> 2. M-- M-x slime RET clojure RET
>>>
>>
>> Well, either method caused this error for me. I deleted all my slime
>> and clojure-related source trees and re-checked everything out again
>> (taking advantage to organize everything a little better this time
>> around), but same problem.
>>
>> So I backed up my .emacs and then got rid of all configuration for the
>> other lisps I was using (clisp, openmcl and sbcl) and now I can
>> successfully start slime for clojure.
>>
>> I'll eventually re-add the config I removed and try to find what it
>> was that broke clojure/slime.
>>
>> thanks everyone.
>>
>> - Peter
>>
>
>
> If you have set "slime-lisp-implementations", make sure the entry for
> clojure looks like this:
>
> (clojure ("clojure") :init swank-clojure-init)
>
> For example, my slime-lisp-implementations is:
>
>   (setq slime-lisp-implementations
> `(
>   (sbcl ("sbcl"))
>   (ccl ("ccl"))
>   (clojure ("clojure") :init swank-clojure-init)
>   (clisp ("clisp"))
>   (abcl ("abcl"))
>   (cmucl ("lisp"))
>   (s48 ("scheme48") :init slime48-init-command)
>
>
>
> If I specify (clojure ("clojure")) instead of (clojure (clojure") :init
> swank-clojure-init), I get the same error as you.
>
> --
> dl
>
>
> >
>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: try catch syntax

2008-11-28 Thread Vijay Lakshminarayanan
On Fri, Nov 28, 2008 at 8:33 PM, Vincent Foley <[EMAIL PROTECTED]> wrote:
>
> I can agree with the multiple-exceptions-in-one-catch, however I don't
> think the syntax should be so liberal.  It should all be (catch
> [Exception+] e body).

The liberal syntax "feature" was more because I didn't know which
class to use on the other side of instanceof rather than anything
else.  If you look at the earlier patch you'll see that I compare the
sequence of exceptions against java.util.Collection.

I've changed the source to accept only vectors and attached the new
patch.  The new error message on passing some wrong value as sequence
of exceptions is "Expected Exception name or vector of Exception
names, got: " + second.getClass()

I've tried to follow Rich's indentation style but I could've gotten
some things wrong.

My emacs settings remove trailing whitespace so there were some extra
lines in the diff.  I used "svn diff -x -w" to generate the attached
diff.

Cheers
~vijay

> On Nov 28, 1:19 am, "Vijay Lakshminarayanan" <[EMAIL PROTECTED]>
> wrote:
>> Hi
>>
>> I'd like to propose a change to Clojure's current try-catch syntax.
>>
>> Currently the syntax is (copied from clojure.org)
>>
>> (try expr* catch-clause* finally-clause?)
>> catch-clause -> (catch classname name expr*)
>> finally-clause -> (finally expr*)
>>
>> I'd like to propose a change to the catch-clause so that it's possible
>> to specify different classnames one of which will be caught and its
>> expr evaluated.
>>
>> It would be something like
>>
>> (try ...
>>   (catch SomeException e (println e))
>>   (catch (SomeOtherException OrAnotherException) e
>> (println "xyz" e))
>>   (finally ...))
>>
>> In my programming experience I often find that I need to execute the
>> same code for a few different exceptions but specialized code for some
>> others and rather than duplicate code (that's why we use lisp right?
>> no more code duplication!) I thought it would be best that Clojure
>> support the same.
>>
>> I saw that it wasn't possible to modify the try syntax from Clojure
>> itself so I modified the clojure.lang.Compiler file to reflect the
>> same.
>>
>> I produced the diff using "svn diff" so patching the same shouldn't be
>> too hard, I think.
>>
>> With the new syntax Exceptions can be specified in a List, Vector or a
>> Set but not a map.  The exceptions must be specified explicitly as
>> they will not be evaluated.  So
>>
>> (try
>>  (foo)
>>  (catch [InterruptedException MalformedURLException] e (dont (do-what-i-say 
>> e)))
>>  (catch (ArithmeticException NumberFormatException
>> NullPointerException) e (do-what-i-mean e))
>>  (catch #{RuntimeException} e)
>>  (catch Exception e (println e)))
>>
>> are all legal.  But
>>
>> (let [excepts [InterruptedException MalformedURLException]]
>> (try
>>  (foo)
>>  (catch excepts e (println e
>>
>> will throw an IllegalArgumentException.
>>
>> Java7 will probably have syntax similar to the 
>> abovehttp://tech.puredanger.com/java7#catch
>>
>> Cheers
>> Vijay
>>
>>  Compiler.java.diff
>> 7KViewDownload
> >
>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---

Index: src/jvm/clojure/lang/Compiler.java
===
--- src/jvm/clojure/lang/Compiler.java	(revision 1127)
+++ src/jvm/clojure/lang/Compiler.java	(working copy)
@@ -1800,9 +1800,22 @@
 	{
 	if(Util.equal(op, CATCH))
 		{
-		Class c = HostExpr.maybeClass(RT.second(f), false);
-		if(c == null)
-			throw new IllegalArgumentException("Unable to resolve classname: " + RT.second(f));
+  IPersistentVector exceptions = PersistentVector.EMPTY;
+  Object second = RT.second(f);
+
+  if (second instanceof Symbol)
+  {
+  exceptions = exceptions.cons(second);
+  }
+  else if (second instanceof IPersistentVector)
+  {
+

try catch syntax

2008-11-28 Thread Vijay Lakshminarayanan
Hi

I'd like to propose a change to Clojure's current try-catch syntax.

Currently the syntax is (copied from clojure.org)

(try expr* catch-clause* finally-clause?)
catch-clause -> (catch classname name expr*)
finally-clause -> (finally expr*)

I'd like to propose a change to the catch-clause so that it's possible
to specify different classnames one of which will be caught and its
expr evaluated.

It would be something like

(try ...
  (catch SomeException e (println e))
  (catch (SomeOtherException OrAnotherException) e
(println "xyz" e))
  (finally ...))

In my programming experience I often find that I need to execute the
same code for a few different exceptions but specialized code for some
others and rather than duplicate code (that's why we use lisp right?
no more code duplication!) I thought it would be best that Clojure
support the same.

I saw that it wasn't possible to modify the try syntax from Clojure
itself so I modified the clojure.lang.Compiler file to reflect the
same.

I produced the diff using "svn diff" so patching the same shouldn't be
too hard, I think.

With the new syntax Exceptions can be specified in a List, Vector or a
Set but not a map.  The exceptions must be specified explicitly as
they will not be evaluated.  So

(try
 (foo)
 (catch [InterruptedException MalformedURLException] e (dont (do-what-i-say e)))
 (catch (ArithmeticException NumberFormatException
NullPointerException) e (do-what-i-mean e))
 (catch #{RuntimeException} e)
 (catch Exception e (println e)))

are all legal.  But

(let [excepts [InterruptedException MalformedURLException]]
(try
 (foo)
 (catch excepts e (println e

will throw an IllegalArgumentException.

Java7 will probably have syntax similar to the above
http://tech.puredanger.com/java7#catch

Cheers
Vijay

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---

Index: src/jvm/clojure/lang/Compiler.java
===
--- src/jvm/clojure/lang/Compiler.java	(revision 1127)
+++ src/jvm/clojure/lang/Compiler.java	(working copy)
@@ -1800,34 +1800,54 @@
 	{
 	if(Util.equal(op, CATCH))
 		{
-		Class c = HostExpr.maybeClass(RT.second(f), false);
-		if(c == null)
-			throw new IllegalArgumentException("Unable to resolve classname: " + RT.second(f));
-		if(!(RT.third(f) instanceof Symbol))
+  java.util.Collection exceptions = PersistentVector.EMPTY;
+  Object second = RT.second(f);
+
+  if (second instanceof Symbol)
+  {
+  exceptions = ((PersistentVector) exceptions).cons(second);
+  }
+  else if (second instanceof java.util.Collection)
+  {
+  exceptions = (java.util.Collection) second;
+  }
+  else
+  {
+  throw new IllegalArgumentException(
+  "Expected Exception name or sequence of Exception names, got: " + second.getClass());
+  }
+  if(!(RT.third(f) instanceof Symbol))
 			throw new IllegalArgumentException(
 	"Bad binding form, expected symbol, got: " + RT.third(f));
-		Symbol sym = (Symbol) RT.third(f);
-		if(sym.getNamespace() != null)
-			throw new Exception("Can't bind qualified name:" + sym);
+  Symbol sym = (Symbol) RT.third(f);
+  if(sym.getNamespace() != null)
+  throw new Exception("Can't bind qualified name:" + sym);
 
-		IPersistentMap dynamicBindings = RT.map(LOCAL_ENV, LOCAL_ENV.get(),
-		NEXT_LOCAL_NUM, NEXT_LOCAL_NUM.get(),
-		IN_CATCH_FINALLY, RT.T);
-		try
-			{
-			Var.pushThreadBindings(dynamicBindings);
-			LocalBinding lb = registerLocal(sym,
-			(Symbol) (RT.second(f) instanceof Symbol ? RT.second(f)
-			  : null), null);
-			Expr handler = (new BodyExpr.Parser()).parse(context, RT.rest(RT.rest(RT.rest(f;
-			catches = catches.cons(new CatchClause(c, lb, handler));
-			}
-		finally
-			{
-			Var.popThreadBindings();
-			}
-		caught = true;
-		}
+  for (Object exception : exceptions)
+  {
+  Class c = HostExpr.maybeClass(exception, false);