[ANN] clj-peg

2009-07-03 Thread Richard Lyman
I'm a little apprehensive about sharing this project with others, but I
thought I might as well try.

I'm very interested in any feedback, but for now the license is a
bit-non-open.
There are modifications that I'm still wanting to make to the core before I
fully open the license.

Here's a bit of info:
 - clj-peg is intended to eventually support Parser Expression
Grammars(it
does a good job as is).
 - It's released as an AOT compiled pair of JARs (I'd love feedback on this
approach to distributing a Clojure library).
 - It is in _no_ way optimized. (I'm pretty sure current runtimes are
exponential in the worst case.)
 - The project page is at: http://www.lithinos.com/clj-peg/
 - An intro post is at: http://www.lithinos.com/Intro-to-clj-peg.html

A sample of the syntax that I'm currently using (though I'm really not happy
with it yet):
Expr  <- (=ast expr-ast (=s Sum (=e)))
Sum   <- (=ast sum-ast (=s Product (=* (=s SumOp Product
Product   <- (=ast product-ast (=s Value (=* (=s ProductOp Value
Value <- (=ast value-ast (=o Num (=s LParen Expr RParen)))
Num   <- (=ast num-ast (=+ NumChar))
SumOp <- #"^[+-]"
ProductOp <- #"^[*/]"
LParen<- "("
RParen<- ")"
NumChar   <- #"^[0-9]"

What does everyone think?

-Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Lazy sequence blows starck. Why?

2009-07-03 Thread David Cabana



On Jul 3, 11:11 pm, Gert Verhoog  wrote:

> This seems to work:
>
> (def triangle-numbers (lazy-cat [1] (map + (iterate inc 2) triangle-
> numbers)))
>
> cheers,
> gert

Gert,
Your proposed change works very well.

It's interesting that a (seemingly) small change makes a huge
difference in performance and correctness.  I'm new to clojure and
laziness, and will have to  mull this over. Thank you for your help.
It is much appreciated.
David
--~--~-~--~~~---~--~~
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: Lazy sequence blows starck. Why?

2009-07-03 Thread Gert Verhoog

On 4/07/2009, at 2:42 PM, David Cabana wrote:

> (defn triangle-numbers []
>  (lazy-cat [1] (map + (iterate inc 2) (triangle-numbers
>
> This second approach dies with a stack overflow. Can anyone shed some
> light on why?

The last (triangle-numbers) is recursive, but without loop/recur this  
consumes stack. Instead of defining a function, you might want to use  
def. This seems to work:

(def triangle-numbers (lazy-cat [1] (map + (iterate inc 2) triangle- 
numbers)))


cheers,
gert


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



conversation with Corey Haines

2009-07-03 Thread Stuart Halloway

Corey Haines, the touring software journeyman, recently spent a few  
days at Relevance (including a day pairing on a Clojure project). At  
the end, he videoed a conversation with me [1]. In Part 2 of the video  
we talk about Clojure.

The conversation does not go at all deep technically, but if you need  
something to show your manager that real people are using Clojure you  
might find it interesting.

[1] 
http://programmingtour.blogspot.com/2009/07/conversation-with-stuart-halloway.html

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



Lazy sequence blows starck. Why?

2009-07-03 Thread David Cabana

I'm working one of the Euler project problems, which asks for the
first triangle number with more than 500 divisors. I thought it might
be fun to use lazy sequences, and tried two approaches. One worked,
the other blew the stack. I'm trying to understand why the second
approach fails.

Here's the successful approach.

(defn tri [n]
  (* n (inc n) 1/2))

(defn triangle-numbers []
  (map tri (iterate inc 1)))

(take 1 (filter #(> (count-divisors %) 500)
(triangle-numbers)))

I have omitted the definition of count-divisors for the sake of
brevity. The failing approach is the same, except for an alternative
definition of the triangle numbers:

(defn triangle-numbers []
  (lazy-cat [1] (map + (iterate inc 2) (triangle-numbers

This second approach dies with a stack overflow. Can anyone shed some
light on why?

Thank you.
David Cabana
--~--~-~--~~~---~--~~
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: loneclojurian at ICFP programming contest

2009-07-03 Thread Robert Fischer

Jon Harrop wrote:
> Scala 
> feels like a minor departure from Java to me, and I am not a Java fan. In 
> fact, more like C# 3 than any real functional language

Don't say that too loud unless you're ready for a drawn-out flame war.

http://enfranchisedmind.com/blog/posts/scala-not-functional/

~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html

--~--~-~--~~~---~--~~
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: parsing program for nested parens and square brackets

2009-07-03 Thread carlitos


Probably the following is much less efficient than the other solutions
proposed, but I find it easier to understand (and if I didn't
misunderstand the problem it gives the right answer).

(defn simplify-1
  "remove adjacent pairs of opening/closing brackets"
  ([string] (simplify-1 "" string))
  ([prefix [a & [b & cdef :as bcdef]]]
 (cond (nil? a) prefix
   (#{"()" "[]"} (str a b)) (recur prefix cdef)
   :otherwise (recur (str prefix a) bcdef

(defn simplify [s]
  (let [ss (simplify-1 s)]
(if (= ss s) ss (recur ss

(defn balanced? [s]
  (empty? (simplify s)))

Cheers,

Carlos
--~--~-~--~~~---~--~~
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: loneclojurian at ICFP programming contest

2009-07-03 Thread Jon Harrop

On Thursday 02 July 2009 07:58:11 you wrote:
> I wonder if Jon Harrop is still planning to write Clojure for
> Scientists or Scala for Scientists or both?

I am certainly interested in writing both books. I reviewed Scala back in 2007 
and decided that it was not ready to be advocated. Perhaps things have 
progressed significantly since then but my impression is that Clojure is 
developing in a more productive direction and much more rapidly. I am also 
more interested in Clojure because it strives to be a genuine functional 
language rather than an OOP language with some odds and sods bolted on (Scala 
feels like a minor departure from Java to me, and I am not a Java fan. In 
fact, more like C# 3 than any real functional language) and because Clojure 
is designed with industrial use in mind rather than as an academic exercise. 
However, I have yet to give Clojure the thorough study that it deserves 
simply because I am tied up getting our F# products ready for its big release 
in 2010.

If anyone here is interested in a Clojure book aimed at technical users 
(scientists and engineers), please let me know.

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e

--~--~-~--~~~---~--~~
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: Displaying Clojure code on a Website

2009-07-03 Thread Rick Moynihan

Hi Kai,

2009/7/2 Kai :
> @Rick
>
> I got fairly far into this before I had problems with stack overflows.
> I found out later than I needed knowledge of trampoline and mutual
> recursion to solve the issue. I think the approach still has potential
> but the setback forced me to consider other options. This lead me to
> implement the stack local in the recursive definition of parse-code.

Thanks for your comprehensive answer.  I've read about
mutually-recursive functions but never really known where these issues
might occur in the wild outside of Stuart's discussion of trampolines
in Programming Clojure.  As I wrote my previous email I began to
suspect by the liberal recur's that this was the case (it's amazing
the amount of times through writing an email asking a question about
some code you stumble upon the solution), though I'm really glad
you've cleared this up for me.

Is it fair to say that you've made a trade off here?  i.e. it seems
you're trading off the costs associated with having a large function
definition against the less widely understood techniques of mutual
recursion and trampolining?  If so I'm inclined to agree that this is
a fair trade off, particularly because of the rhythmic nature of the
code and of course the fact that by using recur you're codifying a
guarantee to your readers that you're tail calling.

I am now curious as to whether or not this program would be clearer
with trampolines.

Thanks again for sharing and enlightening us with your discussion!

R.

--~--~-~--~~~---~--~~
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: loneclojurian at ICFP programming contest

2009-07-03 Thread Nicolas Oury
I suspect you are not using double arrays with direct array manipulation in
CLojure.
I wonder whether it is linked to the fact your arrays are not in local (let)
variables.

I will try to randomly change a few things in your implementation tomorrow.

Best,

Nicolas.


On Fri, Jul 3, 2009 at 9:56 PM, igorrumiha  wrote:

>
> On Jul 3, 4:30 pm, Shawn Hoover  wrote:
> > Interesting. Maybe I'm crazy, but when running java -server, replacing
> > vectors/assoc with arrays/aset slowed my project down from 4000
> > iterations/second to 100! Similarly, removing multimethods for each
> > instruction and loop/recur to churn through them and replacing with one
> big
> > fn generated up front resulted in a massive slowdown. I haven't profiled
> > yet, but I plan to do so because I'm so surprised by the results.
>
>
> Well, I did one more thing: implement the VM core in Java. Only the
> storage and the instructions. Quite ugly, one class, everything is
> public static final, and this thing is fast! I get ~65000 iterations/
> s. It would be interesting to find out why
>
> machine_data[pc] = machine_data[r1] + machine_data[r2];
>
> is so much faster than:
>
> (aset-double machine-data (+ (Array/getDouble machine-data r1) (Array/
> getDouble machine-data r2)))
>
> but I guess, at this level, it would involve comparing the generated
> JVM bytecode for each case but that is way over my capabilities at
> this moment.
>
> --
> IgorR
> >
>

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



OAuth libraries?

2009-07-03 Thread Michael Harrison (goodmike)

Howdy,

The DC Clojure Study Group is working on a mashup tool, with Yahoo
Pipes as an inspiration. I'm tasked with building a reader module to
read from Twitter, which uses OAuth. This led me to consider the
broader task of writing an OAuth library, and that led me immediately
to the hope that someone else already had.

Aside from a few teasing Tweets, I can't find any evidence of OAuth
libraries for Clojure. Anyone know of one or more? Anyone already
working on one?

Thanks!
Michael

P.S. Thank you, Stuart S, for the clojure-1.0-compatible branch of
clojure-contrib. I just updated to it, and it was painless. More time
for hacking!
--~--~-~--~~~---~--~~
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: loneclojurian at ICFP programming contest

2009-07-03 Thread igorrumiha

On Jul 3, 4:30 pm, Shawn Hoover  wrote:
> Interesting. Maybe I'm crazy, but when running java -server, replacing
> vectors/assoc with arrays/aset slowed my project down from 4000
> iterations/second to 100! Similarly, removing multimethods for each
> instruction and loop/recur to churn through them and replacing with one big
> fn generated up front resulted in a massive slowdown. I haven't profiled
> yet, but I plan to do so because I'm so surprised by the results.


Well, I did one more thing: implement the VM core in Java. Only the
storage and the instructions. Quite ugly, one class, everything is
public static final, and this thing is fast! I get ~65000 iterations/
s. It would be interesting to find out why

machine_data[pc] = machine_data[r1] + machine_data[r2];

is so much faster than:

(aset-double machine-data (+ (Array/getDouble machine-data r1) (Array/
getDouble machine-data r2)))

but I guess, at this level, it would involve comparing the generated
JVM bytecode for each case but that is way over my capabilities at
this moment.

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



NYC Clojure Users Group

2009-07-03 Thread Eric Thorsen

I setup a Meetup Group
http://www.meetup.com/Clojure-NYC

It would be great if people who might be interested in attending join
the group.  It's free.
I'm working on setting up our first meeting.
Please send me any thoughts on topics of interest, possible
presenters, etc.

Looking forward to meeting you!

Eric


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



Hiring full-time work-at-home clojure devs

2009-07-03 Thread dysinger

I probably should have titled this thread better so people would see
it...

"Hiring full-time work-at-home clojure devs" :D

On Jul 2, 9:39 am, dysinger  wrote:
> We need to hire some more devs full time to work on a clojure project
> (distributed backend hardcore clojure - not web dev).
>
> I would prefer to have someone in Seattle to work with Philip
> Hagelberg (technomancy on IRC).  This would be work from home salary
> employment w/ mac laptop provided (or if you prefer - your own
> laptop).
>
> If you feel you have clojure under your belt, please drop a resume w/
> a note on why you are awesome to j...@sonian.net  If you are involved
> in any open source code, please include links.
>
> ( Even if you don't live in Seattle but are still a clojure stud/ette
> don't hesitate to wave your arms. )
>
> :)
--~--~-~--~~~---~--~~
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: Clojure STM not serializable

2009-07-03 Thread Rich Hickey



On Jun 19, 2:44 pm, Rich Hickey  wrote:
> On Fri, Jun 19, 2009 at 9:35 AM, Eric Willigers wrote:
>
> > On Jun 18, 9:35 pm, Rich Hickey  wrote:
> >>http://clojure.org/refs
>
> >> point #8:
>
> >> "If a constraint on the validity of a value of a Ref that is being
> >> changed depends upon the simultaneous value of a Ref that is not being
> >> changed, that second Ref can be protected from modification by calling
> >> ensure. Refs 'ensured' this way will be protected (item #3), but don't
> >> change the world (item #2)."
>
> >> That describes your situation, and you can use 'ensure' to ensure the
> >> serializability of your reads.
>
> > Thanks, that was all very helpful. With ensure, there's no write skew.
>
> >> This is better than the "dummy write"
> >> solution in that multiple ensures of the same refs don't conflict.
>
> > I haven't been able to verify this part - are you refering to
> > Clojure's current implementation? In my experiment below using Clojure
> > 1.0.0, I'm seeing conflicts.
>
> They don't conflict, but you are correct that Clojure's STM currently
> doesn't leverage that fact. It is my intention that at some point it
> will, so please use ensure rather than dummy writes.
>

I've implemented overlapping ensure in the ensure branch:

http://github.com/richhickey/clojure/tree/ensure

Everyone using the STM please try it out.

Thanks,

Rich
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: loneclojurian at ICFP programming contest

2009-07-03 Thread Shawn Hoover
On Fri, Jul 3, 2009 at 9:29 AM, igorrumiha  wrote:

>
> On Jul 2, 7:13 pm, Nicolas Oury  wrote:
>
> You can also try to replace the arithmetic by unchecked arithmetic. (Is it
> > correct from the point of view of the semantic of the VM you are
> > implementing?).
>
> I didn't get to that yet because my profiling shows that the amount of
> time spent getting values from an array (even when using getDouble)
> surpasses by far the time spent in any other operation. Of course, my
> understanding of the JVM profiler logs may be wrong.
>

Interesting. Maybe I'm crazy, but when running java -server, replacing
vectors/assoc with arrays/aset slowed my project down from 4000
iterations/second to 100! Similarly, removing multimethods for each
instruction and loop/recur to churn through them and replacing with one big
fn generated up front resulted in a massive slowdown. I haven't profiled
yet, but I plan to do so because I'm so surprised by the results.

Shawn

--~--~-~--~~~---~--~~
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: parsing program for nested parens and square brackets

2009-07-03 Thread Laurent PETIT

2009/7/3 Christophe Grand :
> Hi all!
>
> On Thu, Jul 2, 2009 at 11:09 PM, Laurent PETIT 
> wrote:
>>
>> (def push conj)
>> (def closing-counterpart { \( \), \[ \] })
>> (def opening-char? closing-counterpart)
>> (defn matching-pair? [left right] (= right (closing-counterpart left)))
>>
>> (defn consume-one [stack c]
>>  (if (or (opening-char? c)
>>          (not (matching-pair? (peek stack) c)))
>>    (push stack c)
>>    (pop stack)))
>>
>> (defn balanced? [s]
>>  (empty? (reduce consume-one [] s)))
>>
>> (defn main []
>>  (apply print (map balanced? *command-line-args*)))
>>
>> (when *command-line-args*
>>  (main))
>
> I think you don't need opening-char?
>
> (defn balanced? [s]
>   (let [tr {\( \) \[ \]}]
>     (empty?
>   (reduce #(if (= (peek %1) %2)
>  (pop %1)
>  (conj %1 (tr %2))) [] s
>
> I push "transposed" characters on the stack, thus only \] \) or nil can be
> on the stack.
> Since nil isn't equal to a character, it will never be popped and thus it
> ensures the stack will not be empty.
>
>
>>
>> It's the second time I wish I had a version of reduce that allows to
>> quit the reduction early.
>
>
> You're not alone Laurent but I'm not sure that's a simple reduce-while is
> possible (I can't decide which values to test for early exit (accumulated
> result or accumulated result + item) and when (before or after calling the
> reducing function)).

Indeed, not easy to be general, concise and elegant at the same time here ...

What about:
"(reduce-until pred reductor init-acc coll)" ?
pred would be a function of acc (the accumulator) and i (next item from coll),
be executed before reductor,
and return
  * nil or false for continuing,
  * a vector with a specific return value (which could be acc or something else)
  * special meaning keyword :next for reduce-until to return the final
call of reductor on acc and i (this one could be got rid of, though ?)

e.g. :
my version would become

(defn consume-one [stack c]
 (cond
  (opening-char? c)   (push stack c)
  (matching-pair? (peek stack) c) (pop stack)))

(defn balanced? [s]
  (empty? (reduce-until #(when-not (consume-one %1 %2) [[:error]])
consume-one [] s)))

or yours:

(defn balanced? [s]
  (let [tr {\( \) \[ \]}]
(empty?
  (reduce-until (fn [acc v] (when (nil? (get acc 0 true)) [acc]))
#(if (= (peek %1) %2)
   (pop %1)
   (conj %1 (tr %2))) [] s

But all in all I don't find this is much a readability or
composability improvement ..., or is this ?

Regards,

-- 
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: loneclojurian at ICFP programming contest

2009-07-03 Thread igorrumiha

On Jul 2, 7:13 pm, Nicolas Oury  wrote:
> Hello,
> I just have a look at your code. I was wondering why reflect.Array/getDouble
> was faster than aget?

(aget arrayname) actually makes a call to java.lang.reflect.Array/get
which looks at the type of data in the array and then does the right
thing. Calling  java.lang.reflect.Array/getDouble directly saves the
time for type resolving (I guess) and gives me a 30% speedup.

> And I realized than you create arrays of objects and not array of doubles.
>
> Have you tried to replace make-array by double-array?

I'm using an equivalent of double-array:

user> (make-array Double/TYPE 5)
#
user> (double-array 5)
#
user>

> You can also try to replace the arithmetic by unchecked arithmetic. (Is it
> correct from the point of view of the semantic of the VM you are
> implementing?).

I didn't get to that yet because my profiling shows that the amount of
time spent getting values from an array (even when using getDouble)
surpasses by far the time spent in any other operation. Of course, my
understanding of the JVM profiler logs may be wrong.

> Can you try to check in your profiling whether the function you generate get
> compiled or not?

Looks like my function did not get compiled, here is the java -Xprof
log: http://paste.org/8811 On line 10 you can se the method
loneclojurian.ovm2$eval__3920$fn__3922.invoke. But you can see that
only 0.5% of time is spent in that function. Scroll down to line 44
and you will see the real time wasters:

54.9% 0  +  2413java.lang.reflect.Array.getDouble
21.0% 0  +   924java.lang.reflect.Array.setDouble

Looks like the JIT compiler decided it would be a waste of time to
compile my function and I agree.  :)

> What function are you running at the top level? Is that a loop where you run
> multiple times the same program?

This is the contents of benchmark.clj:

(require 'loneclojurian.ovm2)

(in-ns 'loneclojurian.ovm2)
(def machine (init-ovm "/path/to/bin1.obf"))
(defn one-run [] (machine) [(aget output-ports 0)
(aget output-ports 1)
(aget output-ports 2)
(aget output-ports 3)
(aget output-ports 4)])

(time (dotimes [_ 20] (one-run)))

So, init-ovm returns a function that executes the program, then I
define the one-run function that mimics the "real" usage of the VM:
execute the program once and then get the values of the first 5 output
ports (this is all related to problem 1).

So, I think the problem is that this approach of emulating computer
memory is quite resource hungry. Either a way needs to be found to
make these gets and sets really cheap or I need to rethink the
problem.

--
IgorR
--~--~-~--~~~---~--~~
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: NullPointerException in Compiler.java

2009-07-03 Thread Rich Hickey



On Jul 3, 5:27 am, jon  wrote:
> Hi, could Rich or someone knowledgeable look into this (reflection
> related?) NullPointerException in Compiler.java.
> I think it's either a bug or at least should provide a better error
> message, but I don't have any time to look deeper into it..
> Thanks, Jon
>
> -
> I was using clojure-1.0 but looks likely to still be a problem with
> the trunk.
>
> * compile the below java class and make available on classpath:
>    package mypkg;
>    public class MyClass {
>        public MyClass() {
>        }
>        Object myField;
>    }
>
> * then this line of clojure throws a NullPointerException:
>    (set! (.myField (mypkg.MyClass.)) "test")
>
> -
> When myField definition is private, as above, (or completely removed)
> the NullPointerException
> occurs. When you add 'public' to myField definition, the problem goes
> away..
>
> Looking at InstanceFieldExpr in Compiler.java (approx line 900)..
> the emit() and emitUnboxed() functions guard against 'field' being
> null
>    if(targetClass != null && field != null)
> but the emitAssign() function doesn't
>    if(targetClass != null)
> and therefore in this case field.getType() causes the
> NullPointerException

Fixed - thanks for the report:

http://www.assembla.com/spaces/clojure/tickets/142-Bug--Compile-time-NPE-on-set!-of-non-existent-field

RIch

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: parsing program for nested parens and square brackets

2009-07-03 Thread Christophe Grand
Hi all!

On Thu, Jul 2, 2009 at 11:09 PM, Laurent PETIT wrote:

> (def push conj)
> (def closing-counterpart { \( \), \[ \] })
> (def opening-char? closing-counterpart)
> (defn matching-pair? [left right] (= right (closing-counterpart left)))
>
> (defn consume-one [stack c]
>  (if (or (opening-char? c)
>  (not (matching-pair? (peek stack) c)))
>(push stack c)
>(pop stack)))
>
> (defn balanced? [s]
>  (empty? (reduce consume-one [] s)))
>
> (defn main []
>  (apply print (map balanced? *command-line-args*)))
>
> (when *command-line-args*
>  (main))
>

I think you don't need opening-char?

(defn balanced? [s]
  (let [tr {\( \) \[ \]}]
(empty?
  (reduce #(if (= (peek %1) %2)
 (pop %1)
 (conj %1 (tr %2))) [] s

I push "transposed" characters on the stack, thus only \] \) or nil can be
on the stack.
Since nil isn't equal to a character, it will never be popped and thus it
ensures the stack will not be empty.



> It's the second time I wish I had a version of reduce that allows to
> quit the reduction early.



You're not alone Laurent but I'm not sure that's a simple reduce-while is
possible (I can't decide which values to test for early exit (accumulated
result or accumulated result + item) and when (before or after calling the
reducing function)).



-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (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: print-base / print-radix?

2009-07-03 Thread Parth



On Jul 3, 11:25 am, Tom Faulhaber  wrote:
> Parth,
>
> I was thinking about this a little more today and I came up with a way
> to extend the pretty printer easily to support *print-radix* with a
> little wrapper. I'll try to get a chance to write it up for you
> tomorrow.
>
> Tom
>

Sounds perfect. Thanks very much :)

Regards,
Parth


> On Jul 2, 6:29 pm, Parth  wrote:
>
> > On Jul 3, 6:15 am, Parth  wrote:
>
> > > Tom, Chouser, Thanks for your responses.
>
> > > As of now I am doing the same thing as suggested.
> > > However, this tends be become painful the moment structures
> > > start to nest. For e.g. I am using Clojure to decode a bit
> > > of assembly and below is what I end up doing to see the
> > > values of interest in hex:
>
> > > user=> (decode :b32 (nth test-ops 3))
> > > {:inst {:prefix (), :code (199 69 248 10 0 0 0), :op :movl, :args
> > > [{:type :Ev-mem, :arg {:reg :ebp, :disp -8}} 10]}, :more ()}
> > > user=> (def r (decode :b32 (nth test-ops 3)))
> > > #'user/r
> > > user=> (map hex (get-in r [:inst :code]))
> > > ("c7" "45" "f8" "a" "0" "0" "0")
> > > user=> (hex (second (get-in r [:inst :args])))
> > > "a"
> > > user=>
>
> > > Basically, I need to extract each number seq or value
> > > individually and print it in hex for every instruction I
> > > decode and view.
>
> > > This isn't too much fun to do in the middle of  a debug session :)
>
> > > Having something like *print-base* would be ideal IMHO
> > > would make scenarios like this really easy as one could
> > > simply do:
>
> > > user=> (set! *print-base* 16)
> > > user=> (decode :b32 (nth test-ops 3))
> > > {:inst {:prefix (), :code (c7 47 f8 a 0 0 0), :op :movl, :args
> > > [{:type :Ev-mem, :arg {:reg :ebp, :disp f8}} a]}, :more ()}
>
> > > In the absence of this I thought of writing a function
> > > that would take an arbitrary Clojure structure/coll and print
> > > it out in the manner like above. But then it won't
> > > be much different from pprint with radix support but without
> > > the pretty part.
>
> > > I suppose what I am hoping is that a feature request for
> > > *print-base* sort of a mechanism get considered
> > > for Clojure as it makes scenarios like the above very
> > > easy to deal with. Any chance of this being somewhere
> > > on the Clojue todo? :)
>
> > Rich,
>
> > If this is something you think would be a good addition
> > to Clojure I could give a shot at creating a patch for
> > this (with a CA of course). Please let me know.
>
> > I think rather than a generic radix support, if
> > we have hex, bin and octal supported, most uses
> > cases should be covered.
>
> > Regards,
> > Parth
>
> > > I will probably create a poor mans radix based print
> > > in the mean time for the this scenario. That should
> > > be an interesting exercise.
>
> > > Thanks,
> > > Parth
>
> > > On Jul 2, 10:58 pm, Chouser  wrote:
>
> > > > On Thu, Jul 2, 2009 at 4:51 AM, Parth
>
> > > > Malwankar wrote:
>
> > > > > I frequently deal with hex and binary numbers.
> > > > > As of now when I need to view a list of numbers
> > > > > I just map a little hex function to it to translate it
> > > > > into a list of hex strings at the repl.
>
> > > > > Having something like *print-base* / *print-radix* [1] may be
> > > > > valuable in such a scenario
>
> > > > I don't think Java's built-in formatter is nearly as
> > > > flexible as those, but getting hex or octal strings is easy
> > > > enough:
>
> > > > user=> (format "%d" 255)
> > > > "255"
> > > > user=> (format "%o" 255)
> > > > "377"
> > > > user=> (format "%x" 255)
> > > > "ff"
> > > > user=> (format "%X" 255)
> > > > "FF"
>
> > > > --Chouser
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



NullPointerException in Compiler.java

2009-07-03 Thread jon

Hi, could Rich or someone knowledgeable look into this (reflection
related?) NullPointerException in Compiler.java.
I think it's either a bug or at least should provide a better error
message, but I don't have any time to look deeper into it..
Thanks, Jon

-
I was using clojure-1.0 but looks likely to still be a problem with
the trunk.

* compile the below java class and make available on classpath:
   package mypkg;
   public class MyClass {
   public MyClass() {
   }
   Object myField;
   }

* then this line of clojure throws a NullPointerException:
   (set! (.myField (mypkg.MyClass.)) "test")

-
When myField definition is private, as above, (or completely removed)
the NullPointerException
occurs. When you add 'public' to myField definition, the problem goes
away..

Looking at InstanceFieldExpr in Compiler.java (approx line 900)..
the emit() and emitUnboxed() functions guard against 'field' being
null
   if(targetClass != null && field != null)
but the emitAssign() function doesn't
   if(targetClass != null)
and therefore in this case field.getType() causes the
NullPointerException

--~--~-~--~~~---~--~~
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: parsing program for nested parens and square brackets

2009-07-03 Thread B Smith-Mannschott

On Fri, Jul 3, 2009 at 00:50, Laurent PETIT wrote:
>
> Hey, how come we did not see this even more concise version sooner ? :-):
>
> ;; using just clojure 1.0.0 without any additional library :-)
> ;; from command line:
> ;; java -cp clojure.jar /path/to/challenge2.clj "()" "((([[]])))" ... ...
> (ns challenge2)
>
> (defn balanced? [s]
>  (and
>    (every? #{ \( \) \[ \] } s)
>    (try (read-string s) true (catch java.lang.RuntimeException e false
>
> (defn main [] (apply print (map balanced? *command-line-args*)))
>
> (when *command-line-args* (main))
>
> Hehe

ROFL. :-D

Brilliantly punny solution.

// Ben

--~--~-~--~~~---~--~~
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: *command-line-args*

2009-07-03 Thread Emeka
Steve,

Could this be done such that  % java -cp /sq/ext/clojure/clojure.jar
clojure.main demo.clj foo bar baz  the highlighted part won't the there? But
would be ''attached'' behind the scene .

Regards,
Emeka

On Thu, Jul 2, 2009 at 6:17 PM, Stephen C. Gilardi  wrote:

>
> On Jul 2, 2009, at 2:00 PM, Mark Volkmann wrote:
>
>  I run it with "clj demo.clj foo bar baz" and get this output:
>>
>> clojure.lang.ArraySeq
>> 2
>>
>> I get the same output with "clj demo.clj -- foo bar baz".
>>
>> Why doesn't it output 3?
>>
>
> That depends on your definition of clj.
>
> Here's what I get without using a launcher script:
>
>  % java -cp /sq/ext/clojure/clojure.jar clojure.main demo.clj foo bar baz
>  clojure.lang.ArraySeq
>  3
>  (foo bar baz)
>
> (I added (println *command-line-args*) to my demo.clj. You might get some
> good info by adding it yours as well.)
>
> --Steve
>
>

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