Re: Namespaces and distinctness

2008-11-19 Thread mb

Hi,

On 19 Nov., 09:47, Simon Brooke [EMAIL PROTECTED] wrote:
 Java has a simple and neat convention for achieving global namespace
 distinctness without the overhead of a central registry - you just
 reverse your domain name and append a bit. Is there a similar
 convention for Clojure namespaces?

Yes. This is the convention for Clojure. com.example.mylib.

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Alioth binary-tree benchmark

2008-11-18 Thread mb

Hi,

blindly copying code is usually not a good way to learn a new
language

I don't know, whether this is more idiomatic Clojure code, but
it works...

(defn build-tree
  [item depth]
  (when ( 0 depth)
(let [i (* 2 item)
  d (dec depth)]
  [item (build-tree (dec i) d) (build-tree i d)])))

(defn check-node
  [z]
  (if z
(+ (z 0) (check-node (z 1)) (- (check-node (z 2
0))

(defn iterate-trees
  [mx mn d]
  (let [iterations (bit-shift-left 1 (+ mx mn (- d)))]
(println (* 2 iterations) \ttrees of depth d \tcheck:
 (reduce + (map (fn [i]
  (+ (check-node (build-tree i d))
 (check-node (build-tree (- i) d
(range 1 (inc iterations)))

(defn main
  [max-depth]
  (let [min-depth 4
str-depth (inc max-depth)]
(let [tree (build-tree 0 str-depth)
  x(check-node tree)]
  (println stretch tree of depth str-depth \tcheck: x))
(let [long-lived-tree (build-tree 0 max-depth)]
  (doseq d (range min-depth str-depth 2)
(iterate-trees max-depth min-depth d))
  (println long lived tree of depth max-depth \tcheck:
   (check-node long-lived-tree)

 Armed Bear
         Interpreted     232.54
         Compiled                 35.3
 CMUCL
         Interpreted     600.15
         Compiled                  6.13
 Clojure                  57.131432

 These are not formal benchmark tests; each test is of one run, not
 averaged over several, and is performed on my development machine
 which has many other processes running.

user= (time (main 16))
stretch tree of depth 17check: -1
131072  trees of depth 4check: -131072
32768   trees of depth 6check: -32768
8192trees of depth 8check: -8192
2048trees of depth 10   check: -2048
512 trees of depth 12   check: -512
128 trees of depth 14   check: -128
32  trees of depth 16   check: -32
long lived tree of depth 16 check: -1
Elapsed time: 24222.279088 msecs
nil

That is 24.2 seconds on my crappy 1.7 GHz Office machine.

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: clojure.contrib.test-is changes

2008-11-18 Thread mb

Hello Stuart,

On 18 Nov., 15:58, Stuart Sierra [EMAIL PROTECTED] wrote:
 1. I want to keep optional messages per-assertion.  These are very
 useful in the RSpec testing framework for Ruby; they're like comments
 explaining what each assertion is supposed to demonstrate.

I'd also like to see the messages included. I'm working on a TAP
implementation for Clojure, which I find nice for communicating test
results to external processes. In TAP also the messages are used
as some kind of documentation.

This leads me to another question: Is it possible to look into
pluggable
harnesses? That is: can we separate the tests from the result
reporting?
In my TAP implementation I currently have two harnesses, one
produces TAP output, one can be used inside a test to allow recursive
tests. One application is for example the ClojureCheck library I am
working on.

(holds?
  (for-all [x Integer
y Integer]
(is (= (+ x y) (+ y x
  addition commutes)

for-all sets up a batch-harness, so the body of the for-all may
contain
any number or form of tests. The result of the for-all, is then the
result
of the internal tests.

 2. The current 'is' macro works more or less like the one Meikel
 described.  The multimethod is assert-expr, but it's complicated and
 could be simplified.

My sketch was rather minimalistic. I will post a more complete
example with working code later on today.

Sincerely
Meikel

--~--~-~--~~~---~--~~
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: Running Clojure scripts at the command line

2008-11-17 Thread mb

Hi,

On 17 Nov., 09:07, Michael Wood [EMAIL PROTECTED] wrote:
 #!/usr/bin/env java -cp /sq/ext/clojure/clojure.jar clojure.lang.Script

Most systems only allow one argument to the command.
scsh solved this issue with the special \ argument and
block comment #! ... !#

#! /usr/bin/scsh \
-m ore -o ptions -g o -h ere
!#

So when encountering a \ in the command-line options,
scsh reads the second line and parses it as additional
commandline args.

However, this leads to the usual problems with #! scripts:
hardcoded path, env hack doesn't work and the interpreter
(/usr/bin/scsh in this case) must not be a script itself!

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Strange behaviour

2008-11-17 Thread mb

Hi,

On 17 Nov., 13:05, Konrad Hinsen [EMAIL PROTECTED] wrote:
         (defn replace-syms
            [sym-map expr]
            (let [replace #(replace-syms sym-map %)]
               (cond (contains? sym-map expr) (get sym-map expr)
                     (list? expr) (map #(replace-syms sym-map %) expr)
                     (vector? expr) (into [] (map replace expr))
                     (map? expr) (into {} (map replace (seq expr)))
                     (set? expr) (set (map replace expr))
                     true expr)))

vals returns a clojure.lang.APersistentMap$ValSeq, which
is not a list. Hence list? returns false and you get the true
branch, ie. the thing itself.

I tried the following approach, which also doesn't work, because
clojure.lang.PersistentHashMap$LeafNode does not return
something of a similar type or a vector when called with empty,
but a list. Hence the following doesn't work for maps. Note
also the annoying special case for the list...

(defn replace-syms
  [sym-map expr]
  (cond
(contains? sym-map expr) (sym-map expr)
(list? expr) (map #(replace-syms sym-map %) expr)
(coll? expr) (into (empty expr)
   (map #(replace-syms sym-map %)
expr))
:elseexpr))

I know. It doesn't help much, but it shows, that you have to take
care to distinguish the abstraction vs. the specific implementation.

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Eager map?

2008-11-17 Thread mb

Hi,

On 18 Nov., 03:01, Adam Jones [EMAIL PROTECTED] wrote:
 I'm in the middle of writing some code to extract sql results, which
 means I'm doing a *lot* of forcing right now. It's almost enough for
 me to wish there was a convention (and provided definitions) for
 denoting lazy/strict versions of functions. (e.g. (map f ...) is a
 lazy seq, (map! f ...) is strict)

For what it's worth: I use the following convention.

- For code which is purely done for side-effects, I use doseq. eg.
(doseq [x some-seq] (println x))

- In case I want to have the seq in memory, or there are side-effects
  and I need the actual results, I use doall.
(doall (map some-f some-seq))

On the other hand: you can simply create your own map!.
  (def map! (comp doall map))

Just my 0.02€.

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: recur in catch and finally?

2008-11-16 Thread mb

Hi,

On 17 Nov., 02:09, Chouser [EMAIL PROTECTED] wrote:
 You could of course work around this by putting your loop in some
 other function and calling it from inside catch.

In this specific case I used:
(last (take-while #(not (nil? %)) (iterate #(.getCause %) e)))

However, a separate function would also work. That is not
the point. One can work around it. But I try to follow the
principle of least surprise as much as possible. So when
valid looking code doesn't work for an obscure reason, this
certainly is a surprise.

I have no problem putting the loop into a dedicated function.
Or find some equivalent way to express it. However then it
should be documented somewhere, that this is actually
necessary. (for technical reasons loop/recur cannot be
used in/at/for)

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Clojure for LISP programmers....

2008-11-16 Thread mb

Hi Simon,

there is a detailed explanation of syntax, data
structures etc. as well as a complete reference
at the Clojure site[1].

Then there's a wiki[2] with a lot of information of
setting Clojure up with different editors like emacs
or vim and a lot of examples. Also explaining
some of the quirks like missing TCO due to the
underlying JVM.

Rich held a talk at the Boston Lisp Group. So
when you have a Lisp background you might
certainly be interested in this, since the audience
was also quite familiar with Lisp. The talk was
recorded and is available at blip.tv[3]. There
are also other talks, eg. Rich's concurrency talk
with the famous ant simulation, which might
be interesting. Google probably knows where
to get those.

For live experience there is the #clojure channel
on freenode. The people there are alway helpful.
So in case you have a problem, you can get
real-time help from them. Rich is also quite
active there. So feedback reaches the right
people.

And finally (as you already did) you might post
your questions here on the list.

Hope this helps to get going with Clojure. :)

Sincerely
Meikel

[1]: http://clojure.org
[2]: http://en.wikibooks.org/wiki/Clojure_Programming
[3]: http://blip.tv/file/1313398


--~--~-~--~~~---~--~~
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: let accepting a vector

2008-11-13 Thread mb

Hi,

On 13 Nov., 07:27, Larrytheliquid [EMAIL PROTECTED] wrote:
 Is there a way to pass a vector to a function like let, rather than manually
 typing in the brackets?

let is not a function, but a special form (see: 
http://clojure.org/special_forms).
It is only possible via eval to achieve the desired effect.

(def *bvec* '[x 1 y 2])

(eval
  `(let ~*bvec*
 (+ ~'x ~'y)))

And this is almost surely not what you want to do. eval is a strong
code
smell, if not stench.

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: a question about ns

2008-11-10 Thread mb

Hi,

On 10 Nov., 12:48, Chanwoo Yoo [EMAIL PROTECTED] wrote:
 (ns test
   (-:import import org.apache.http.HttpVersion; import
 org.apache.http.http.client.HttpClient))

ns is itself a macro, which treats the :import, :use, :require and
:refer-clojure clauses specially. Since it does not evaluated the
clauses, and hence doesn't expand the -:import macro, it sees
the -:import literally. You will have to stick with -import and
use it after the ns.

(ns test)
(-import import org.apache.http.HttpVersion; import
org.apache.http.http.client.HttpClient))

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: About testing private functions

2008-11-10 Thread mb

Hi,

simply change to the namespace in question:

in classpath/foo/foo.clj:
---8---
(ns foo)

(defn- private-foo-func
  [x y]
  (+ x y))
---8---

in test-foo.clj:
---8---
; Make sure foo namespace is loaded
; correctly before we go on.
(require 'foo)

(in-ns 'foo)

; Make sure, we don't interfere with
; foo's vars.
(require '[clojure.contrib.test-is :as test])

(test/deftest test-private-foo-func
  (test/is (= (private-foo-func 1 2) 3)))

(test/run-tests)
---8---

In Clojure:
---8---
user= (require 'foo)
nil
user= (foo/private-foo-func 1 2)
java.lang.IllegalStateException: var: #=(var foo/private-foo-func) is
not public (NO_SOURCE_FILE:2)
user= (load-file test-foo.clj)
Testing #Namespace: foo

Ran 1 tests with 1 assertions.
0 failures, 0 exceptions.
nil
user=
---8---

I don't know whether this is the recommended way of doing things,
but it works

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: A trivial question about type and class

2008-11-06 Thread mb

Hi,

On 6 Nov., 13:30, Chanwoo Yoo [EMAIL PROTECTED] wrote:
  Is {:a 1} not a hash-map? It seems that there is some inconsistency...

Clojure holds promises about the interface and the performance
characteristics of the provided functions. In general Clojure is
a lot about abstract interfaces. The underlying thing may change
as necessary to provide the best implementation for the specific
case.

An array map may be good for maps with a very small number of
entries, but inappropriate for maps with a big number of entries.
Since Clojure only promises the interface, it's free to decide
that assoc should now return a converted map for performance
reasons.

At least this is the impression I got from Rich's talk at - I think -
the Boston Lisp Group. I think he mentioned something like this.
Please correct me if I'm wrong.

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Having struggle in understanding FP (and Clojure question)

2008-11-05 Thread mb

Hi,

On 5 Nov., 08:31, Konrad Hinsen [EMAIL PROTECTED] wrote:
 That's exactly my point. Multimethods may well be sufficient or even  
 superior for implementing OO concepts useful in Clojure. We will see  
 when someone actually uses them this way (or has it already  
 happened?). But as long as the most important interfaces (sequences,  
 maps, numbers), which happen to be the ones also used by the built-in  
 types, don't use the same mechanism, there will always be first-class  
 and second-class citizens in Clojure's datatype universe.

I don't think that there are first-class and second-class citizens.
They
just have a different aspect. Having pure Clojure classes with
multimethods might well be integrated and nice, but you get problems
when you have to interface to Java. On the other hand using Java
classes gives you easy interface, but you have to live with gen-class.
So which one is first, which one second class? I think each solution
has just different Pros and Cons.

What would interesting, is the question, whether both approaches
could be combined. We make a Java class (via gen-class), which
gets a default implementation for each method, which references
a similar named multimethod instead of the Class-methodName.
Clojure classes deriving from that class do not provide an
a Java method themselves, but register with the multimethod.
The Clojure code could use the multimethods, while there are still
the methods available for a Java interface. So the downside would
be that one can only inherit from one such prototype class (since
it needs to be a class, not an interface, for the default
implementation
of the methods) or one has to respecify the method - multimethod
translation in all sub classes. Maybe a modified gen-class could
support?

(These are just random thoughts. Maybe they make sense, maybe
not.)

For the built-in datatypes: I implemented nth and get as multimethods
(as some kind of proof-of-concept), but Rich was not very interested
due to performance issues and the fact, that the datatypes are used
internally in very low-level areas. I don't really follow the argument
about monkey patching. I think it's not monkey patching at all, since
the multimethods only define the interface. So I don't modify a thing
which is returned by hash-map. That's still a hash map using the
hash-map implementation.

- http://clojure-log.n01se.net/date/2008-10-06.html#13:18

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Having struggle in understanding FP (and Clojure question)

2008-11-05 Thread mb

Hi,

On 5 Nov., 15:40, Konrad Hinsen [EMAIL PROTECTED] wrote:
 But does gen-class have to look the way it does? Couldn't the same  
 functionality be provided in a way that looks more like a proper part  
 of the language?

I'm not sure about the form itself. I had look at a CLOS tutorial
and that defclass doesn't look to different in the form the function
is called, a mix of keywords and arguments.

My main concern with gen-class is that it doesn't use the namespace
itself. I posted a patch[1] yesterday which addresses the namespace
and -/_ translation. I rose this also some weeks ago on the list but
there was no response. So the general interest seems to be pretty
low. On the other hand Rich, seems to have something like this on
his TODO list[2]. But maybe everything is different again because
of AOT. So I'm not sure, what his plans are for gen-class right now.

[1]: 
http://groups.google.com/group/clojure/browse_thread/thread/386d90a8b757aee4
[2]: http://richhickey.backpackit.com/pub/1597914

 The current implementation of nth provides a special implementation  
 for each kind of datatype that it knows about, and fails for unknown  
 types. Shouldn't it be possible to add a default case at the end that  
 calls a Clojure multimethod? That shouldn't have any performance  
 impact on the built-in datatypes.

That is a good idea. It would be really cool.

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: macro questions, can't embed unreadable...

2008-10-31 Thread mb

Hi,

On 31 Okt., 05:30, Stephen C. Gilardi [EMAIL PROTECTED] wrote:
 It works with a literal for vecs:

 user= (declare-init [[a 1] [b 2] [c 3]])
 #=(var user/c)

 But if I def the seq of seqs:

 user= (def myvecs '[[a 1] [b 2] [c 3]])
 #=(var user/myvecs)
 user= myvecs
 [[a 1] [b 2] [c 3]]
 user= (declare-init myvecs)
 java.lang.IllegalArgumentException: Don't know how to create ISeq
 from: myvecs (Symbol) (NO_SOURCE_FILE:17)

For my understanding, the answer is: it is not possible to make
declare-init work that way. The declare-init call only sees the Symbol
myvecs. It doesn't resolve the var behind or whatever, since the
declare happens at compile time. Think (def myvecs
(terrible-computation)). However with literal vectors you actually get
the data structures themselves (containing symbols).

Why should (declare-init foo) resolve foo, but (declare-init [foo 5])
should not resolve foo?

Another question: Why not unify both?

  (defmacro declare
[ vars]
`(do
   ~@(map (fn [x]
(if (vector? x)
  `(def [EMAIL PROTECTED])
  `(def ~x)))
  vars)))

  (declare foo [bar 5])

Using defvar instead of def from clojure.contrib.def
one even gets automatic docstrings.

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Pathetic n00b wonders how to deploy

2008-10-31 Thread mb

Hi,

On 31 Okt., 04:46, JCB [EMAIL PROTECTED] wrote:
 1) does Clojure maintain the CL notion of a running image (ACL
 terms), or a core (sbcl terms)?

 For example, in ACL I can do (dumplisp), and I think sbcl has
 something called (save-lisp-and-die) ..

I don't think so, no.

 2) Does Clojure have anything similar to fasl files? It looks right
 now like the way to deploy a Clojure program is to deploy the source
 (.clj) files and (load) them, is this correct?

My guess for deployment would be to create a .jar file, which
is distributed. The users put the .jar in their classpath and are
able to load the library with require/use. For this to work the file
layout has to follow the guidelines for namespace / filename
translation, of course.

I would use load only inside a ns to suck in different files for
a namespace in case the implementation is split up. I would
never use it to load a library. That's what require/use are for.

To deploy a program one can create a Java class via gen-class,
which contains a main function which requires the implementation
of the program and starts the application running. In the
MANIFEST.MF one can specify this class as Main-Class.
So the user can do java -jar MyApp.jar to run the program.

Just my 0.02€.

Sincerely
Meikel

--~--~-~--~~~---~--~~
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: Proxy Bug?

2008-10-30 Thread mb

Hi,

On 30 Okt., 00:31, ntupel [EMAIL PROTECTED] wrote:
 Consider the following code which attempts to redefine clojure/*out*:
 (def output-stream
   (let [buffer (new java.io.ByteArrayOutputStream)]
 (proxy [java.io.OutputStream] []
   (flush []
 (.append output (.toString buffer UTF-8))
 (.reset buffer))
   (write [x]
 (when (= (.size buffer) 32)
   (.flush this))
 (.write buffer x))
   (write [x off len]
 (.write buffer x off len)
 ...
 However if I omit the second write method in the proxy definition,
 I get the following error:

I think the problem here the second write. The syntax should be the
same as for defns.

 (def output-stream
   (let [buffer (new java.io.ByteArrayOutputStream)]
 (proxy [java.io.OutputStream] []
   (flush
 []
 (.append output (.toString buffer UTF-8))
 (.reset buffer))
   (write
 ([x]
  (when (= (.size buffer) 32)
(.flush this))
  (.write buffer x))
 ([x off len]
  (.write buffer x off len))

I'm not sure what happens in your case, but my suspicion is, that
the second overwrites the first, or that it may be equivalent to
this form.

However when you new remove the second form, there is still a write
method! However this one takes the wrong number of arguments. Hence
the method of the super class is not called and you get the Exception.

But proxy-super to the rescue: You may try the following snippet
for the write method:

   (write
 ([x]
  (when (= (.size buffer) 32)
(.flush this))
  (.write buffer x))
 ([x off len]
  (proxy-super write x off len)))

Since there is a write method, we have to call the super-class'
method explicitely.

Hope this helps.

Sincerely
Meikel

--~--~-~--~~~---~--~~
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: Proxy Bug?

2008-10-30 Thread mb

Hi,

On 30 Okt., 08:48, ntupel [EMAIL PROTECTED] wrote:
 Interestingly java.io.OutputStream.write(I)V is invoked even though this
 should be covered by the proxy write method.

I lookep up the implementation of proxy-super. It replaces the
method temporarily. So proxy-super basically doesn't work for
methods with multiple implementations for different arglists,
since only the actually called method-arglist combination is
then in effect. I think it throws the Exception because now,
the first implementation is missing and it is abstract in the
superclass.

But I might be on the wrong track here. I'm not very familiar
with Java. Let alone with reflection and stuff...

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: genclass error message

2008-10-28 Thread mb

Hi,

On 7 Okt., 01:57, Chouser [EMAIL PROTECTED] wrote:
 Currently if you fail to provide or mis-name the main fn in a
 gen-class implementation, you get an error like:

 Exception in thread main java.lang.UnsupportedOperationException:
 net.n01se/main not defined

 This is wrong, since the name shouldn't be just main.  Attached is a
 patch to change this error to:

 Exception in thread main java.lang.UnsupportedOperationException:
 net.n01se/TestObj-main not defined

 --Chouser

  fix-genclass-error.patch
  1KViewDownload

I want to bring this back to mind. The message is still not fixed.

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Chimp Patch - MacroExpand command

2008-10-28 Thread mb

Hi,

On 28 Okt., 19:52, J. McConnell [EMAIL PROTECTED] wrote:
 For anyone using Meikel Brandmeyer's Chimp plugin for Vim, below is a
 patch that adds a MacroExpand command, which sends a (macroexpand-1
 ...) for the inner s-expr. Hope someone finds it useful.

Thank you for the patch. I added \me for macroexpand and
\m1 for macroexpand-1. Changes are in the mercurial repository.

  http://kotka.de/repositories/hg/chimp

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Clojure and introspection/reflection analysis?

2008-10-24 Thread mb

Hi,

On 24 Okt., 00:42, BerlinBrown [EMAIL PROTECTED] wrote:
  And then I have a utility to load hello_world.lisp and execute
 the hello-world call.

 At the command line:
 #Inspect: hello-world function was called
 #Hello World
 #Inspect: hello-world has finished executing.

There is also clojure.contrib.trace.

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Data types in Clojure

2008-10-23 Thread mb

Hi,

On 23 Okt., 08:50, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 This leads me to  a more down-to-earth question: what is the right way
 to use clojure/zip in a program? First I tried

 (use 'clojure.zip)

I normally use an alias: (require '[clojure.zip :as zip])

user= (- (zip/vector-zip [[1 2] 3 [[4 5] 7 8]])
  zip/down
  zip/right
  zip/right
  zip/down
  zip/down
  zip/right
  (zip/edit inc)
  zip/root)
[[1 2] 3 [[4 6] 7 8]]

I prefer using the zip prefix than having conflicts...

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Strange behavior of the #() macro

2008-10-23 Thread mb

Hi Rick,

First of all:
#(x) is equivalent with (fn [] (x)). So as an example with reduce:
user= (reduce #(+ %1 %2) (range 1 101))
5050
user= (reduce (fn [x y] (+ x y)) (range 1 101))
5050

So it should be obvious, that #(3) throws exception as soon as it is
called, since it is equivalent to (fn [] (3)). So you actually try
to call an Integer.

On 23 Okt., 11:29, R. P. Dillon [EMAIL PROTECTED] wrote:
 Using #() for one off functions, you get some odd behavior:
 (reduce #(3) (range 1 100))
 throws an exception:
 java.lang.IllegalArgumentException: Wrong number of args passed to:
 eval--2365$fn
 as does:
 (reduce (fn [] 3) (range 1 100)

This case is different. Without any %, #() retuns function, which
does not expect to be called with any argument. However reduce needs
a function which accepts two arguments:
user= (doc reduce)
-
clojure/reduce
([f coll] [f val coll])
  f should be a function of 2 arguments. If val is not supplied,
   ^^^
  ...

That's also the reason, why you example with fn also fails.
(reduce (fn [a b] 3) (range 1 100)) should work however.

 but:
 (reduce (constantly 3) (range 1 100))

The reason here is, that (constantly 3) is equivalent to
(fn [ args] 3). So the function returned by constantly takes
arbitrary many arguments, in particular two. So reduce is happy.

 performs as one would expect.

The exceptions are also to be expected.

 There are other trivial odd cases:
 (#(3))
 produces an exception.
 But:
 ((fn [] 3))
 does not.
See initial remarks.

 Finally,
 (#(%))
 or even:
 (#(%1))

Again see initial remarks. #(%1) returns a function of one argument
which actually calls this argument. So it is equivalent to
(fn [x] (x)). Doing (#(%)) is missing this argument and you get
an exception.

user= (#(%) (fn [] (println Hello)))
Hello

 throws an exception, but:
 ((fn [a] a))
 does not.

This does also throw an exception.

 I'll admit I haven't look at the source for the #() macro, but is this
 type of behavior intended?  I don't fully grok macros in lisp, so I
 may be missing something...

I think you just had a misunderstanding of #(). I hope I could shed
some light on its usage.

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Placement of metadata in defn

2008-10-23 Thread mb

Hi Paul,

On 23 Okt., 15:11, Paul Drummond
[EMAIL PROTECTED] wrote:
 I am a bit puzzled by how metadata seems to behave differently
 depeding on where it's used and whether #^ is included or not:

AFAIU, #^ attaches the given map to the thing read.

 (defn #^{:doc doc}  my-fn ([x] x))
 ;;Works
Attaches {:doc doc} to the metadata of the symbol my-fn.

 (defn {:doc doc}  my-fn ([x] x))
 ;;Error: Second argument to def must be a Symbol
Obviously #^ is missing, hence the map is passed on to defn.
Defn expects a Symbol not a Map. = *meep*

 (defn my-fn [x] x #^{:doc doc})
 ;;Error: Unmatched delimiter: )
Since #^ attaches to the next thing read and there is
nothing following the reader screws up in some way.

 (defn my-fn ([x] x) {:doc doc})
 ;;Works
This is the syntax of defn, I believe. What ever map
you pass at the end of the definition is added to the
meta-data.

 Can anyone help me understand this please?
I'm not sure understand this meta-data stuff myself...

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: On macros

2008-10-22 Thread mb

Hi Karl,

On 22 Okt., 06:43, Krukow [EMAIL PROTECTED] wrote:
 user (eval (list (symbol Object.)))
 [EMAIL PROTECTED]
 user

 This seems to indicate that actually Object. is just a symbol like any
 other. So there isn't any special reader support for it, but instead
 the compiler handles symbols with dots specially (depending on where
 the dot is in the symbol - beginning middle end).

 Is this the right way to think about it?
Yes. Symbols with dots in the beginning and the end are special.
- .method:
  (.method x) = (. x method) (or more verbose: (. x (method)))

- Foo.:
  (Foo.) = (new Foo)

While the first is a nice abbreviation for things like -, I don't
particularly like the second. The . is quickly overlooked.

 @Bill: Yes, I did see defmacro in boot - I didn't understand it
 completely at first read. I think I do now. A macro is just a function
 that maps a data structure to a data structure. Additionally the var
 has a special property 'macro' set to true, which has implications for
 the compiler. I guess this implies that one can take any function
 already defined (even if not intended to be a macro) simply by doing
 (. (var name) setMacro)?
What is a macro actually? A macro is nothing else than a function on
code (data structures actually) returning (most likely) different
code.
However a function, which is applied at compile time. While a normal
function is applied at runtime. The setMacro call just tells the
compiler when to apply the function and whether to evaluate its
arguments or not. Then whatever this function returns is used as new
input for the compiler at the original position of the macro call.

So, yes, theoretically one can make every function behave like a
macro.
Whether this makes sense Different story.

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Data types in Clojure

2008-10-22 Thread mb

Hi Konrad,

On 22 Okt., 12:49, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 However, there is one point that is not clear to me: how does Clojure
 deal with data types in general, and abstract data types in
 particular? How would one implement a library for tree operations, a
 graph library, or a numerical library for operations on complex
 numbers?

 In OO languages, one would uses classes and interfaces for that. In
 functional languages of the ML family, one would use algebraic data
 types and modules/packages to hide a particular implementation. In
 standard Lisps, everything would be represented by cons nodes, with
 little to no abstraction.

 Clojure knows about abstractions and interfaces, but all I have seen
 until now is the use of interfaces on the client side, with data types
 already implemented. I can also see how one would implement classes
 and interfaces in Java and use them from Clojure. But who would one
 define interfaces and concrete implementations in Clojure itself?

Well on the one hand you can define interfaces by documentation.
Define the interface in the documentation and export the functions
which do things as advertised from your namespace. Private helper
functions can be declared and are not exported (defn vs. defn-).
Whatever the functions return should be treated opaque. As long as
the opaqueness is respected you can change the underlying
implementation without customer impact.

An example is the interface of clojure.zip. It returns a location
in the tree, which is sufficiently vague to tell you Leave your
hands off!. Of course you may inspect a location and change it
as you like (it's a normal vector). But well, don't complain
afterwards.

If you are more the Give a programmer a tree and rope and he will
use them! type, you can use gen-class from clojure itself and
gen-interface from clojure.contrib to define an opaque interface
and a class implementing the interface.

I think the later is good idea when you expect different
implementations
to be plugged in at run-time, which may also come from the user of
your library. If it's just the implementation of the library's
functionality I would go with the first way.

Just my 0.02$

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Testing Clojure (was Re: Bug? Strange set equality (r1075))

2008-10-22 Thread mb

Hello Stuart,

On 21 Okt., 16:37, Stuart Halloway [EMAIL PROTECTED] wrote:
 Since there is now a movement afoot to write a comprehensive test  
 suite, I want to re-post the spike I did earlier on ClojureCheck.

 It would be cool to use check-style tests for at least part of the  
 Clojure suite. If there is interest in this, I hope to have time to  
 work on this in late November, or would be delighted if someone else  
 picks up the idea and runs with it.

I am working on a TAP implementation[1] for Clojure. For this I
would really like to have a ClojureCheck (as there is LectroTest
for Perl). And as stated in the original ClojureCheck thread
I will work on this.

Unfortunately, (not= de.kotka.tap clojure/test clojure.contrib.test-
is)
but I think the basic machinery like arbitrary definition etc. can
be reused. I will hopefully soon post a first draft of the
implementation.

Sincerely
Meikel

[1]: http://kotka.de/projects/clojure/tap.html (Not up-to-date, though)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Modified doto

2008-10-21 Thread mb

Hi,

recently I ran in the a limitation of doto, that it only invokes
methods. However piping the object with - does not work
also, since it's semantics are more like .. .

I'd like to propose the following chimera of doto and -.

(defmacro doto-
  [obj  forms]
  (let [objx (gensym obj__)]
`(let [~objx ~obj]
   (do
 ~@(map (fn [f]
  (if (seq? f)
`(~(first f) ~objx ~@(rest f))
`(~f ~objx)))
forms))
   ~objx)))

It allows the full support of doto via the dot notation of
methods. And it supports on the other hand other functions
not only methods. One example is the new miglayout
interface in clojure-contrib.

(doto- (new JFrame Hello, World!)
  (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
  (miglayout SomeChild :AConstraint MoreChildren ...))

Any thoughts?

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Modified doto

2008-10-21 Thread mb

Hi,

On 21 Okt., 14:41, mb [EMAIL PROTECTED] wrote:
 (defmacro doto-
The name is actually also up to discussion. doto is already
in use and this change is incompatible to legacy code.
I couldn't come up with a good alternative...

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Modified doto

2008-10-21 Thread mb

Hello Stephen,

On 21 Okt., 17:05, Stephen C. Gilardi [EMAIL PROTECTED] wrote:
 Is the .. aspect of it the automatically make a list if it's not  
 one part?
This is actually a - aspect. What I meant was:
(.. x (getModel) (getRoot) (state))
is equivalent to
(- x .getModel .getRoot .state)

That is the reason, why (- frame (.method1 ...) (.method2 ...))
doesn't work in the given examples. The methods most likely
don't return frame...

 (doto- (JFrame. Hello Frame)
                (miglayout (JLabel. Hello Label))
                .pack
                (.setVisible true))
This is exactly my first use case. :)

 It seems a key thing to remember here is that while this does return a  
 useful value, it's primarily a construct for side effects. We're  
 calling these Clojure functions because they're compositions of calls  
 that have side effects either on the state of obj or on the system as  
 a whole (e.g., showing a window). We're throwing away the values  
 produced by the individual calls. This is in contrast to - where  
 each call's result is consumed by the next function in the thread.
Yes. This is intended as an augmented (or improved or whatever) doto.
It's purely for side effects, but very handy for object creation,
which
needs to call several methods on the same object.

For functional uses - is almost perfect. Hmm... When we currently
talk about it... How about this:

(defmacro xxx-
  ([x form] (if (seq? form)
  (let [[hd tl] (split-with #(not= ' %) form)]
(if tl
  `(~@(concat hd (cons x (rest tl
  `(~(first form) ~x ~@(rest form
  (list form x)))
  ([x form  more] `(- (- ~x ~form) [EMAIL PROTECTED])))

Disclaimer: this is only a rough idea!!! Let alone a correct
implementation.

The idea is to provide a way to let the piped argument be someting
else than the first one.

(xxx- Hello (apply str  [,  World!])) gives Hello, World!.

The  is used to mark the hole where the value is to be inserted.
Should this be only replaced in the top expression? Or also in
sub expressions? Without zipper in boot.clj? Is this a good idea
in the first place?

Acknowledgement:  is stolen from the cut notation of some SRFI.

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Modified doto

2008-10-21 Thread mb

Hello,

On 21 Okt., 19:08, Chouser [EMAIL PROTECTED] wrote:
 Here's my implementation:

 (defmacro _ [ exprs]
   (list 'let (apply vector (mapcat (fn [expr] (list '_ expr)) exprs)) '_ ))
Now this is a nice idea.

 I used it a couple times after first writing it, but have since failed
 to find much use for it.  I guess I wouldn't really recommend it.
I often encountered the case, that I want to do an apply in the
- or eg. some filter or map, which also does not work. But maybe
you are right, and this is a sign that the code is bad.

Nevertheless here a combined version, which does not need to
specify the _ all the time.

(defmacro 
  [x  forms]
  `(let ~(apply vector
'_ x
(mapcat (fn [form]
  (if (seq? form)
(if (some #(= '_ %) form)
  (list '_ form)
  (list '_ (list* (first form) '_ (rest
form
(list '_ (list form '_
forms))
 ~'_))

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Ruby = Clojure for Enumerable and Array

2008-10-17 Thread mb

Hi,

On 17 Okt., 00:14, Mark McGranaghan [EMAIL PROTECTED] wrote:
 When I first started working with Clojure a while back I tried to get
 my bearings by figuring out how to do some basic things in Clojure
 that I had previously done in Ruby.  With all the recent talk about
 the seq api, I thought I'd clean up my notes on Ruby = Clojure for
 the Enumerable and Array Ruby classes.

 You can find what I have so far here:http://gist.github.com/17283

 I hope someone finds this helpful. Comments are appreciated.

Nice summary. I shortly skimmed through it and noticed some things:

- remove is now in Clojure (since yesterday) :)

- There is min and max. You just mentioned first/last
  if ordered.

- You use a strange-looking way for loops:
  (defn foo
[a b]
((fn [a c] (recur (bar a c) (b a c)) a :initial))

  This is better written with loop:

  (defn foo
[a b]
(loop [a a c :initial] (recur (bar a c) (b a c)))

- It is maybe a good idea to also include things
  of Clojure, which Ruby doesn't have, eg. interpose
  and interleave, to help programmers to get some
  ideas for the Clojure-way of doing things. Hmm...
  or maybe not. There are the docs and the wiki
  after all

As Parth suggested, you should definitively
put a link in the Ruby section of the wiki.

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: offtopic - where are you come from? (poll)

2008-10-17 Thread mb

Frankfurt am Main, Germany
--~--~-~--~~~---~--~~
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: (map f coll) using memfn

2008-10-16 Thread mb

Hi,

On 16 Okt., 05:13, Timothy Pratley [EMAIL PROTECTED] wrote:
 Just a few follow on questions...
 1) Is there any way to do away with the input bindings altogether? map
 doesn't need input bindings, but memfn does. I don't quite grasp why
 they are needed for memfn, or how to construct an input binding based
 on the number of collections. ie: I would need to generate a list of
 symbols the size of the number of collections (map gensym colls) 
 I know that code wont work, but there must be a way.

Maybe you find this helpful: http://paste.lisp.org/display/67182

  (map #(jcall Timothy 'substring %1 %2) (iterate inc 0) [3 4 5])

Please note, that the annotation does not allow variadic application
while jcall does. It's trivial to cut arguments, eg.

  #(jcall obj 'method %1 fixed-arg %2 another-fixed %)

Sincerely
Meikel

--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread mb

Hello,

On 15 Okt., 17:53, CuppoJava [EMAIL PROTECTED] wrote:
 What's supposed to do is take an arbitrary-form, and create a lazy
 sequence out of calls to yield.

You can construct the inputs in a lazy sequence and then map
yield over that:

(map yield
 (lazy-cat (for [i (range 3)]
 i)
   [(if true Hello World Dlrow Olleh)]
   (for [i (range 2)
 j (range 2)]
 [i j])))

Since map, lazy-cat and for are all lazy, it should do, what
you want.

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread mb

Hi,

On 15 Okt., 18:33, CuppoJava [EMAIL PROTECTED] wrote:
 That solution will work for this simple case, but my goal is to make
 it possible to create lazy-sequences in a more straight-forward
 manner. So that we can use the usual sequence functions (doseq,
 dorun, loop) instead of the lazy-equivalents (for).
 Is what I'm asking for impossible?

Obviously I misunderstood your question. The sequence you
wanted would have been just the lazy-cat w/o the map call.

Your are asking for something like coroutines.

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Help writing this Lazy Sequence Macro

2008-10-15 Thread mb

Hi,

On 15 Okt., 19:11, CuppoJava [EMAIL PROTECTED] wrote:
 I'm trying to use this macro to port a game-framework that I've
 written in Ruby, to Clojure.
 ...
 Do you guys have any ideas? Or a direction that I might consider
 looking in?

I can only offer a general advice:

Don't stick to close to your original code.

You said, you used coroutines in Ruby and now you are
asking for them in Clojure. Maybe you should take one
step back and take a view from the distance and try to
think in Clojure.

Suppose the yield in your original post is not a coroutine
thing, but some utility function.

Just to see, that instead of calling it in a loop, one can
also construct the inputs in a seq and map yield over
it, takes sometimes hours for me. But when I get such
sudden idea (which is maybe obvious for experienced
Clojure programmers), I'm always surprised by the
compression it yields. Real case: some 10 pages of
code were shrunk to ~2 pages of code with the same
functionality. I thought, wtf did I do in the first version?

Sincerely
Meikel

--~--~-~--~~~---~--~~
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: (map f coll) using memfn

2008-10-15 Thread mb

Hi,

On 15 Okt., 19:09, Graham Fawcett [EMAIL PROTECTED] wrote:
   (map f coll (range (count coll)))

 Rather than (range (count coll)), I would use (iterate inc 0), which
 incurs no overhead for counting the argument.

There is not only the overhead of counting, (count coll) might
also destroy the laziness of the collection.

user= (count (for [i (range 3)] (do (println i) i)))
0
1
2
3

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: Nested Multimethods

2008-10-14 Thread mb

Hello,

On 14 Okt., 16:58, Randall R Schulz [EMAIL PROTECTED] wrote:
 I have heard it claimed (on one of the Scala lists, I think)
 that patterns themselves are an anti-pattern...

I think there are always patterns. They are just different. In
Clojure there is maybe the Driver Function pattern: Instead
of writing a huge macro, put the logic in a driver function,
package up the arguments in (fn [] ...) closures and pass
them to the driver.

Sincerely
Meikel


--~--~-~--~~~---~--~~
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: Making a living on Clojure

2008-10-14 Thread mb

Hi,

On 14 Okt., 22:13, Fogus [EMAIL PROTECTED] wrote:
 I am attempting to work Clojure (at least partially) into my job,
 but in doing so I wonder how many of you here use it at your own
 jobs as opposed to relegating it to hobby.

I'm using Clojure at my job, but mainly to make my life easier.
It's something which doesn't show up in HR files and my boss doesn't
care as long as it gets the job done. So maybe not what you are
interested in. How did Rich put it? I know of some companies, who
use it as their secret weapon.

Nevertheless: Although it's not a big project I see the savings
in time and code, which were already stated by others. I planned
to give the GUI to a student worker to implement it in Java, so
that I can focus on the bussiness logic in the backend. But I'm
about to change my mind and go for full Clojure. Maybe I can infect
him with the Clojuritis but I have little hope...

In any case: if it has to run on the JVM and no one cares how
it looks like under the hood, I would go for Clojure. Although one
has to bring the patience to adapt to the development. (I had
several changes while tracking the development of
clojure.contrib.lib to clojure/ns.)

Take this with a grain of salt. I'm not a software developer.
Just my two cents.

Sincerely
Meikel

--~--~-~--~~~---~--~~
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: Suggest changing update-in to accept additional args for f

2008-10-13 Thread mb

Hello,

On 13 Okt., 17:02, Stephen C. Gilardi [EMAIL PROTECTED] wrote:
         user= (update-in m [:a :b] + 2) ; new
         {:a {:b 3}}

I think this is a good idea. This would also be in-line with things
like
alter and commute.

Sincerely
Meikel
--~--~-~--~~~---~--~~
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: gen-class and namespace

2008-10-09 Thread mb

Hi,

 gen-class loads eg. foo/bar/Baz.clj for class foo.bar.Baz. However,
 maybe one also has support functions in the foo.bar namespace. Hence
 one needs also foo/bar/bar.clj.

 I seem to be able to solve the problem by putting this at the top of
 Baz.clj:

 (ns foo.bar (:use foo.bar))

 That causes foo/bar/bar.clj to be loaded the first time its needed and
 not again.  Is that what you want? I'm probably misunderstanding the
 problem, so feel free to correct me.

- You understand me correctly.
- That works? I didn't even try. I was under the impression, that
there
  was some cycle detection implemented in use and require. So I would
  have expected this to fail...

For me this feels fishy, because:
- Why does the user have to do crazy looking stuff? (defining a
  namespace requiring itself?)
- I have to be concerned about load'ing Baz.clj in bar.clj. If there
  is no cycle detection, I'm in trouble. So I have to inform myself
  about unrelated implementation details.
- It is inconsistent to the namespace matters, not file philosophy
  advocated previously.

I could also just put (require 'foo.bar) in Bar.clj and put the
implementation somewhere else. That would solve the problem also, but
why does the user have to provide boilerplate, when this could be done
automatically?

Your solution solves my problem, but to be honest: to me it looks not
less hacky...

Sincerely
Meikel

--~--~-~--~~~---~--~~
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: First Release of Chimp available

2008-10-09 Thread mb

Hello,

On 9 Okt., 02:41, Jonas Bengtsson [EMAIL PROTECTED] wrote:
 It almost works now, however something fishy is going on when it tries
 to launch screen from vim. I've done the following setting:
Do you also use the VimClojure plugin? Chimp heavily relies on its
syntax highlighting. Of course one has to have a visual block for \eb
or
one has to be in a sexp for \et. If not, they fail silently. I have to
add some diagnostics here...

Otherwise you can check, that Chimp and screen expect the temporary
files in the same directory. But in case you use a cygwin vim, this
should be the case.

Sincerely
Meikel

--~--~-~--~~~---~--~~
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: First Release of Chimp available

2008-10-09 Thread mb

Hello,

On 9 Okt., 06:41, Mitch [EMAIL PROTECTED] wrote:
 I've been using chimp a little bit, and it works pretty well except
 for the \ef command.  It gives me the following error:
 E119: Not enough arguments for function: SNR31_EvalFile
Please report such issues! Otherwise they can't be fixed.

 All the other commands work fine though!  Thanks for the plugin!
:) Thanks for using it.

Sincerely
Meikel

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



Bug in isa??

2008-10-08 Thread mb

Hello Rich,

in the definition of isa? in boot.clj in the last line (no. 2879),
there isa? recurs into the contents of the vectors. It uses
implicitely the global-hierarchy instead of the provided
one.

Shouldn't it be
  (isa? h (child i) (parent i))

instead of
  (isa? (child i) (parent i))

Sincerely
Meikel
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---