Re: Android 'dex' stage takes a very long time with Clojure

2010-05-29 Thread Remco van 't Veer
Nice!  This will speedup development and allow you to workaround the
terribly long startup time with a distracting splash screen.


On 2010/05/29 01:06, MHOOO wrote:

> I've just started with development on android myself, but from what
> I've read on the internets, you could probably write a .dex loader in
> the default classes.dex (which will be loaded when you start your
> application) and write your actual program in other .dex files. This
> way you'll be able to compile the entire clojure system into the
> classes.dex and will only have to update your custom .dex files.
> This is actually something I'm currently trying to get to work.
> For further info, see:
> http://code.google.com/p/android/issues/detail?id=7147
> http://developer.android.com/reference/dalvik/system/DexClassLoader.html
>
> On May 28, 4:12 pm, Matt Clark  wrote:
>> I'm new to Android, but I've been wanting to give it a try for a while
>> so I thought I'd try using Clojure's master branch.  It all seems to
>> be working fairly well except the dex stage of installation takes
>> around 2 minutes for a simple Hello World app.  How do others get
>> around this lag?
>>
>> I'm pretty sure it's caused by the large clojure.core namespace, as
>> I've already taken everything else that I can out of the clojure jar
>> file.  I'm just not sure if there's anything else I can do.  I am
>> using emacs and android-mode, if that is of any help.  I've also tried
>> giving it more memory as suggested 
>> here:http://groups.google.com/group/clojure/msg/c38e015582cf7623
>>
>> Thanks a lot
>>
>> Matt

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Anyone experienced in using clojure as a "database"

2010-05-29 Thread Andrzej
Hi Erik,

I have a question about primary keys. As far as I can see you're
currently using the first field of the relation as a primary key.
While that's what other databases do (and it is working well), I think
it would be better to make _records_ themselves primary keys. Since
records are immutable they are guaranteed to be unique and comparing
them is essentially free. I have a feeling that would make whole lot
of things much easier (no need to check the primary key field for
uniqueness, no need to implement auto increment mechanisms, foreign
keys would just become actual records). What do you think about it?

Andrzej

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Elegant way to replace a few words in string

2010-05-29 Thread Oleg
Thank you for great solution.

On 28 май, 23:45, Laurent PETIT  wrote:
> 2010/5/28 Michael Gardner 
>
> > On May 28, 2010, at 12:42 PM, Laurent PETIT wrote:
>
> > > The rule should really always be: no warning at all (with
> > *warn-on-reflection* set to true, of course).
>
> > I strongly disagree. Why should you care about those sorts of warnings
> > unless you've already identified a bottleneck that needs elimination?
>
> Said differently than my previous answer : consider removing warnings as the
> act of keeping your code in a good state/shape. I tend to not get rid of
> warnings enough in my own java code, but for clojure production code, I
> would take warnings wayy more  seriously than e.g. java warnings.
>
> My 0,02€,
>
> --
> Laurent

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: 57 varieties

2010-05-29 Thread Joost
On May 28, 9:26 pm, Steve Purcell  wrote:
> If it helps, I've got a working non-ELPA set-up which you can browse here:
>
>  http://github.com/purcell/emacs.d
>
> It uses git versions of Slime, Clojure-mode and Swank-clojure (as git 
> submodules). Feel free to mail me off-list with any questions.

Similarly; my setup is here (only tested with clojure 1.1):
http://github.com/joodie/emacs-d
with most of the relevant configuration in
http://github.com/joodie/emacs-d/blob/master/topics.d/topic-clojure.el

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Newbie question about vector performance

2010-05-29 Thread igorrumiha
On May 28, 3:47 pm, Rubén Béjar  wrote:
>
> I would thank a lot any hint, suggestion, comment, or
> whatever... :-)
>

Here is a version that is approx 10 times faster: http://snipt.org/Olml
The code structure is basically the same but it uses integer arrays
for storage, some manual inlining and lots of type casts. I'm not
certain it _works_ correctly, but... :)
My observations:
- use the profiler. jvisualvm that comes with the sun JDK has received
some much needed love recently (especially in java 1.6.0_20) and has
helped me alot in profiling the code. Install an additional plugin:
Sampler. It is has a much lower overhead compared to the Profiler
plugin that is installed by default. Both are useful, though.
- native clojure data structures (seqs, vectors, maps, etc.) are slow
(compared to native Java arrays for instance). There is no going
around that. Immutability and other very nice features come with a
price. Dynamic languages are also, by their nature, slower than their
static companions.
- jvisualvm shows that in my version 40% - 50% of the time is spent in
the ur-8neigh-minmax function. That time is further split into array
fetches, casts to int, arithmetic (inc, dec, add, multiply,
comparisons). I simply don't know how to optimise that further without
changing the algorithm. On that note, the Clojure compiler and core
libraries are getting better: http://snipt.org/Olmn Current Clojure
1.2.0 gives approx 10% better results.

I assume (am certain, actually :)) my "improvements" can be further
improved, but the code gets quite unreadable bery fast.

A side note: I have been happily programing in Perl for many years
now. Perl is typically 50x to 100x slower than C or Java. When people
identify a performance bottleneck someone writes a version of the same
thing in C. I don't see a problem with using the same approach in
Clojure. You can write some quite ugly clojure (usually using
mutability) that approaches Java speed or you can abstract the slow
parts out and write them in Java.

Hope this helps... :)

--
Igor Rumiha

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Datatype Usage Examples

2010-05-29 Thread Sina K. Heshmati
Krukow wrote:
> Sina K. Heshmati wrote:
> [snip]
>> The only member data _I'm_ able find are the ones that are passed to the 
>> default
>> constructor, namely at the time that the abstraction is reified. What if I'd 
>> have
>> to give create a member field that is not necessarily known by the caller or
>> instantiator. That is, it's the abstraction itself that has to create and
>> maintain the value of that field.
> 
> You mean something like a private field in Java that is not supplied
> as a constructor argument, but computed as a function of the other
> fields, and which is not necessarily accessible from callers. If I
> understand correctly what it is you want, I think you are moving away
> from Clojure, trying to somehow encapsulate an "object". See RH's note
> on encapsulation: "Encapsulation of information is folly. Fields are
> public. Use protocols/interfaces to avoid dependencies" [1].

I chose Clojure to experiment with new things rather than applying my old 
tricks so I'm definitely not looking for encapsulation per se but I should be 
able to map the concepts from one language to the other in order to be able to 
effectively code. That said, I'd rather make sure that my low-level data 
structures are being operated on by only one implementation.

The fact that a certain field is immutable reassures me that other programs 
can't alter it and this is good enough. If I want my abstraction to be able to 
alter its own state, then I'd use Refs, Atoms, and the like. I hope this is 
Clojure idiomatic.

My implementation of the pair abstraction in Clojure is here:
http://github.com/sindoc/algorithms/blob/master/src/main/clojure/memory-management/manual/pairs/pair.clj

Right now, external programs can access my low-level data structures e.g. 
car-mem and alter them since they're 'refs'. This is not good to my eyes, 
unless someone says: no matter what you do, external programs can still find a 
way to access the private fields of my implementation e.g. using reflection.

Macros could also be used to generate most of the helper functions for car-mem, 
cdr-mem and next-free.

Please feel free to report any bad practices or improvements.

>> One of the abstraction that I was hoping to implement in Clojure is a 
>> Scheme-like
>> pair in order to demonstrate various memory management techniques. Once we do
>> (cons a b), an abstract pair should be made that only contains a pointer to 
>> its
>> location in memory: (tag address). Here's the pair implementation [2] in 
>> Scheme
>> R5RS.
>>
> 
> So you want a mutable pair (fst, snd) where fst and snd can be mutated
> arbitrarily? This is definately not the Clojure way :) In Clojure,
> you'd either use a pair of atoms or refs, giving you managed
> mutability, or you'd simply write a functional pair.

Obviously, this is not the Clojure way but I have to simulate the Scheme pair 
system.

Thanks for the follow-up, Krukow.

SinDoc

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Newbie question about vector performance

2010-05-29 Thread Laurent PETIT
If you change the size of your CA, is the ( java time / clojure time ratio )
roughly constant ?

2010/5/28 Rubén Béjar 

> Hi all,
>
> I am new to the list and to Clojure. I have been working in
> implementing some 2D cellular automata (CA) just to have a project
> to teach Clojure to myself. After some work I have something that
> works, but it is pretty slow. The function that takes a CA
> of 500x500 cells (integers) and returns an updated (*) copy
> takes 4 s. (using Clojure vectors), while doing more or less the same in
> Java (using arrays and primitive types) takes more or
> less 16 *ms.*. I expected some difference, but not that big. Before
> trying to use Java arrays and primitive types
> in Clojure, I would like to know how my Clojure approach can
> be improved  (I am willing to sacrifice some performance to keep
> it "more Clojure", but not that much).
>
> As I do not want to post a bunch of horrible code full of comments
> and not properly indented, I have extracted what i hope are the
> main pieces, written some comments and posted it here:
> http://snipt.org/Okpk
>
> Pasting that code in a new file in Eclipse (I am using
> counterclockwise) and running it in the REPL prints this:
>
> Clojure 1.1.0-alpha-SNAPSHOT
> "Elapsed time: 4355.363706 msecs"
> "Elapsed time: 4416.98562 msecs"
> 1:1 user=> #
> 1:2 cellular-automata-basic=>
>
> I would thank a lot any hint, suggestion, comment, or
> whatever... :-)
>
> Best regards,
>
>   Rubén
>
> (*) The update consists on adding the values of the 8 neighbours
> of every cell and changing it if that sum is between two fixed
> numbers.
>
> --
> Rubén BÉJAR HERNÁNDEZ
>
> Dpto. de Informática e Ingeniería de Sistemas - Universidad de Zaragoza
> (Computing and Systems Engineering Department - Universidad de Zaragoza)
> c/ María de Luna 1, 50018 Zaragoza, Spain
>
> Tel: (+34) 976 76 2332 (Fax: 1914)  e-mail: rbe...@unizar.es
>
> Grupo IA3 (IA3 Laboratory) - http://iaaa.cps.unizar.es
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: JIT Compilation on Android

2010-05-29 Thread Remco van 't Veer
The dalvikvm does not run java classes and has a different instruction
set.  That's why you need to do the dex step before deploying your code
on android.

George Jahad did get a repl/eval to run on android some time ago.  See:

  http://groups.google.com/group/clojure/browse_thread/thread/14725172c626642c

And the revelant commit in his clojure fork:

  
http://github.com/GeorgeJahad/clojure-android/commit/9caf2913a2724c38d735743649763c7b0c96dfcd



On 2010/05/29 05:44, MHOOO wrote:

> I've got 1.2.0-master running on android froyo with a repl. Froyo
> supports JIT compilation, but whenever I call code which is defining a
> new class (e.g.: "(defn blub [] nil)"), I get an Exception:
> -
> clojure.core=> (defn blub [] 1)
> java.lang.RuntimeException: java.lang.UnsupportedOperationException:
> can't load this type of class file (NO_SOURCE_FILE:15)
> clojure.core=>
> -
> And the following error inside the android logs:
> -
> E/dalvikvm(  522): ERROR: defineClass(0x43e6e188, clojure.core$blub,
> 0x43f83a58, 0, 984, 0x0)
> -
> Am I doing something wrong/impossible or is there a way to fix this?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Elegant way to replace a few words in string

2010-05-29 Thread Dennis
However, in this case, the point of the code was probably to
show/teach somebody how to solve a problem.  When teaching, you want
to make the point as clear as possible, and I think John is trying to
point out, in this instance, the extra code to remove the reflection
warnings detracts from that goal.

I do not disagree with the idea of removing reflection warnings as a
rule and not an exception, especially in production software.

I should probably not fan this fire, but I did anyways... :)

-- Dennis

On Fri, May 28, 2010 at 2:45 PM, Laurent PETIT  wrote:
>
>
> 2010/5/28 Michael Gardner 
>>
>> On May 28, 2010, at 12:42 PM, Laurent PETIT wrote:
>>
>> > The rule should really always be: no warning at all (with
>> > *warn-on-reflection* set to true, of course).
>>
>> I strongly disagree. Why should you care about those sorts of warnings
>> unless you've already identified a bottleneck that needs elimination?
>
> Said differently than my previous answer : consider removing warnings as the
> act of keeping your code in a good state/shape. I tend to not get rid of
> warnings enough in my own java code, but for clojure production code, I
> would take warnings wayy more  seriously than e.g. java warnings.
>
> My 0,02€,
>
> --
> Laurent
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: (apply interleave [[1 2]])

2010-05-29 Thread Paul Hobbs
What code would this make simpler?  Are you constantly having to check this
special case?  If not, I don't see a reason to include it.
--
Paul Hobbs


On Sat, May 29, 2010 at 1:32 AM, Eugen Dück  wrote:

> When I do
>
> (apply interleave some-colls)
>
> and some-colls is a sequence/collection of only one sequence/
> collection, it will throw:
>
> user=> (apply interleave [[1 2]])
> java.lang.IllegalArgumentException: Wrong number of args passed to:
> core$interleave (NO_SOURCE_FILE:0)
>
> (Of course I don't need the apply to cause that exception, but calling
> interleave directly with just one parameter doesn't make any sense.
> But in the case you use apply, having only one sequence in a sequence
> is a possible corner case that can arise "at run time")
>
> In order to make interleave more general, I'd like to add a "one param
> overload" to interleave like
>
> (defn interleave
>  "Returns a lazy seq of the first item in each coll, then the second
> etc."
>  ([c] (seq c))
>  ...
>
> or even just
>
> (defn interleave
>  ([c] c)
>
> but that would break the contract of interleave, in that it returns
> whatever you pass in, which might not be a sequence, as is the case in
> my example.
>
> Any thoughts on this?
>
> Eugen
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Elegant way to replace a few words in string

2010-05-29 Thread Laurent PETIT
My memory was bad. There's no rampant bug in the code if one does not place
type hints. My bad.

2010/5/29 Dennis 

> However, in this case, the point of the code was probably to
> show/teach somebody how to solve a problem.  When teaching, you want
> to make the point as clear as possible, and I think John is trying to
> point out, in this instance, the extra code to remove the reflection
> warnings detracts from that goal.
>
> I do not disagree with the idea of removing reflection warnings as a
> rule and not an exception, especially in production software.
>
> I should probably not fan this fire, but I did anyways... :)
>
> -- Dennis
>
> On Fri, May 28, 2010 at 2:45 PM, Laurent PETIT 
> wrote:
> >
> >
> > 2010/5/28 Michael Gardner 
> >>
> >> On May 28, 2010, at 12:42 PM, Laurent PETIT wrote:
> >>
> >> > The rule should really always be: no warning at all (with
> >> > *warn-on-reflection* set to true, of course).
> >>
> >> I strongly disagree. Why should you care about those sorts of warnings
> >> unless you've already identified a bottleneck that needs elimination?
> >
> > Said differently than my previous answer : consider removing warnings as
> the
> > act of keeping your code in a good state/shape. I tend to not get rid of
> > warnings enough in my own java code, but for clojure production code, I
> > would take warnings wayy more  seriously than e.g. java warnings.
> >
> > My 0,02€,
> >
> > --
> > Laurent
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> your
> > first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Elegant way to replace a few words in string

2010-05-29 Thread Stuart Halloway
This is covered in the coding standards doc [1]: "Use type hints for functions 
that are likely to be on critical code; otherwise keep code simple and 
hint-free."

Reusable libraries are a strong candidate for type hinting.

[1] http://www.assembla.com/wiki/show/clojure/Clojure_Library_Coding_Standards

> 2010/5/28 Michael Gardner 
> On May 28, 2010, at 12:42 PM, Laurent PETIT wrote:
> 
> > The rule should really always be: no warning at all (with 
> > *warn-on-reflection* set to true, of course).
> 
> I strongly disagree. Why should you care about those sorts of warnings unless 
> you've already identified a bottleneck that needs elimination?
> 
> 
> Said differently than my previous answer : consider removing warnings as the 
> act of keeping your code in a good state/shape. I tend to not get rid of 
> warnings enough in my own java code, but for clojure production code, I would 
> take warnings wayy more  seriously than e.g. java warnings.
> 
> My 0,02€,
> 
> -- 
> Laurent
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

How to reset a counter

2010-05-29 Thread WoodHacker
I've been working with Lisp and Scheme for the past few years and have
migrated to Clojure because of the JVM.   I think I get functional
programming, but one problem is giving me fits.

I'm working on  a simple imaging problem.   I want to copy an array of
pixels to an image buffer.   That means that I have to deal both with
an array and a matrix (x and y).   As I go along my array, each time x
reaches the end of a line in the matrix I have to set it back to zero
and increment y.

I can find no simple way to do this without getting a compile error.
Can someone show me how to do this?

Example in pseudo code:

x = 0
y = 0

for  (k = 0; k < 256; ++k)
   if (= x 16) {
  x = 0
 (inc y)
  }
  else
 (inc x)

 writeBuffer (x, y, value[k])


Bill

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: How to reset a counter

2010-05-29 Thread James Reeves
On 29 May 2010 14:19, WoodHacker  wrote:
> I'm working on  a simple imaging problem.   I want to copy an array of
> pixels to an image buffer.   That means that I have to deal both with
> an array and a matrix (x and y).   As I go along my array, each time x
> reaches the end of a line in the matrix I have to set it back to zero
> and increment y.
>
> I can find no simple way to do this without getting a compile error.
> Can someone show me how to do this?

You could use loop/recur. The following code is closest in structure
to the pseudo code you supplied:

  (loop [x 0, y 0, k 0]
(when (< k 256)
  (write-buffer x y (value k))
  (if (= x 16)
(recur 0 (inc y) (inc k))
(recur (inc x) y (inc k)

However, there are more concise methods of programming the same thing.
For instance, we don't need to bother incrementing x and y; we can
calculate them on the fly from k using modulus (mod) and quotient
(quot):

  (loop [k 0]
(when (< k 256)
  (write-buffer (mod k 16) (quot k 16) (value 16))
  (recur (inc k

Now we just have a single loop with a single incrementing variable, k.
This is a common pattern, and there is a macro called "dotimes" in
clojure.core that implements that pattern:

  (dotimes [k 256]
(write-buffer (mod k 16) (quot k 16) (value 16)))

- 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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: JIT Compilation on Android

2010-05-29 Thread MHOOO
Ah yes, applying the commits onto clojure master worked. Thanks!

On May 29, 2:06 pm, Remco van 't Veer  wrote:
> The dalvikvm does not run java classes and has a different instruction
> set.  That's why you need to do the dex step before deploying your code
> on android.
>
> George Jahad did get a repl/eval to run on android some time ago.  See:
>
>  http://groups.google.com/group/clojure/browse_thread/thread/14725172c...
>
> And the revelant commit in his clojure fork:
>
>  http://github.com/GeorgeJahad/clojure-android/commit/9caf2913a2724c38...
>
> On 2010/05/29 05:44, MHOOO wrote:
>
> > I've got 1.2.0-master running on android froyo with a repl. Froyo
> > supports JIT compilation, but whenever I call code which is defining a
> > new class (e.g.: "(defn blub [] nil)"), I get an Exception:
> > -
> > clojure.core=> (defn blub [] 1)
> > java.lang.RuntimeException: java.lang.UnsupportedOperationException:
> > can't load this type of class file (NO_SOURCE_FILE:15)
> > clojure.core=>
> > -
> > And the following error inside the android logs:
> > -
> > E/dalvikvm(  522): ERROR: defineClass(0x43e6e188, clojure.core$blub,
> > 0x43f83a58, 0, 984, 0x0)
> > -
> > Am I doing something wrong/impossible or is there a way to fix this?
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Android 'dex' stage takes a very long time with Clojure

2010-05-29 Thread MHOOO
I'd like to try to compile the clojure code (i.e. its different parts
like .core, .main, .set, etc) into different .dex files so as to speed
up both compilation (since you'll only have to recompile those .dex
files which have changed) and start-up (since only those .dex files
are loaded which are needed during program runtime). However I'm not
quite sure where to hook into as I have only little understanding of
how clojure loads files. Is there a function somewhere in the java/
clojure side of the code which is responsible for finding a namespace
(possibly compiling it first) and loading it?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: do clojure and la(tex) have something in common ?

2010-05-29 Thread Perry Trolard


On May 28, 10:35 pm, Dave Pawson  wrote:
>
> Which Saxon have you wrapped please?
> saxon655 or Saxon9he?

Currently I'm wrapping the last Saxon 9B before the switch to the
three-way split. I plan to stick with it until there's a reason not
to; there are some features of B I'd rather not be without, like
saxon:eval() in stylesheets.

Best,
Perry

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: do clojure and la(tex) have something in common ?

2010-05-29 Thread Dave Pawson
On 29 May 2010 15:44, Perry Trolard  wrote:
>
>
> On May 28, 10:35 pm, Dave Pawson  wrote:
>>
>> Which Saxon have you wrapped please?
>> saxon655 or Saxon9he?
>
> Currently I'm wrapping the last Saxon 9B before the switch to the
> three-way split. I plan to stick with it until there's a reason not
> to; there are some features of B I'd rather not be without, like
> saxon:eval() in stylesheets.

eval will be in the new xslt 2.1, hence in the newer Saxon,
unless Mike Kay makes it a pay version.
3 way sounds good Perry.

regards



-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: How to reset a counter

2010-05-29 Thread Meikel Brandmeyer
Hi,

here an example using clojure sequence library.

(require 'clojure.contrib.seq-utils)

(doseq [[y vs] (indexed (partition 256 value))
[x v]  (indexed vs)]
   (write-buffer x y v))

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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: (apply interleave [[1 2]])

2010-05-29 Thread Michael Gardner
On May 29, 2010, at 5:07 AM, Paul Hobbs wrote:

> What code would this make simpler?  Are you constantly having to check this 
> special case?  If not, I don't see a reason to include it.

I haven't run across this particular issue, but I have many times written code 
that may end up calling a function with "degenerate" arguments in corner cases. 
I much prefer functions that handle such degenerate arguments gracefully when 
it makes sense to do so, which it absolutely does for interleave.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Suggession for your website

2010-05-29 Thread Nitin r vasnik vasnik

My name is Nitin Vasnik and I just happen to visit your Website. I
see  that your company's Website is good but the only thing lacking is
page ranking due to keywords. A good page ranking is very helpful in
getting more business.

We areElsner Media Marketing & we provide Seo Services. We have a
staff of 150+ employees working 24  hours Mon - Sat.We can increase
your page ranking and get you listed in the top ten of Google. We are
masters in Seo services, we can  increase traffic on your Website by -

1-Social Bookmarking.

2-Link building.

3-Article submission & many more tools.

If you are interested in our services than you can E-mail us at-
ni...@nettechno.com

Our Address:- Elsner Media Marketing  3,6,7 Shubh Complex near
Rajasthan Hospital Shahibaug Ahmedabad Gujrat India-380003

Our Contact No: (India )+919898944736

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Transient HashMaps with not more than 8 elements?

2010-05-29 Thread Daniel Borchmann
Hi,

recently I discovered the following behaviour of transient hash-maps
which seems a bit odd to me:

 user> (def thm (transient {}))
 #'user/thm
 user> (dotimes [i 10]
 (assoc! thm i i))
 nil
 user> (count thm)
 8
 user> (persistent! thm)
 {0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7} 

The same happens if i goes up to 100, 1000, ... Is this a bug or is
this a fundamental misconception of mine?

Daniel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Transient HashMaps with not more than 8 elements?

2010-05-29 Thread Jarkko Oranen


On May 30, 12:32 am, Daniel Borchmann
 wrote:

> The same happens if i goes up to 100, 1000, ... Is this a bug or is
> this a fundamental misconception of mine?

You're using them wrong. Transients are not imperative data
structures. You need to capture the return value of assoc! and use
that as the new transient.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Android 'dex' stage takes a very long time with Clojure

2010-05-29 Thread MHOOO
Well, that was easy enough. I modified the load function inside
RT.java to load classes/namespaces out of .dex files. (use
'my.compiled.namespace) will now look for either the compiled .class
(and load it), or it will look for a .clj (and compile & load it -
thanks to George Jahad's work), or it will look for a .dex file
("my.compiled.namespace.dex") inside the .apk and try to load the
class from there.
Charming!
I've already split clojure-master into several parts (.dex files for
core,main,zip,set,walk,xml,java,inspector,pprint,repl), so now the
next step would be to figure out how to get it all together and
integrate it with leiningen: Build clojure-master .dex files (<- done)
with a custom main (<- todo) which calls the users main android
activity (<- todo), package everything into an apk (<- done) and
install it on the emulator (<- done).

On May 29, 4:07 pm, MHOOO  wrote:
> I'd like to try to compile the clojure code (i.e. its different parts
> like .core, .main, .set, etc) into different .dex files so as to speed
> up both compilation (since you'll only have to recompile those .dex
> files which have changed) and start-up (since only those .dex files
> are loaded which are needed during program runtime). However I'm not
> quite sure where to hook into as I have only little understanding of
> how clojure loads files. Is there a function somewhere in the java/
> clojure side of the code which is responsible for finding a namespace
> (possibly compiling it first) and loading it?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: (apply interleave [[1 2]])

2010-05-29 Thread Eugen Dück
Paul,

I already gave a minimal example of the code it makes simpler, i.e.
work in the first place:

(apply interleave some-colls)

I ran into this a couple of times, and wrote my own variant of
interleave that handles the one-coll case. I'd rather see this case
handled by interleave.

How often do you do:

(+ 5)

or

(* 3)

? But you might have used something like

(apply + coll)

or

(reduce + coll)

and under certain circumstances your coll might have had only one
element. Still + works just fine and returns a value that makes sense
(it even does if you call it with no argument). I'm basically asking
to get the same case that clojure handles for a lot of other functions
added to "interleave".

Eugen

On May 29, 7:07 pm, Paul Hobbs  wrote:
> What code would this make simpler?  Are you constantly having to check this

> > (apply interleave some-colls)

> special case?  If not, I don't see a reason to include it.
> --
> Paul Hobbs
>
> On Sat, May 29, 2010 at 1:32 AM, Eugen Dück  wrote:
> > When I do
>
> > (apply interleave some-colls)
>
> > and some-colls is a sequence/collection of only one sequence/
> > collection, it will throw:
>
> > user=> (apply interleave [[1 2]])
> > java.lang.IllegalArgumentException: Wrong number of args passed to:
> > core$interleave (NO_SOURCE_FILE:0)
>
> > (Of course I don't need the apply to cause that exception, but calling
> > interleave directly with just one parameter doesn't make any sense.
> > But in the case you use apply, having only one sequence in a sequence
> > is a possible corner case that can arise "at run time")
>
> > In order to make interleave more general, I'd like to add a "one param
> > overload" to interleave like
>
> > (defn interleave
> >  "Returns a lazy seq of the first item in each coll, then the second
> > etc."
> >  ([c] (seq c))
> >  ...
>
> > or even just
>
> > (defn interleave
> >  ([c] c)
>
> > but that would break the contract of interleave, in that it returns
> > whatever you pass in, which might not be a sequence, as is the case in
> > my example.
>
> > Any thoughts on this?
>
> > Eugen
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Datatype Usage Examples

2010-05-29 Thread Adrian Cuthbertson
> That said, I'd rather make sure that my low-level data structures are being 
> operated on by only one implementation.

You could use closures to encapsulate the refs/atoms ...

(let [car-mem (ref nil)]
  (defn set-car-mem [new-car-mem]
 (dosync (ref-set car-mem new-car-mem)))
  (defn update-car-mem [new-car-mem]
 (dosync (set-car-mem new-car-mem)))
  (defn get-car-mem [] @car-mem))

user=> (set-car-mem 0)
user=> (get-car-mem)
0
user=> @car-mem
java.lang.Exception: Unable to resolve symbol: car-mem in this context
(NO_SOURCE_FILE:0)

(note that you need a do-sync around ref-set - your code didn't have one.)

-Rgds, Adrian

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Transient HashMaps with not more than 8 elements?

2010-05-29 Thread ataggart
Yup, you need to use the transient functions, e.g., assoc!, just as
you would the persistent functions.  This is nice since you can write
your code in the persistent style, then if you need to make some
performance tweaks, simply add some exclamation points; the structure
of the code remains the same.

As for why you see what you're seeing, the assoc! does generally
mutate the passed in map, thus you see some map entries.  The rub is
that assoc! is smart enough to choose the right implementation for the
size; for small maps (0-8 entries) an array-map is used (and the {}
literal is also an array-map).  Once you assoc! the 9th element, the
function instead returns a hashmap, thus no longer mutating the
instance referenced by thm.

On May 29, 2:41 pm, Jarkko Oranen  wrote:
> On May 30, 12:32 am, Daniel Borchmann
>
>  wrote:
> > The same happens if i goes up to 100, 1000, ... Is this a bug or is
> > this a fundamental misconception of mine?
>
> You're using them wrong. Transients are not imperative data
> structures. You need to capture the return value of assoc! and use
> that as the new transient.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: How to reset a counter

2010-05-29 Thread Adrian Cuthbertson
Also have a look at Christophe's excellent "Taming multidim Arrays"...

http://clj-me.cgrand.net/2009/10/15/multidim-arrays/

-Rgds, Adrian

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Transient HashMaps with not more than 8 elements?

2010-05-29 Thread Daniel Borchmann
On Sat, May 29, 2010 at 08:52:59PM -0700, ataggart wrote:
> Yup, you need to use the transient functions, e.g., assoc!, just as
> you would the persistent functions.  This is nice since you can write
> your code in the persistent style, then if you need to make some
> performance tweaks, simply add some exclamation points; the structure
> of the code remains the same.
> 
> As for why you see what you're seeing, the assoc! does generally
> mutate the passed in map, thus you see some map entries.  The rub is
> that assoc! is smart enough to choose the right implementation for the
> size; for small maps (0-8 entries) an array-map is used (and the {}
> literal is also an array-map).  Once you assoc! the 9th element, the
> function instead returns a hashmap, thus no longer mutating the
> instance referenced by thm.
Ah, yes:

  user> (loop [thm (transient {}),
   i 0]
  (if (<= 10 i)
(persistent! thm)
(recur (assoc! thm i i)
   (inc i
  {0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9}

So, a fundamental misconception of mine then ;)

Thanks!
Daniel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en