Ctrl-C terminates REPL

2009-04-13 Thread fft1976

Pressing Ctrl-C terminates the REPL and not the evaluation/editing. Is
this the intended behavior?
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Ctrl-C terminates REPL

2009-04-13 Thread Meikel Brandmeyer

Hi,

Am 13.04.2009 um 10:54 schrieb fft1976:


Pressing Ctrl-C terminates the REPL and not the evaluation/editing. Is
this the intended behavior?


http://groups.google.com/group/clojure/browse_frm/thread/32e4f89300456118/1f2c1f1594c51ccf

And:
(require '[clojure.contrib.repl-utils :as repl-utils])
(doc repl-utils/add-break-thread!)

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Tue, Apr 28th AppEngine talk in Atlanta

2009-04-13 Thread Sari Connard
John Hume is scheduled to talk about AppEngine
at
the Atlanta Clojure User Group  on Tue, April 28th at
7pm.
Join us if you can.

-- 
Sari Connard
http://www.linkedin.com/in/sariconnard

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Got a Clojure library?

2009-04-13 Thread Matt Clark

Name: test-expect
URL: http://code.google.com/p/test-expect/
Author: Matt Clark
Tags: testing, mocking, expectations, stubbing
License: EPL
Dependencies: none (optional dependency on test-is)
Description: Supports setting up and validating expectations on mocked
dependency functions.  Informative failure output for easy integration
into any testing environment via functional override.


On Apr 10, 3:07 pm, Tom Faulhaber  wrote:
> Rich,
>
> Since cl-format/pprint has now moved into contrib, we should remove
> the existing cl-format entry and replace it with this:
>
> Name: pprint
> URL :http://code.google.com/p/clojure-contrib/
> Author: Tom Faulhaber
> Tags: pretty printing, formatted output, Common Lisp compatibility
> License: EPL
> Dependencies: none (outside of contrib)
> Description:
>
> Two parts:
>
> 1) A flexible, customizable pretty printer for displaying clojure code
> and data (and potentially other structured data as well).
>
> 2) A fully functional implementation of Common Lisp's crazy powerful
> format function. cl-format provides a way of producing formatted
> output in the "lisp style" in which the format string itself can
> perform destructuring on the the input arguments rather than having
> complex iterations and conditionals in your code to do output.
>
> Thanks!
>
> Tom
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Got a Clojure library?

2009-04-13 Thread mikel

Name: xg-model, xg-gf
URL:  http://code.google.com/p/explorersguild/source/clj/com/explorersguild
   Instructions for checking out code are at:
   http://code.google.com/p/explorersguild/source/checkout
Files: util.clj, gf.clj, model.clj, model_gf.clj
Author: mikel evins
Tags: generic functions, models, dispatch
License: EPL
Dependencies: none
Description: Provides:

  model: an implementation of extensible record types with optional
value constraints on fields

  gf:an implementation of CLOS_style generic functions. gf domains
provide a means of defining dispatch algorithms. Example domains are
provided that implement CLOS-style dispatch over Java classes, and
simple predicate-dispatch. Included is a dispatch domain that
implements multimethod dispatch on XG models.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Has anyone on this group ever tried Forth?

2009-04-13 Thread Victor Rodriguez

On Sat, Apr 11, 2009 at 11:19 PM, fft1976  wrote:
...
>
> I find stack languages to be obtuse. Sometimes Forth programmers need
> variables, and what they do is usually just mutable some global ones.
> Also Forth programmers always have to document what they are doing
> with the stack: what arguments are consumed what results are left,
> i.e. this is a calling convention "by convention". Why not let the
> compiler enforce these rules instead of leaving it up to the comments?

Factor has a library for local variables based on Scheme, no less.
Also, the Factor compiler does at least some checks on stack effects.

Cheers,

Victor Rodriguez.

> Basically, applicative languages (like C) are to Forth, what GC is to
> malloc/free and what STM is to locks: a huge step forward.
>
> I don't know what Factor people are doing. It's Forth with dynamic
> typing, as far as I know.
> >
>

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Amb operator

2009-04-13 Thread David Nolen
Using try-catch for control flow is probably not a good idea. Shameless
plug, do you think you could get this to work with clj-cont? clj-cont is a
port I did of cl-cont. It has some limitations, but because Clojure has so
few special forms (compared to Common Lisp), it has the chance to achieve
pretty good coverage.
I'm trying to get it working with compojure and enlive for web development a
la Seaside and Weblocks- it would be interesting to see what other uses it
might have.

2009/4/10 André Ferreira 

>
> So, I was wondering if anyone had implemented the amb operator in
> Clojure, so I decided to give it a try. This is my first Clojure
> program bigger then 5 lines, the code still needs ALOT of work, it is
> ugly as hell atm, but I think it kind of works. (Yes, I know, it's
> very easy to bug it, its just a sketch). Notice that unlike most
> continuation based amb operators, the amount of backtracking this
> implementation has to do depends on the order of the requires, not the
> amb assignments.
> If anyone wants to clear or improve the code, go ahead.
> I also would like to know how to be able to write @baker instead of
> the current (myderef baker), I tried using a proxy and implementing
> IDeref, but then I couldn't acess the amb-struct private data. Since
> Clojure doesn't have continuations I had to use a try catch block to
> do the stack unwinding, and some redundant calculations might be done
> because of it.
>
> Here is the code:
>
> (defstruct amb-struct :instance :orig :possible)
>
> (def amb-stack nil)
> (defn amb [choices]
>  (struct-map amb-struct :instance false :orig choices  :possible
> choices))
>
> (defn myderef [a]
>  (if (:instance @a)
>(:value @a)
>(do
>  (set! amb-stack (cons a amb-stack))
>  (let
>  [oldpos (:possible @a)]
>(var-set a (assoc @a
> :value (first oldpos)
> :instance true
> :possible (rest oldpos
>  (:value @a
>
> (defn amb-require [condition]
>  (if condition
>nil
>(do
>  (throw (.Exception "nothing")
>
> (defn bindnext []
>  (if (empty? amb-stack)
>'nomatchfound
>(let [lastbind (first amb-stack)
>  oldpos (:possible @lastbind)]
>  (if (empty? oldpos)
>(do
>  (var-set lastbind (assoc @lastbind :instance false :possible
> (:orig
> @lastbind)))
>  (set! amb-stack (rest amb-stack))
>  (recur))
>(do
>  (var-set lastbind (assoc @lastbind :value (first oldpos) :possible
> (rest oldpos)))
>  'recur)
>
>
> (defmacro amb-let [declarations & body]
>  `(with-local-vars
>~declarations
>  (binding [amb-stack nil]
>(loop []
>  (let [retvalue#
>(try
> (do ~...@body)
> (catch Exception ~'except
>   (bindnext)))]
>(cond
>  (= retvalue# 'recur) (recur)
>  true retvalue#))
>
> (defn distinct-seq? [s]
>  (cond
>(empty? (rest s)) true
>(= (first s) (second s)) false
>true (and (distinct-seq? (cons (first s) (rest (rest s
>  (distinct-seq? (rest s)
>
> (amb-let [baker (amb [1 2 3 4 5])
>  cooper (amb [1 2 3 4 5])
>  fletcher (amb [1 2 3 4 5])
>  miller (amb [1 2 3 4 5])
>  smith (amb [1 2 3 4 5])]
>  (amb-require (distinct-seq? (map myderef (list baker cooper fletcher
> miller smith
>  (amb-require (not (= (myderef baker) 5)))
>  (amb-require (not (= (myderef cooper) 1)))
>  (amb-require (not (= (myderef fletcher) 1)))
>  (amb-require (not (= (myderef fletcher) 5)))
>  (amb-require (> (myderef miller) (myderef cooper)))
>  (amb-require (not (= 1 (. java.lang.Math abs (- (myderef smith)
> (myderef fletcher))
>  (amb-require (not (= 1 (. java.lang.Math abs (- (myderef fletcher)
> (myderef cooper))
>  [['baker (myderef baker)]
>   ['cooper (myderef cooper)]
>   ['fletcher (myderef fletcher)]
>   ['miller (myderef miller)]
>   ['smith (myderef smith)]])
>
> Running it returns [[baker 3] [cooper 2] [fletcher 4] [miller 5]
> [smith 1]]
>
> >
>

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Amb operator

2009-04-13 Thread David Nolen
One caveat is that because this works by transforming the code into
Continuation Passing Style, it's dog slow, like 2 orders of magnitude for
regular Clojure code. This is not really much of an issue for user interface
related code (which is what I'm using it for), but unrealistic for pretty
much anything else.
However, with some quick testing I note that using Exceptions for flow
control might be even 2x slower than clj-cont.

On Mon, Apr 13, 2009 at 1:54 PM, David Nolen  wrote:

> Using try-catch for control flow is probably not a good idea. Shameless
> plug, do you think you could get this to work with clj-cont? clj-cont is a
> port I did of cl-cont. It has some limitations, but because Clojure has so
> few special forms (compared to Common Lisp), it has the chance to achieve
> pretty good coverage.
> I'm trying to get it working with compojure and enlive for web development
> a la Seaside and Weblocks- it would be interesting to see what other uses it
> might have.
>
> 2009/4/10 André Ferreira 
>
>
>> So, I was wondering if anyone had implemented the amb operator in
>> Clojure, so I decided to give it a try. This is my first Clojure
>> program bigger then 5 lines, the code still needs ALOT of work, it is
>> ugly as hell atm, but I think it kind of works. (Yes, I know, it's
>> very easy to bug it, its just a sketch). Notice that unlike most
>> continuation based amb operators, the amount of backtracking this
>> implementation has to do depends on the order of the requires, not the
>> amb assignments.
>> If anyone wants to clear or improve the code, go ahead.
>> I also would like to know how to be able to write @baker instead of
>> the current (myderef baker), I tried using a proxy and implementing
>> IDeref, but then I couldn't acess the amb-struct private data. Since
>> Clojure doesn't have continuations I had to use a try catch block to
>> do the stack unwinding, and some redundant calculations might be done
>> because of it.
>>
>> Here is the code:
>>
>> (defstruct amb-struct :instance :orig :possible)
>>
>> (def amb-stack nil)
>> (defn amb [choices]
>>  (struct-map amb-struct :instance false :orig choices  :possible
>> choices))
>>
>> (defn myderef [a]
>>  (if (:instance @a)
>>(:value @a)
>>(do
>>  (set! amb-stack (cons a amb-stack))
>>  (let
>>  [oldpos (:possible @a)]
>>(var-set a (assoc @a
>> :value (first oldpos)
>> :instance true
>> :possible (rest oldpos
>>  (:value @a
>>
>> (defn amb-require [condition]
>>  (if condition
>>nil
>>(do
>>  (throw (.Exception "nothing")
>>
>> (defn bindnext []
>>  (if (empty? amb-stack)
>>'nomatchfound
>>(let [lastbind (first amb-stack)
>>  oldpos (:possible @lastbind)]
>>  (if (empty? oldpos)
>>(do
>>  (var-set lastbind (assoc @lastbind :instance false :possible
>> (:orig
>> @lastbind)))
>>  (set! amb-stack (rest amb-stack))
>>  (recur))
>>(do
>>  (var-set lastbind (assoc @lastbind :value (first oldpos)
>> :possible
>> (rest oldpos)))
>>  'recur)
>>
>>
>> (defmacro amb-let [declarations & body]
>>  `(with-local-vars
>>~declarations
>>  (binding [amb-stack nil]
>>(loop []
>>  (let [retvalue#
>>(try
>> (do ~...@body)
>> (catch Exception ~'except
>>   (bindnext)))]
>>(cond
>>  (= retvalue# 'recur) (recur)
>>  true retvalue#))
>>
>> (defn distinct-seq? [s]
>>  (cond
>>(empty? (rest s)) true
>>(= (first s) (second s)) false
>>true (and (distinct-seq? (cons (first s) (rest (rest s
>>  (distinct-seq? (rest s)
>>
>> (amb-let [baker (amb [1 2 3 4 5])
>>  cooper (amb [1 2 3 4 5])
>>  fletcher (amb [1 2 3 4 5])
>>  miller (amb [1 2 3 4 5])
>>  smith (amb [1 2 3 4 5])]
>>  (amb-require (distinct-seq? (map myderef (list baker cooper fletcher
>> miller smith
>>  (amb-require (not (= (myderef baker) 5)))
>>  (amb-require (not (= (myderef cooper) 1)))
>>  (amb-require (not (= (myderef fletcher) 1)))
>>  (amb-require (not (= (myderef fletcher) 5)))
>>  (amb-require (> (myderef miller) (myderef cooper)))
>>  (amb-require (not (= 1 (. java.lang.Math abs (- (myderef smith)
>> (myderef fletcher))
>>  (amb-require (not (= 1 (. java.lang.Math abs (- (myderef fletcher)
>> (myderef cooper))
>>  [['baker (myderef baker)]
>>   ['cooper (myderef cooper)]
>>   ['fletcher (myderef fletcher)]
>>   ['miller (myderef miller)]
>>   ['smith (myderef smith)]])
>>
>> Running it returns [[baker 3] [cooper 2] [fletcher 4] [miller 5]
>> [smith 1]]
>>
>> >>
>>
>

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

Updated clojure-pom with AOT compile

2009-04-13 Thread dysinger

I updated my maven setup to include clojure-maven-plugin & AOT
compiles now. -> Example hello world project in the README.

http://github.com/dysinger/clojure-pom/tree/master

PS - Compojure is now maven ready ->
http://github.com/dysinger/compojure/tree/master

PSS - Compojure POM & hello world example is next.

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: How to compile in AquaMacs without slime? classpath problem for classes

2009-04-13 Thread dysinger

Bill,

I switch between projects with slime using this method ->
http://github.com/dysinger/clojure-pom/tree/master which sets up slime
with _ALL_ the right jars / paths for each project using the
generated ./bin/ repl script with SLIME.

-Tim

On Apr 12, 5:25 pm, billh04  wrote:
> I can compile in NetBeans with enclojure and I can compile in AquaMacs
> with slime. However, I prefer to use AquaMacs without slime. But, I
> cannot compile my application using the (compile 'my.namespace.main)
> invocation. The classes are generated except for "main__init.class" (I
> believe).
>
> I can force it to comile correctly by using the following before I
> invoke (compile 'my.namespace.main) command:
>
> 
> (import 'java.io.File)
> (import 'java.net.URLClassLoader)
> (import 'java.net.URL)
> (import 'java.lang.ClassLoader)
>
> (defn classpath-add [path]
>   (let [url (cond (string? path) (.toURL (new java.io.File path))
>                   (instance? java.io.File path) (.toURL path)
>                   :else path)
>         addURL (.getDeclaredMethod (identity java.net.URLClassLoader)
>                                    "addURL"
>                                    (into-array [java.net.URL]))]
>     (.setAccessible addURL true) ; scared yet?
>     (.invoke addURL (ClassLoader/getSystemClassLoader) (to-array
> [url]
>
> (classpath-add "classes")
> 
>
> Thus, I believe the problem is due to "classes" not being in the
> classpath.
>
> I have looked around and I have seen recommendations to add the
> classpath for "classes" to my Aquamacs preference file, but I don't
> like that if I would be working on several projects in different
> directories.
>
> Is there an easy way for AquaMacs to pick up the directory for
> "classes" (which is in the same directory as my program "main.clj")
> when I invoke the "compile" command from Aquamacs?
>
> Thanks for any suggestions.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Has anyone on this group ever tried Forth?

2009-04-13 Thread Mark Fredrickson

Previous to my discovering Clojure, I wrote a small Scheme library to
embed concatenative programming inside a Lisp:

http://www.call-with-current-continuation.org/eggs/3/stacktor.html

I ultimately found that I didn't use it much when I was writing real
programs, but it was a good way to learn about concatenative
programming without having to leave an environment that I was familiar
with. I would say that the (-> ...) macro (and some basic permutations
to it) in Clojure handle 90% of what I would have used Stacktor for.
At the same time, I do like the cut-n-paste ability of writing new
"words" from messing around in the REPL. Lisps are close to as easy,
but not quite as straight forward.

Enjoy,
-Mark


On Fri, Apr 10, 2009 at 2:13 AM, CuppoJava  wrote:
>
> Hi everyone,
> I was browsing through webpages and the language Forth caught my eye.
> Reading through it's supposed advantages it sounded very interesting,
> and I was wondering if anyone here has any experience with it, and can
> comment.
>
> I'm asking on the Clojure forum instead of the Forth forum because I
> agree with the programming values that Clojure emphasizes, and would
> like to hear opinions from people with similar values to myself.
>
> I'm most interested in it's productivity aspect. (ie. how quick can I
> get real work done)
>
> Thanks for your opinions
>  -Patrick
> >
>

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Got a Clojure user group?

2009-04-13 Thread Jason Riedy

And Rich Hickey writes:
> Got a Clojure user group, meetup etc?

After a fashion.  There is a (low-traffic) Clojure group on identi.ca
for chatting:
  http://identi.ca/group/clj

Jason

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



clojure.contrib.repl-utils/get-source broken

2009-04-13 Thread James Reeves

Hi folks,

In the latest versions of Clojure, the :file key in a var's metadata
seems to contain the full path of the file (relative to the
classpath). e.g.

=> (:file ^#'html)
"compojure/html/gen.clj"
=> (:file ^#'map)
"clojure/core.clj"

The get-source function in clojure.contrib.repl-utils seems to assume
that :file only contains the base filename, rather than the full
filepath. This means that the path is added twice. e.g.

compojure/html/compojure/html/gen.clj

- James


--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



in-ns in bootstrap

2009-04-13 Thread Greg Harman

I have a bootstrap file (executed either on the command line or via
user.clj) that contains an in-ns call, along with other stuff that I
have verified working (e.g. println statements).

I'd like the bootstrap file to leave the REPL in whatever namespace I
last specified with my in-ns. But I'm getting different (unexpected)
results in two cases.

Case 1: Slime: the in-ns is ignored (although expressions around it
are evaluated), and my repl is in the user ns.
Case 2: Command-line (java ... clojure.main -i ./bootstrap.clj -r) the
repl prints user->, but is actually in the correct namespace (I can
execute functions defined in that namespace directly, without
explicitly in-ns from the repl command line).

Any ideas how to get the repl to "start" in a different NS than user
and why I'm seeing different behavior in my two cases?

thanks,
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
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: Amb operator

2009-04-13 Thread Victor Rodriguez

On Mon, Apr 13, 2009 at 2:13 PM, David Nolen  wrote:
> One caveat is that because this works by transforming the code into
> Continuation Passing Style, it's dog slow, like 2 orders of magnitude for
> regular Clojure code. This is not really much of an issue for user interface
> related code (which is what I'm using it for), but unrealistic for pretty
> much anything else.
> However, with some quick testing I note that using Exceptions for flow
> control might be even 2x slower than clj-cont.

Although I have never verified this myself, reputedly it is
constructing exceptions what is slow, not throwing or catching them.

In other words, for the amb implementation above, it might be worth
defining a "constant" exception and throwing that.  (Although I'm
confused, I see in the code (.Exception "something"), shouldn't that
be (Exception. "something") instead?)

Cheers,

Victor Rodrigeuz.

> On Mon, Apr 13, 2009 at 1:54 PM, David Nolen  wrote:
>>
>> Using try-catch for control flow is probably not a good idea. Shameless
>> plug, do you think you could get this to work with clj-cont? clj-cont is a
>> port I did of cl-cont. It has some limitations, but because Clojure has so
>> few special forms (compared to Common Lisp), it has the chance to achieve
>> pretty good coverage.
>> I'm trying to get it working with compojure and enlive for web development
>> a la Seaside and Weblocks- it would be interesting to see what other uses it
>> might have.
>>
>> 2009/4/10 André Ferreira 
>>>
>>> So, I was wondering if anyone had implemented the amb operator in
>>> Clojure, so I decided to give it a try. This is my first Clojure
>>> program bigger then 5 lines, the code still needs ALOT of work, it is
>>> ugly as hell atm, but I think it kind of works. (Yes, I know, it's
>>> very easy to bug it, its just a sketch). Notice that unlike most
>>> continuation based amb operators, the amount of backtracking this
>>> implementation has to do depends on the order of the requires, not the
>>> amb assignments.
>>> If anyone wants to clear or improve the code, go ahead.
>>> I also would like to know how to be able to write @baker instead of
>>> the current (myderef baker), I tried using a proxy and implementing
>>> IDeref, but then I couldn't acess the amb-struct private data. Since
>>> Clojure doesn't have continuations I had to use a try catch block to
>>> do the stack unwinding, and some redundant calculations might be done
>>> because of it.
>>>
>>> Here is the code:
>>>
>>> (defstruct amb-struct :instance :orig :possible)
>>>
>>> (def amb-stack nil)
>>> (defn amb [choices]
>>>  (struct-map amb-struct :instance false :orig choices  :possible
>>> choices))
>>>
>>> (defn myderef [a]
>>>  (if (:instance @a)
>>>    (:value @a)
>>>    (do
>>>      (set! amb-stack (cons a amb-stack))
>>>      (let
>>>          [oldpos (:possible @a)]
>>>        (var-set a (assoc @a
>>>                         :value (first oldpos)
>>>                         :instance true
>>>                         :possible (rest oldpos
>>>      (:value @a
>>>
>>> (defn amb-require [condition]
>>>  (if condition
>>>    nil
>>>    (do
>>>      (throw (.Exception "nothing")
>>>
>>> (defn bindnext []
>>>  (if (empty? amb-stack)
>>>    'nomatchfound
>>>    (let [lastbind (first amb-stack)
>>>          oldpos (:possible @lastbind)]
>>>      (if (empty? oldpos)
>>>        (do
>>>          (var-set lastbind (assoc @lastbind :instance false :possible
>>> (:orig
>>> @lastbind)))
>>>          (set! amb-stack (rest amb-stack))
>>>          (recur))
>>>        (do
>>>          (var-set lastbind (assoc @lastbind :value (first oldpos)
>>> :possible
>>> (rest oldpos)))
>>>          'recur)
>>>
>>>
>>> (defmacro amb-let [declarations & body]
>>>  `(with-local-vars
>>>        ~declarations
>>>      (binding [amb-stack nil]
>>>        (loop []
>>>          (let [retvalue#
>>>                (try
>>>                 (do ~...@body)
>>>                 (catch Exception ~'except
>>>                   (bindnext)))]
>>>            (cond
>>>              (= retvalue# 'recur) (recur)
>>>              true retvalue#))
>>>
>>> (defn distinct-seq? [s]
>>>  (cond
>>>    (empty? (rest s)) true
>>>    (= (first s) (second s)) false
>>>    true (and (distinct-seq? (cons (first s) (rest (rest s
>>>              (distinct-seq? (rest s)
>>>
>>> (amb-let [baker (amb [1 2 3 4 5])
>>>          cooper (amb [1 2 3 4 5])
>>>          fletcher (amb [1 2 3 4 5])
>>>          miller (amb [1 2 3 4 5])
>>>          smith (amb [1 2 3 4 5])]
>>>  (amb-require (distinct-seq? (map myderef (list baker cooper fletcher
>>> miller smith
>>>  (amb-require (not (= (myderef baker) 5)))
>>>  (amb-require (not (= (myderef cooper) 1)))
>>>  (amb-require (not (= (myderef fletcher) 1)))
>>>  (amb-require (not (= (myderef fletcher) 5)))
>>>  (amb-require (> (myderef miller) (myderef cooper)))
>>>  (amb-require (not (= 1 (. java.lang.Math abs (- (myderef smith)
>>> (myderef fletcher))
>>>  (amb

Re: update-in wildcards?

2009-04-13 Thread Ozzi Lee

Well, I expected someone to tell my that was a horrible idea, not to
implement it for me. Thanks!

One thing that concerns me is that :* could conceivable be used as a
key in a hash-map. Perhaps a separate distinct value should be used as
a wildcard? Does clojure have a facility for creating a value that
will never be considered equal to any other value?
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update-in wildcards?

2009-04-13 Thread Ozzi Lee

> Does clojure have a facility for creating a value that
> will never be considered equal to any other value?

Duh, brainfart. Gensym will work nicely, of course.
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: in-ns in bootstrap

2009-04-13 Thread Stephen C. Gilardi


On Apr 13, 2009, at 3:44 PM, Greg Harman wrote:


I'd like the bootstrap file to leave the REPL in whatever namespace I
last specified with my in-ns. But I'm getting different (unexpected)
results in two cases.

Case 1: Slime: the in-ns is ignored (although expressions around it
are evaluated), and my repl is in the user ns.
Case 2: Command-line (java ... clojure.main -i ./bootstrap.clj -r) the
repl prints user->, but is actually in the correct namespace (I can
execute functions defined in that namespace directly, without
explicitly in-ns from the repl command line).

Any ideas how to get the repl to "start" in a different NS than user
and why I'm seeing different behavior in my two cases?


The "-e" and "-i" initialization arguments to clojure.main run after  
the repl has entered the user namespace. In Clojure, every "load"  
saves and restores the current namespaces around the load, so only a "- 
e" argument can affect the initial namespace for a repl.


This should do what you're after:

% java -cp clojure.jar clojure.main -e "(in-ns 'funky-ns)" --repl
#
funky-ns=>

Regarding your Case 2 where it appeared you were actually in a  
namespace other than the one shown in the prompt, that's very  
unlikely. *ns* is the "one" true place (in a given thread at a given  
time) where the current namespace is stored. Could it be some code you  
loaded "referred" to or "used" the non-user namespace thereby bringing  
its names into user?


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: clojure dependency management and build

2009-04-13 Thread bradford cross
I have written up my journeys so far:
http://bradfordcross.blogspot.com/2009/04/clojure-build-and-dependency-management.html

I re-used Meikel's ant + ivy successfully.   Next step is to get something
working for the transative deps , i.e. pulling other clojure projects i
depend on and building them and getting the resulting jars and transitive
deps on the classpath.  Rigth now I jsut pack it all up into jars at the top
level lib dir and add that to my swank-extra-classpaths.

I have had some good discussions with Meikel Brandmeyer and Phil Hagelberg
and things seem to be coming along nicely.

I'd like to get things working with ant + ivy xml and so I understand all
the issues and then start building out Lancet or something similar so we can
script in clojure rather than xml. :-)

On Sat, Apr 11, 2009 at 7:06 AM, Meikel Brandmeyer  wrote:

> Hi Bradford,
>
> Am 08.04.2009 um 21:31 schrieb Bradford Cross:
>
>  I heard some chatter yesterday on #clojure about using Ivy with Clojure.
>>
>
> Yes. I'm working on marrying Clojure and Ivy. So far with, IMHO,
> great success. I set up a little ivy repo with clojure and contrib.
> The clojure module has the following configurations:
>
> - default => AOT compiled clojure jar
> - dev => the previous + a source jar
> - slim => Java source compiled, clojure sources as is
>
> The contrib module has (roughly) one configuration per unit, ie.
> def, pprint, stacktrace, with the following exceptions:
>
> - I grouped together the scattered math stuff into a math configuration.
> - generic and types depend on each other so their combined into
>  the generic configuration.
>
> Similar to clojure a source configuration is included, which adds
> a source jar to the dependencies
>
> This allows very fine-grained control of what is needed. So if you want
> only def, you only download a 13k not 2.5M.
>
> To use this setup, you only have to specify the dependencies in
> your ivy.xml and ivysettings.xml files. Here an example:
>
> ivysettings.xml:
> 
>
>http://kotka.de/ivy/ivysettings.xml"/>
> 
>
> The first line sucks in the default configuration, the second tells
> Ivy how to resolve the clojure and contrib dependencies.
>
> ivy.xml:
> 
>... 
>
>
> conf="default"/>
> conf="default->def"/>
>
> 
>
> Now you only have to integrate Ivy with your build system. It can
> be done very easily with ant, but may also be used standalone,
> eg. with make.
>
> Here you can see an example how I integrated Ivy with my lazymap project.
>
>http://bitbucket.org/kotarak/lazymap/src/
>
> It is avalaible via the kotka.de ivysettings as
>
>
>
> I can't speak for SLIME, but VimClojure can be simply started with the
> resolved jars from lib directory in the classpath.
>
>  -I download lots of little projects things from github and i want to munge
>> them all together for my app. This means I need to build jars (some with
>> ant, otehrs with maven, etc.)  and in other cases I want to depend directly
>> on the .clj files using clojures namespace-to-dir-structure conventions.  So
>> there are a couple different ways to build of the classpath - one for .clj
>> and one for .jar.
>>
>
> I'm not sure, that Ivy can help in the general case, where you have to
> build
> the dependencies. I think it only downloads the files and makes them
> available.
> In particular it doesn't seem to handle subdirectories. So vanilla clj
> might not
> work.
>
>  -Many projects also have their own lib foler - with both jars and cljs, so
>> I need to pick those deps up transatively.
>>
>
> This is a breeze with Ivy. It must say, that this just works beautifully.
> The
> dependencies either work with Ivy or with Maven and are resolved
> transitively.
> You can also mirror dependencies locally, to make sure they don't go away.
>
>  -The work in the Clojure community is proceeding very fast, so I'd like
>> updating all the projects from git to be automated as well.
>>
>
> This could be easily done with Ivy. Check out the dependencies you need.
> Add an ivy.xml and a custom build script for ant. Then you can create a
> master build.xml, which iterates through all dependencies in the right
> order
> to pull changes, rebuild and publish into your local repository.
>
> I actually haven't set up production version of such a structure but I
> tried
> around and it worked without problems. The Ivy documentation has some
> tutorial on this.
>
>  So what is a good solution to these problems?  Perhaps it would be cool to
>> build some git/maven/lancet aware infrastructure to do this refreshing of
>> deps, building the deps, and building up the classpath.  It may also be good
>> to configure .emacs to be able to load projects and rebuild the classpath
>> dynamically based on lancet build files - much in the way that intelliJ or
>> eclipse load projects from ant .builds or maven poms.
>>
>
> I'm not sure for bigger setups, but for my current needs Ivy Just Works. So
> I think it's certainly worth a lo

Re: clojure dependency management and build

2009-04-13 Thread Stephen C. Gilardi

On Apr 13, 2009, at 4:58 PM, bradford cross wrote:

I have written up my journeys so far: 
http://bradfordcross.blogspot.com/2009/04/clojure-build-and-dependency-management.html


Thanks very much for the write-up!

Given the recent discussions and interest in dependency management I  
thought I'd mention an idea in that area that I think is a good one.


At ILC '09, Francois-Rene Rideau made a presentation about "xcvb":

http://common-lisp.net/project/xcvb/

which is intended to be a successor to Common Lisp's ASDF with some  
nice features.


One of the issues it addresses is the possibly problematic behavior of  
a "same world" compiler as we have in Clojure AOT: build dependencies  
which are intended to be explicit and correct can be incorrect, but  
accidentally work.


Here's an example:

A depends on B and C
E depends on A, B, and D, but only declares A and D

Compile A
Compile E

works

Now change A so it no longer depends on B.

	Now compiling E "breaks". (And in the general case, the guy who made  
the change to A knows nothing about E.)


In xcvb, the strategy they use to avoid that and make sure all  
dependencies are correctly specified is to make the compilation of  
each file start with the compiler's "image" in a known, minimal state.  
They break the build into a dependency discovery phase and a make-like  
minimal rebuild phase (which may actually use "make" itself) to  
accomplish this. The tradeoff in overall "system" compilation time is  
the reloading of compiled code every time it's needed rather than just  
once.


For us, the corresponding strategy would be that the compilation of  
each namespace should start with only clojure.core loaded.


We could adopt this strategy in a given Clojure build system without  
any changes to how Clojure works (by launching a new instance of  
Clojure for each compilation) which makes it particularly easy to  
experiment with.


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: clojure dependency management and build

2009-04-13 Thread bradford cross
On Mon, Apr 13, 2009 at 2:31 PM, Stephen C. Gilardi wrote:

> On Apr 13, 2009, at 4:58 PM, bradford cross wrote:
>>
>> I have written up my journeys so far:
>> http://bradfordcross.blogspot.com/2009/04/clojure-build-and-dependency-management.html
>>
>
> Thanks very much for the write-up!
>
> Given the recent discussions and interest in dependency management I
> thought I'd mention an idea in that area that I think is a good one.
>
> At ILC '09, Francois-Rene Rideau made a presentation about "xcvb":
>
> http://common-lisp.net/project/xcvb/
>
> which is intended to be a successor to Common Lisp's ASDF with some nice
> features.
>
> One of the issues it addresses is the possibly problematic behavior of a
> "same world" compiler as we have in Clojure AOT: build dependencies which
> are intended to be explicit and correct can be incorrect, but accidentally
> work.
>
> Here's an example:
>
>A depends on B and C
>E depends on A, B, and D, but only declares A and D
>
>Compile A
>Compile E
>
>works
>
>Now change A so it no longer depends on B.
>
>Now compiling E "breaks". (And in the general case, the guy who made
> the change to A knows nothing about E.)


Yes, I have had nasty issues with this in the past.  IMO, explicitly
declaring deps and not relying on transitive resolution is the only way to
go.



>
>
> In xcvb, the strategy they use to avoid that and make sure all dependencies
> are correctly specified is to make the compilation of each file start with
> the compiler's "image" in a known, minimal state. They break the build into
> a dependency discovery phase and a make-like minimal rebuild phase (which
> may actually use "make" itself) to accomplish this. The tradeoff in overall
> "system" compilation time is the reloading of compiled code every time it's
> needed rather than just once.
>
> For us, the corresponding strategy would be that the compilation of each
> namespace should start with only clojure.core loaded.
>
> We could adopt this strategy in a given Clojure build system without any
> changes to how Clojure works (by launching a new instance of Clojure for
> each compilation) which makes it particularly easy to experiment with.


I believe we can achieve this via ant and ivy but i am not sure if they can
force explicit deps.  I'm not sure if a separate closure process is
required, I have seen static analysis tools that can do the graph traversal
and warn you about transitive dependency resolutions (or unused
dependencies.)


>
>
> --Steve
>
>

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure dependency management and build

2009-04-13 Thread Laurent PETIT
Hi,

2009/4/14 bradford cross 

>
>
> On Mon, Apr 13, 2009 at 2:31 PM, Stephen C. Gilardi wrote:
>
>>  On Apr 13, 2009, at 4:58 PM, bradford cross wrote:
>>>
>>> I have written up my journeys so far:
>>> http://bradfordcross.blogspot.com/2009/04/clojure-build-and-dependency-management.html
>>>
>>
>> Thanks very much for the write-up!
>>
>> Given the recent discussions and interest in dependency management I
>> thought I'd mention an idea in that area that I think is a good one.
>>
>> At ILC '09, Francois-Rene Rideau made a presentation about "xcvb":
>>
>> http://common-lisp.net/project/xcvb/
>>
>> which is intended to be a successor to Common Lisp's ASDF with some nice
>> features.
>>
>> One of the issues it addresses is the possibly problematic behavior of a
>> "same world" compiler as we have in Clojure AOT: build dependencies which
>> are intended to be explicit and correct can be incorrect, but accidentally
>> work.
>>
>> Here's an example:
>>
>>A depends on B and C
>>E depends on A, B, and D, but only declares A and D
>>
>>Compile A
>>Compile E
>>
>>works
>>
>>Now change A so it no longer depends on B.
>>
>>Now compiling E "breaks". (And in the general case, the guy who
>> made the change to A knows nothing about E.)
>
>
> Yes, I have had nasty issues with this in the past.  IMO, explicitly
> declaring deps and not relying on transitive resolution is the only way to
> go.
>

I don't understand, the example given by Stuart does not rely on any
transitive resolution mechanism, but rather plain explicit dependency
declaration. So I think that transitive resolution is not the problem here.
The problem is that the compilation of A had a side effect left that the
compilation of E benefited from.

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure dependency management and build

2009-04-13 Thread bradford cross
On Mon, Apr 13, 2009 at 3:22 PM, Laurent PETIT wrote:

> Hi,
>
> 2009/4/14 bradford cross 
>
>>
>>
>> On Mon, Apr 13, 2009 at 2:31 PM, Stephen C. Gilardi wrote:
>>
>>>  On Apr 13, 2009, at 4:58 PM, bradford cross wrote:

 I have written up my journeys so far:
 http://bradfordcross.blogspot.com/2009/04/clojure-build-and-dependency-management.html

>>>
>>> Thanks very much for the write-up!
>>>
>>> Given the recent discussions and interest in dependency management I
>>> thought I'd mention an idea in that area that I think is a good one.
>>>
>>> At ILC '09, Francois-Rene Rideau made a presentation about "xcvb":
>>>
>>> http://common-lisp.net/project/xcvb/
>>>
>>> which is intended to be a successor to Common Lisp's ASDF with some nice
>>> features.
>>>
>>> One of the issues it addresses is the possibly problematic behavior of a
>>> "same world" compiler as we have in Clojure AOT: build dependencies which
>>> are intended to be explicit and correct can be incorrect, but accidentally
>>> work.
>>>
>>> Here's an example:
>>>
>>>A depends on B and C
>>>E depends on A, B, and D, but only declares A and D
>>>
>>>Compile A
>>>Compile E
>>>
>>>works
>>>
>>>Now change A so it no longer depends on B.
>>>
>>>Now compiling E "breaks". (And in the general case, the guy who
>>> made the change to A knows nothing about E.)
>>
>>
>> Yes, I have had nasty issues with this in the past.  IMO, explicitly
>> declaring deps and not relying on transitive resolution is the only way to
>> go.
>>
>
> I don't understand, the example given by Stuart does not rely on any
> transitive resolution mechanism, but rather plain explicit dependency
> declaration. So I think that transitive resolution is not the problem here.
> The problem is that the compilation of A had a side effect left that the
> compilation of E benefited from.
>

Right, let me restate it a different way.

The goal is to enforce explicit deps so that you cannot rely on side effects
that transitively resolve a dependency.

My point is there are a couple ways to deal with this:

1) each unit (project or whatever you want to call it) builds in a different
process
2) static analysis or dynamic analysis is injected into the build pipeline
and causes failure (or gives warnings) if you are relying on a transitive
resolution.



>
>
>
>
> >
>

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



What is the difference between :type and :tag metadata?

2009-04-13 Thread samppi

In this message (http://groups.google.com/group/clojure/msg/
d88d9319adfc41a6), Mr. Hickey mentioned a "supported convention for
tagging, the :type metadata". I thought that this was the function of
the :tag metadata, though, which isa? and the hierarchy functions use.
What is the difference? Do their functions overlap, or do they serve
completely different purposes? Or has :tag been remained to :type?


--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure dependency management and build

2009-04-13 Thread dysinger

On Apr 13, 10:58 am, bradford cross 
wrote:
> I have written up my journeys so 
> far:http://bradfordcross.blogspot.com/2009/04/clojure-build-and-dependenc...

Nice article.

> I re-used Meikel's ant + ivy successfully.   Next step is to get something
> working for the transative deps , i.e. pulling other clojure projects i
> depend on and building them and getting the resulting jars and transitive
> deps on the classpath.  Rigth now I jsut pack it all up into jars at the top
> level lib dir and add that to my swank-extra-classpaths.

Maven already has this above solved plus multi-module projects.  I
currently build a half dozen interdependent clojure libs / apps with
one top level "mvn install" command.  The emacs classpath is solved on
a per-module basis too with a custom repl generated for each module.

> I have had some good discussions with Meikel Brandmeyer and Phil Hagelberg
> and things seem to be coming along nicely.
>
> I'd like to get things working with ant + ivy xml and so I understand all
> the issues and then start building out Lancet or something similar so we can
> script in clojure rather than xml. :-)

Me too - but for now I chose not to shave yaks and accept a little XML
(one file) in my modules.  I agree that it'll be awesome to have ivy/
maven power in simple DRY clojure files.

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Amb operator

2009-04-13 Thread David Nolen
Wow, this is very interesting, on a MBP 2.53 JDK 1.6
;; ~2.5 seconds
(time (dotimes [_ 100]
(new Exception)))

;; ~40ms or 62X faster
(time
 (let [exc (new Exception)]
   (dotimes [_ 100]
 (try
  (throw exc)
  (catch Exception _)

However does also means that you're throwing away the away stack trace
making debugging more difficult? It got me thinking about arbitrary flow
control, on the nested loop thread I've added my findings...

On Mon, Apr 13, 2009 at 4:24 PM, Victor Rodriguez  wrote:

>
> On Mon, Apr 13, 2009 at 2:13 PM, David Nolen 
> wrote:
> > One caveat is that because this works by transforming the code into
> > Continuation Passing Style, it's dog slow, like 2 orders of magnitude for
> > regular Clojure code. This is not really much of an issue for user
> interface
> > related code (which is what I'm using it for), but unrealistic for pretty
> > much anything else.
> > However, with some quick testing I note that using Exceptions for flow
> > control might be even 2x slower than clj-cont.
>
> Although I have never verified this myself, reputedly it is
> constructing exceptions what is slow, not throwing or catching them.
>
> In other words, for the amb implementation above, it might be worth
> defining a "constant" exception and throwing that.  (Although I'm
> confused, I see in the code (.Exception "something"), shouldn't that
> be (Exception. "something") instead?)
>
> Cheers,
>
> Victor Rodrigeuz.
>
> > On Mon, Apr 13, 2009 at 1:54 PM, David Nolen 
> wrote:
> >>
> >> Using try-catch for control flow is probably not a good idea. Shameless
> >> plug, do you think you could get this to work with clj-cont? clj-cont is
> a
> >> port I did of cl-cont. It has some limitations, but because Clojure has
> so
> >> few special forms (compared to Common Lisp), it has the chance to
> achieve
> >> pretty good coverage.
> >> I'm trying to get it working with compojure and enlive for web
> development
> >> a la Seaside and Weblocks- it would be interesting to see what other
> uses it
> >> might have.
> >>
> >> 2009/4/10 André Ferreira 
> >>>
> >>> So, I was wondering if anyone had implemented the amb operator in
> >>> Clojure, so I decided to give it a try. This is my first Clojure
> >>> program bigger then 5 lines, the code still needs ALOT of work, it is
> >>> ugly as hell atm, but I think it kind of works. (Yes, I know, it's
> >>> very easy to bug it, its just a sketch). Notice that unlike most
> >>> continuation based amb operators, the amount of backtracking this
> >>> implementation has to do depends on the order of the requires, not the
> >>> amb assignments.
> >>> If anyone wants to clear or improve the code, go ahead.
> >>> I also would like to know how to be able to write @baker instead of
> >>> the current (myderef baker), I tried using a proxy and implementing
> >>> IDeref, but then I couldn't acess the amb-struct private data. Since
> >>> Clojure doesn't have continuations I had to use a try catch block to
> >>> do the stack unwinding, and some redundant calculations might be done
> >>> because of it.
> >>>
> >>> Here is the code:
> >>>
> >>> (defstruct amb-struct :instance :orig :possible)
> >>>
> >>> (def amb-stack nil)
> >>> (defn amb [choices]
> >>>  (struct-map amb-struct :instance false :orig choices  :possible
> >>> choices))
> >>>
> >>> (defn myderef [a]
> >>>  (if (:instance @a)
> >>>(:value @a)
> >>>(do
> >>>  (set! amb-stack (cons a amb-stack))
> >>>  (let
> >>>  [oldpos (:possible @a)]
> >>>(var-set a (assoc @a
> >>> :value (first oldpos)
> >>> :instance true
> >>> :possible (rest oldpos
> >>>  (:value @a
> >>>
> >>> (defn amb-require [condition]
> >>>  (if condition
> >>>nil
> >>>(do
> >>>  (throw (.Exception "nothing")
> >>>
> >>> (defn bindnext []
> >>>  (if (empty? amb-stack)
> >>>'nomatchfound
> >>>(let [lastbind (first amb-stack)
> >>>  oldpos (:possible @lastbind)]
> >>>  (if (empty? oldpos)
> >>>(do
> >>>  (var-set lastbind (assoc @lastbind :instance false :possible
> >>> (:orig
> >>> @lastbind)))
> >>>  (set! amb-stack (rest amb-stack))
> >>>  (recur))
> >>>(do
> >>>  (var-set lastbind (assoc @lastbind :value (first oldpos)
> >>> :possible
> >>> (rest oldpos)))
> >>>  'recur)
> >>>
> >>>
> >>> (defmacro amb-let [declarations & body]
> >>>  `(with-local-vars
> >>>~declarations
> >>>  (binding [amb-stack nil]
> >>>(loop []
> >>>  (let [retvalue#
> >>>(try
> >>> (do ~...@body)
> >>> (catch Exception ~'except
> >>>   (bindnext)))]
> >>>(cond
> >>>  (= retvalue# 'recur) (recur)
> >>>  true retvalue#))
> >>>
> >>> (defn distinct-seq? [s]
> >>>  (cond
> >>>(empty? (rest s)) true
> >>>(= (first s) (second s)) fals

Re: Nested loops

2009-04-13 Thread David Nolen
Out of simple curiosity I wondered how hard it would be to implement flow
control using proxy. I know Rich isn't hot on non-structured programming,
but there may be times where this might be useful:
(ns flow.return-from
  (:import (flow IReturnFrom)))

(defn create-return-from
  [value]
  (proxy [Throwable IReturnFrom] []
(value [& args] value)))

(defmacro allow-return-from [form]
  `(try
~form
(catch ~'clojure.proxy.java.lang.Throwable$IReturnFrom e#
  (.value e#

(defmacro return [value]
  `(throw (create-return-from ~value)))

(defn my-loop [count]
  (dotimes [x count]
(if (= x 5)
  (return x

;; examples

(allow-return-from (my-loop 10)) ; -> 5

(dotimes [x 5]
  (allow-return-from
   (dotimes [y 5]
 (if (= y 2)
   (return y)
   (println x y)

In order for the above to work you'll need to compile an interface:

;; compile with the following
;; (binding [*compile-path* "/path/to/classes"]
;;   (compile 'flow.return-from-interface))

(ns flow.return-from-interface)

(gen-interface
 :nameflow.IReturnFrom
 :methods [[value [] Object]])

Pretty cool.

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: What is the difference between :type and :tag metadata?

2009-04-13 Thread Rich Hickey



On Apr 13, 6:36 pm, samppi  wrote:
> In this message (http://groups.google.com/group/clojure/msg/
> d88d9319adfc41a6), Mr. Hickey mentioned a "supported convention for
> tagging, the :type metadata". I thought that this was the function of
> the :tag metadata, though, which isa? and the hierarchy functions use.
> What is the difference? Do their functions overlap, or do they serve
> completely different purposes? Or has :tag been remained to :type?

:tag is applied to source forms to communicate type hints to the
compiler. :type can be used, by convention, to add 'type names' to
runtime data structures that support metadata. The type function will
return the :type metadata if present, else the class, making it a
handy dispatch function. Neither :tag nor :type are used directly by
isa?

Rich
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Google includes Clojure in App Engine demo

2009-04-13 Thread levand

http://googleappengine.blogspot.com/2009/04/many-languages-and-in-runtime-bind-them.html

As a demo of JVM languages running on the Google App Engine, they
included a Clojure REPL.

Getting more mainstream, it would seem...
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: test-expect functional mocking/expectation library

2009-04-13 Thread Allen Rohner

>Of course, it was not until I had an early working version that I discovered 
>Allen
> Rohner's expectation tools, but I figured that mine were sufficiently
> different to merit further development (at least relative to the
> latest code of his I could find).
>
>
> Suggestions for further changes or improvements are more than
> welcome.  If people find this library useful I'd be more than happy to
> sign the CA and put this in contrib. Also, Allen, if you are
> interested in merging our efforts let me know.  Is your latest code
> available?
>
> -Matt

I like your code better. I didn't really want to write an expectation
library, I wanted to use an expectation library.

My code was never under serious development. I solved the problem
enough to scratch my itch, and posted the results. What you found is
the latest version of my code, but I don't see anything useful in
there to contribute. I'll start using your library, and if I have any
patches I'll send them your way.

-Allen

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Amb operator

2009-04-13 Thread Victor Rodriguez

On Mon, Apr 13, 2009 at 9:02 PM, David Nolen  wrote:
> Wow, this is very interesting, on a MBP 2.53 JDK 1.6
> ;; ~2.5 seconds
> (time (dotimes [_ 100]
> (new Exception)))
> ;; ~40ms or 62X faster
> (time
>  (let [exc (new Exception)]
>    (dotimes [_ 100]
>      (try
>       (throw exc)
>       (catch Exception _)
> However does also means that you're throwing away the away stack trace
> making debugging more difficult? It got me thinking about arbitrary flow

If you want to throw an exception for flow control, then you shouldn't
care about the stack trace.  You can even have a mutable exception
(and thus probably a bad idea) to "pop" values up the stack.

Regards,

Victor.

> control, on the nested loop thread I've added my findings...
> On Mon, Apr 13, 2009 at 4:24 PM, Victor Rodriguez  wrote:
>>
>> On Mon, Apr 13, 2009 at 2:13 PM, David Nolen 
>> wrote:
>> > One caveat is that because this works by transforming the code into
>> > Continuation Passing Style, it's dog slow, like 2 orders of magnitude
>> > for
>> > regular Clojure code. This is not really much of an issue for user
>> > interface
>> > related code (which is what I'm using it for), but unrealistic for
>> > pretty
>> > much anything else.
>> > However, with some quick testing I note that using Exceptions for flow
>> > control might be even 2x slower than clj-cont.
>>
>> Although I have never verified this myself, reputedly it is
>> constructing exceptions what is slow, not throwing or catching them.
>>
>> In other words, for the amb implementation above, it might be worth
>> defining a "constant" exception and throwing that.  (Although I'm
>> confused, I see in the code (.Exception "something"), shouldn't that
>> be (Exception. "something") instead?)
>>
>> Cheers,
>>
>> Victor Rodrigeuz.
>>
>> > On Mon, Apr 13, 2009 at 1:54 PM, David Nolen 
>> > wrote:
>> >>
>> >> Using try-catch for control flow is probably not a good idea. Shameless
>> >> plug, do you think you could get this to work with clj-cont? clj-cont
>> >> is a
>> >> port I did of cl-cont. It has some limitations, but because Clojure has
>> >> so
>> >> few special forms (compared to Common Lisp), it has the chance to
>> >> achieve
>> >> pretty good coverage.
>> >> I'm trying to get it working with compojure and enlive for web
>> >> development
>> >> a la Seaside and Weblocks- it would be interesting to see what other
>> >> uses it
>> >> might have.
>> >>
>> >> 2009/4/10 André Ferreira 
>> >>>
>> >>> So, I was wondering if anyone had implemented the amb operator in
>> >>> Clojure, so I decided to give it a try. This is my first Clojure
>> >>> program bigger then 5 lines, the code still needs ALOT of work, it is
>> >>> ugly as hell atm, but I think it kind of works. (Yes, I know, it's
>> >>> very easy to bug it, its just a sketch). Notice that unlike most
>> >>> continuation based amb operators, the amount of backtracking this
>> >>> implementation has to do depends on the order of the requires, not the
>> >>> amb assignments.
>> >>> If anyone wants to clear or improve the code, go ahead.
>> >>> I also would like to know how to be able to write @baker instead of
>> >>> the current (myderef baker), I tried using a proxy and implementing
>> >>> IDeref, but then I couldn't acess the amb-struct private data. Since
>> >>> Clojure doesn't have continuations I had to use a try catch block to
>> >>> do the stack unwinding, and some redundant calculations might be done
>> >>> because of it.
>> >>>
>> >>> Here is the code:
>> >>>
>> >>> (defstruct amb-struct :instance :orig :possible)
>> >>>
>> >>> (def amb-stack nil)
>> >>> (defn amb [choices]
>> >>>  (struct-map amb-struct :instance false :orig choices  :possible
>> >>> choices))
>> >>>
>> >>> (defn myderef [a]
>> >>>  (if (:instance @a)
>> >>>    (:value @a)
>> >>>    (do
>> >>>      (set! amb-stack (cons a amb-stack))
>> >>>      (let
>> >>>          [oldpos (:possible @a)]
>> >>>        (var-set a (assoc @a
>> >>>                         :value (first oldpos)
>> >>>                         :instance true
>> >>>                         :possible (rest oldpos
>> >>>      (:value @a
>> >>>
>> >>> (defn amb-require [condition]
>> >>>  (if condition
>> >>>    nil
>> >>>    (do
>> >>>      (throw (.Exception "nothing")
>> >>>
>> >>> (defn bindnext []
>> >>>  (if (empty? amb-stack)
>> >>>    'nomatchfound
>> >>>    (let [lastbind (first amb-stack)
>> >>>          oldpos (:possible @lastbind)]
>> >>>      (if (empty? oldpos)
>> >>>        (do
>> >>>          (var-set lastbind (assoc @lastbind :instance false :possible
>> >>> (:orig
>> >>> @lastbind)))
>> >>>          (set! amb-stack (rest amb-stack))
>> >>>          (recur))
>> >>>        (do
>> >>>          (var-set lastbind (assoc @lastbind :value (first oldpos)
>> >>> :possible
>> >>> (rest oldpos)))
>> >>>          'recur)
>> >>>
>> >>>
>> >>> (defmacro amb-let [declarations & body]
>> >>>  `(with-local-vars
>> >>>        ~declarations
>> >>>      (binding [amb-stac

Re: in-ns in bootstrap

2009-04-13 Thread Greg Harman

On Apr 13, 4:50 pm, "Stephen C. Gilardi"  wrote:
> % java -cp clojure.jar clojure.main -e "(in-ns 'funky-ns)" --repl
> #
> funky-ns=>

Worked perfectly, thanks!

> Regarding your Case 2 where it appeared you were actually in a  
> namespace other than the one shown in the prompt, that's very  
> unlikely. *ns* is the "one" true place (in a given thread at a given  
> time) where the current namespace is stored. Could it be some code you  
> loaded "referred" to or "used" the non-user namespace thereby bringing  
> its names into user?

Yeah, that's it - I did have a "use"... sorry, should have caught that
one myself!

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



ATTN contrib authors: Automatic documentation for clojure.contib

2009-04-13 Thread Tom Faulhaber

[This is specifically for contrib authors, but also for anyone whose
interested.]

There was some discussion (or maybe the wailing and gnashing of teeth)
about the fact that there's lots of cool functionally coming into
clojure.contrib but no easily accessible documentation. I had been
thinking about this already and figured maybe I'd set up the framework
for fixing it.

My idea is to use the namespace and var metadata to auto-generate a
set of documentation that has:
- an overview page that lists the namespaces in contrib and presents a
summary of each derived from the namespace metadata.
- each entry on the namespace overview page will have a link to an API
page for that namespace. That page will be basically like the API page
on clojure.org.
- probably should have an index page as well, but I haven't thought
about it much.
- an ability to link from a namespace to a custom created piece of
documentation (like the nice DatalogOverview that Jeffery wrote).

I've written the code that builds (a first cut of) this stuff from the
namespaces. It uses the following metadata:

On the namespace:
- :author to supply a string with the author(s) name(s)
- :wiki-doc to supply a wiki specific doc string (that can include
wiki markup) or, if that doesn't exist, we fall back to
- :doc the default doc string

On the vars, I use:
:wiki-doc and :doc, as above
:macro - to indicate if it's a macro
:arglists to grab the arglist

The last two are set automatically by defn and defmacro.

AUTHORS PLEASE NOTE: In order for this to be useful these fields need
to be filled in for your contributions. The system will work without
it, just not as nicely.

The next stage of my plan is to build a robot that watches the
subversion repository and updates the doc on every checkin. Therefore
the doc will typically correspond to the tip of the tree.

To avoid thinking too hard, I'm planning to use the wiki on
clojure.contrib's googlecode page because (a) there's almost nothing
on it now and (b) it's easy to use subversion to update stuff there.
Whether this is the right place long-term is another question that we
can worry about once it's running.

Does all of this seem like the right direction? Comments? Suggestions?

Tom
--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Javascript generator

2009-04-13 Thread David Nolen
Do you have any plans for continuing to support this? If so are you against
putting this on GitHub or Google Code so that people can follow it's
development?
Thanks for contributing it to the community.

On Wed, Feb 25, 2009 at 7:49 PM, jim  wrote:

>
> I've just uploaded a javascript generator ala Parenscript.  It's
> pretty half-baked, so be cautious using it until we get the bugs
> ironed out.
>
> http://clojure.googlegroups.com/web/js_gen.clj
>
> The code for the generator is about 250 lines.  It depends on the mini-
> kanren implementation I just uploaded.  The file also includes a bunch
> of unit tests of the various functions.  At the bottom, there are some
> examples of javascript functions being generated.
>
> Bug reports very much appreciated.
>
> Jim
> >
>

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Javascript generator

2009-04-13 Thread David Nolen
One thing, there are several assertions in js-gen like the following:
(assert (= '("obj = {prop2:\"str-val\",prop1:3}")
   (run out-str
(js-assignment '(= obj {prop1 3, prop2 "str-val"}) out-str

This assertion statement might fail (and did for me) since maps are not
ordered.

On Tue, Apr 14, 2009 at 1:19 AM, David Nolen  wrote:

> Do you have any plans for continuing to support this? If so are you against
> putting this on GitHub or Google Code so that people can follow it's
> development?
> Thanks for contributing it to the community.
>
> On Wed, Feb 25, 2009 at 7:49 PM, jim  wrote:
>
>>
>> I've just uploaded a javascript generator ala Parenscript.  It's
>> pretty half-baked, so be cautious using it until we get the bugs
>> ironed out.
>>
>> http://clojure.googlegroups.com/web/js_gen.clj
>>
>> The code for the generator is about 250 lines.  It depends on the mini-
>> kanren implementation I just uploaded.  The file also includes a bunch
>> of unit tests of the various functions.  At the bottom, there are some
>> examples of javascript functions being generated.
>>
>> Bug reports very much appreciated.
>>
>> Jim
>> >>
>>
>

--~--~-~--~~~---~--~~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---