Re: Using goog.Timer from ClojureScript leads to compile error in advanced mode

2011-12-04 Thread Paul Richards
I don't understand why, but changing to a 'require' instead of a 'use'
fixed my problem:

(ns hello
(:require
[goog.Timer :as Timer]
[goog.dom :as dom]
[goog.events :as events]
[goog.events.EventType :as EventType]
[goog.events.KeyCodes :as KeyCodes]
[goog.graphics :as graphics]
[goog.graphics.Stroke :as Stroke]
[goog.graphics.SolidFill :as SolidFill]
[goog.graphics.Path :as Path]
))



On 3 December 2011 19:29, Paul Richards  wrote:
> Hi,
> I'm using goog.Timer inside my ClojureScript application.  When I
> compile using the non-optimizing cljsc the code compiles and the
> application works fine.  If I try to compile using the optimizing
> compiler however I get the following error:
>
> cljsc hello.cljs '{:optimizations :advanced}' > hello.js
> Dec 3, 2011 7:26:50 PM com.google.javascript.jscomp.LoggerErrorManager println
> SEVERE: hello:9: ERROR - required "goog" namespace never provided
> goog.require('goog');
>            ^
>
> Dec 3, 2011 7:26:50 PM com.google.javascript.jscomp.LoggerErrorManager
> printSummary
> WARNING: 1 error(s), 0 warning(s)
>
>
> My 'ns' line is as follows:
>
> (ns hello
>    (:use
>        [goog.dom :only [appendChild createDom createTextNode removeChildren]]
>        [goog.events :only [listen]]
>        [goog.events.EventType :only [CLICK]]
>        [goog.graphics :only [createGraphics Stroke SolidFill Path]]
>        [goog :only [Timer]]
>        ))
>
>
>
> --
> Paul Richards
> @pauldoo



-- 
Paul Richards
@pauldoo

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


Using goog.Timer from ClojureScript leads to compile error in advanced mode

2011-12-03 Thread Paul Richards
Hi,
I'm using goog.Timer inside my ClojureScript application.  When I
compile using the non-optimizing cljsc the code compiles and the
application works fine.  If I try to compile using the optimizing
compiler however I get the following error:

cljsc hello.cljs '{:optimizations :advanced}' > hello.js
Dec 3, 2011 7:26:50 PM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: hello:9: ERROR - required "goog" namespace never provided
goog.require('goog');
^

Dec 3, 2011 7:26:50 PM com.google.javascript.jscomp.LoggerErrorManager
printSummary
WARNING: 1 error(s), 0 warning(s)


My 'ns' line is as follows:

(ns hello
(:use
[goog.dom :only [appendChild createDom createTextNode removeChildren]]
[goog.events :only [listen]]
[goog.events.EventType :only [CLICK]]
[goog.graphics :only [createGraphics Stroke SolidFill Path]]
    [goog :only [Timer]]
))



-- 
Paul Richards
@pauldoo

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


ClojureScript: Should 'advanced optimizations' lead to faster execution? (or just faster loading)

2011-11-17 Thread Paul Richards
Hi,
I'm interested in the differences between the default ClojureScript
compile, and the {:optimizations :advanced} mode.

Aside from loading times (due to different file sizes) and memory
usage (again due to different file sizes, minified field names, etc),
do we expect the optimized version to execute faster?

It might be argued that the client side compiler in a modern
JavaScript engine will be capable of reproducing (at runtime) any of
the performance optimizations that the static compiler is able to
perform ahead of time.  Has anyone measured 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: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Paul Richards
On Sep 26, 6:04 pm, Benny Tsai  wrote:
> The reason that (rand-nth (seq (sorted-set 1 2 3))) performs badly on large
> sets is probably because nth is O(n) on sequences.  nth is much much faster
> on vectors, so I would suggest trying out (rand-nth (vec (sorted-set 1 2
> 3))) and see if that works for your application.

This will replace an O(n) call to "nth" with an O(n) call to copy into
a vector, so still leaving me with O(n).

-- 
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: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Paul Richards
On Sep 26, 6:13 pm, Jeremy Heiler  wrote:
> On Mon, Sep 26, 2011 at 9:12 AM, Paul Richards  
> wrote:
> > Hi,
> > How can I efficiently pick a random element from a sorted-set?
>
> > If I try rand-nth I get this:
> > user=> (rand-nth (sorted-set 1 2 3))
> > java.lang.UnsupportedOperationException: nth not supported on this
> > type: PersistentTreeSet (NO_SOURCE_FILE:0)
>
> > I can get this expression to work if I naively apply seq:
> > user=> (rand-nth (seq (sorted-set 1 2 3)))
> > 1
>
> > However this performs very badly on large sets.  Is there a more
> > efficient way to do this?
>
> > (I need to keep my elements in a sorted-set for other parts of the
> > application, where I rely on subseq.)
>
> Try just getting the value with rand-int directly. The sorted-set uses
> a tree map underneath, so look up time is consistent with a map. Also,
> count is O(1).
>
> (get foo (rand-int (count foo)))

I feel I picked a bad example.  My sorted-set does not contain
integers, the elements are (collections of) strings.  Trying this
approach leads to a different failure:

user=> (get (sorted-set "a" "b" "c") 1)
java.lang.ClassCastException: java.lang.String cannot be cast to
java.lang.Number (NO_SOURCE_FILE:0)

-- 
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: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Paul Richards
On Sep 26, 2:12 pm, Paul Richards  wrote:
> Hi,
> How can I efficiently pick a random element from a sorted-set?
>

I've come up with a bit of a hack, which relies on me not caring about
non-uniform distributions.  If I create a custom comparator with a
"random" backdoor, I can select random elements from the sorted set:

(defn my-comp [a b]
(if (or (= :random a) (= :random b))
(- (* 2 (rand-int 2)) 1)
(compare a b)))

; Create test collection (of strings) using the special comparator
(def coll (apply sorted-set-by my-comp (map str (range 1 1000

(map #(first (subseq coll > %)) ["500" "200" "700" :random :random])
; Result: ("501" "201" "701" "626" "286")



Bonus question..  What is the distribution of the random selection?

(I suspect elements will be chosen with some probability like (1/2)^H
(where H is the height of the element within the red-black tree).  I
should probably generate a histogram to find out..)

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


Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Paul Richards
Hi,
How can I efficiently pick a random element from a sorted-set?

If I try rand-nth I get this:
user=> (rand-nth (sorted-set 1 2 3))
java.lang.UnsupportedOperationException: nth not supported on this
type: PersistentTreeSet (NO_SOURCE_FILE:0)

I can get this expression to work if I naively apply seq:
user=> (rand-nth (seq (sorted-set 1 2 3)))
1

However this performs very badly on large sets.  Is there a more
efficient way to do this?

(I need to keep my elements in a sorted-set for other parts of the
application, where I rely on subseq.)

-- 
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 namespace conventions

2011-02-24 Thread Paul Richards
My goodness..  Seems like a can of worms.  :p

I think I'll pick something at least two levels deep like
"pauldoo.someproject", complete with ".core" and ".tools" as sub
namespaces..



On 23 February 2011 20:35, Mark Rathwell  wrote:
>
> This discussion has been had multiple times on this list, not sure how much
> new information you will get.  See the following for a couple examples:
> http://groups.google.com/group/clojure/browse_thread/thread/968e9066223c3a2b/fbce84869dbf4ce6?lnk=gst#
> http://groups.google.com/group/clojure/browse_thread/thread/78a32eeaacd659e/89304aeec4d00f7d?lnk=gst#
>
>
>
> On Wed, Feb 23, 2011 at 3:19 PM, Paul Richards 
> wrote:
>>
>> Hi,
>> Is there a guide to the conventions for naming and structuring
>> namespaces in a Clojure project?
>>
>> I see for example that the ".core" namespace is fairly common in
>> different projects.  Is this also where the "-main" entry point should
>> live?
>>
>> Also is it typical to have code living in "someproject" as well as
>> "someproject.tools", or should the former be promoted to
>> "someproject.core"?
>>
>>
>> --
>> Paul Richards
>> @pauldoo
>>
>> --
>> 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



-- 
Paul Richards
@pauldoo

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


Clojure namespace conventions

2011-02-23 Thread Paul Richards
Hi,
Is there a guide to the conventions for naming and structuring
namespaces in a Clojure project?

I see for example that the ".core" namespace is fairly common in
different projects.  Is this also where the "-main" entry point should
live?

Also is it typical to have code living in "someproject" as well as
"someproject.tools", or should the former be promoted to
"someproject.core"?


-- 
Paul Richards
@pauldoo

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


Docstring on def

2011-02-20 Thread Paul Richards
I've been trying to add docstrings to my constants that are defined
using 'def'.  According to the webpage[1] I should be able to write:

(def pi "hello" 3.14)

But this fails with:
java.lang.Exception: Too many arguments to def (NO_SOURCE_FILE:1)

This is with Clojure 1.2.0.


Note the slightly longer syntax works just fine, but this isn't picked
up by Marginalia. :/
user=> (def ^{:doc "hello"} pi 3.14)
#'user/pi
user=> (doc pi)
-
user/pi
nil
  hello
nil



1: 
http://clojure.org/special_forms#Special%20Forms--(def%20symbol%20doc-string?%20init?)


-- 
Paul Richards
@pauldoo

-- 
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: Wildcards on multimethod matching

2010-10-25 Thread Paul Richards
So in this particular case I wouldn't care, but in general I'd expect
the prefer-method stuff to kick in. :)



On 25 October 2010 10:54, Mark Nutter  wrote:
> I tried to have a go at this, but then I realized it's a bit difficult
> to specify. For example, if you have
>
> (defmethod bar [42 _] ..) ; and
> (defmethod bar [_ 16] ..)
>
> which one should be called when you give it (bar 42 16)?
>
> Mark
>
> On Sat, Oct 23, 2010 at 5:16 PM, Paul Richards  
> wrote:
>> Hi,
>> I have a multimethod which is dispatched on two arguments:
>>
>> (defmulti bar (fn [x y] [x y]))
>> (defmethod bar [1 2] ..)
>> (defmethod bar [3 4] ..)
>>
>> Is there a way I can define methods on this which use "wildcards"?
>>
>> E.g.:
>>
>> ; To match any call with 42 as the 1st argument
>> (defmethod bar [42 _] ..)
>>
>> ; To match any call with 16 as the 2nd argument
>> (defmethod bar [_ 16] ..)
>>
>> The above syntax doesn't seem to work, neither does using ':default'
>> in place of the '_'.
>>
>> If this is not possible, is there a common pattern I should implement 
>> instead?
>
> --
> 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



-- 
Paul Richards
@pauldoo

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


Wildcards on multimethod matching

2010-10-23 Thread Paul Richards
Hi,
I have a multimethod which is dispatched on two arguments:

(defmulti bar (fn [x y] [x y]))
(defmethod bar [1 2] ..)
(defmethod bar [3 4] ..)

Is there a way I can define methods on this which use "wildcards"?

E.g.:

; To match any call with 42 as the 1st argument
(defmethod bar [42 _] ..)

; To match any call with 16 as the 2nd argument
(defmethod bar [_ 16] ..)

The above syntax doesn't seem to work, neither does using ':default'
in place of the '_'.

If this is not possible, is there a common pattern I should implement instead?


-- 
Paul Richards
@pauldoo

-- 
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: Suspensions

2010-10-20 Thread Paul Richards
On 20 October 2010 21:21, Paul Richards  wrote:
> On 20 October 2010 20:45, Paul Richards  wrote:
>> On 20 October 2010 20:23, Alan  wrote:
>>> Augh no, future is not lazy; it's for multithreading. Try delay - it's
>>> identical to the (suspend) given by the OP.
>>>
>>> user=> (time (def x (delay (Thread/sleep 1
>>> "Elapsed time: 0.256312 msecs"
>>> #'user/x
>>> user=> (time (force x))
>>> "Elapsed time: 1.19261 msecs"
>>>
>>
>> This is perfect!  Thank you.
>>
>
> The only missing feature is that these aren't automatically forced by
> "println" and friends in the same way that lazy sequences are..  The
> force is explicit (which is nice for clarity really), but a pain when
> printing.
>

Please ignore this, I was printing the wrong thing.  The delay objects
print perfectly and show their forced values.

Apologies,

-- 
Paul Richards
@pauldoo

-- 
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: Suspensions

2010-10-20 Thread Paul Richards
On 20 October 2010 20:45, Paul Richards  wrote:
> On 20 October 2010 20:23, Alan  wrote:
>> Augh no, future is not lazy; it's for multithreading. Try delay - it's
>> identical to the (suspend) given by the OP.
>>
>> user=> (time (def x (delay (Thread/sleep 1
>> "Elapsed time: 0.256312 msecs"
>> #'user/x
>> user=> (time (force x))
>> "Elapsed time: 1.19261 msecs"
>>
>
> This is perfect!  Thank you.
>

The only missing feature is that these aren't automatically forced by
"println" and friends in the same way that lazy sequences are..  The
force is explicit (which is nice for clarity really), but a pain when
printing.


-- 
Paul Richards
@pauldoo

-- 
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: Suspensions

2010-10-20 Thread Paul Richards
On 20 October 2010 20:23, Alan  wrote:
> Augh no, future is not lazy; it's for multithreading. Try delay - it's
> identical to the (suspend) given by the OP.
>
> user=> (time (def x (delay (Thread/sleep 1
> "Elapsed time: 0.256312 msecs"
> #'user/x
> user=> (time (force x))
> "Elapsed time: 1.19261 msecs"
>

This is perfect!  Thank you.

I did some more playing and it memoizes the returned value too. :)


-- 
Paul Richards
@pauldoo

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


Suspensions

2010-10-20 Thread Paul Richards
Hi,..
Having just completed reading "Purely Functional Data Structures"
(Chris Okasaki), I'm keen to try things out in Clojure..  Something
used fairly often in the book is the notion of a suspension.  It's
effectively a way to mark an expression as being lazy and memoized.

I've not seen anything equivalent in Clojure, and I wonder if someone
knows how I can do it.  Effectively I'd like to write code as follows:

=> (var t (suspend (* 42 42)))  ; 42 * 42 will not be evaluated yet..

=> (force t)  ; Only now will 42 * 42 be evaluated..
1764

=> (force t)  ; Returns the memoized value, (* 42 42) is *not* re-evaluated
1764


In practice this would be used for heavier expressions than these.. :)

Also, it must act a bit like a closure in that it should capture the
context at creation time, making it possible to write a function which
returns a suspension.

=> (defn create-suspension [x] (suspend (* x x)))

=> (var t (create-suspension 3))

=> (var u (create-suspension 6))

=> (force t)
9

=> (let [x 100] (force u))  ; Uses previously captured value of 'x'..
36


Finally, I would not expect identical suspensions to automagically
find each other.

=> (var t (suspend (* 42 42))

=> (var u (suspend (* 42 42))

=> (force t)  ; (* 42 42) will be evaluated and memoized
1764

=> (force u)  ; (* 42 42) will be evaluated again and memoized separately
1764


Any hints would be appreciated, I suspect there may be some way to
hack this using lazy-seq.


-- 
Paul Richards
@pauldoo

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


Access function argument from outer anonymous function

2010-07-22 Thread Paul Richards
When I use the reader macro for anonymous functions I can use "%" to
access the function argument:

#(... % ...)

This is great.  When I nest these however:

#(.. #(.. % ..) )

Is there a way to access the function argument for the outer anonymous
function from inside the inner one?

E.g, it would be handy if "%" was rebound to "%%" (or some other magic).

At the moment I've had to convert my outer anonymous function to use
(fn [x] ..) style to allow me to use "%" and "x" inside the inner
anonymous function.


-- 
Paul Richards
@pauldoo

-- 
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: Why does using a dynamic binding make a function impure?

2010-07-20 Thread Paul Richards
On 19 July 2010 20:42, Brenton  wrote:
> Hi Paul,
>
> Pure functions have two properties: they cannot produce side effects
> and the return value is a function (in the mathematical sense) of its
> arguments and nothing else. There are two corresponding questions that
> you can ask when looking at a function to determine if it is pure.
>
> 1) When I call this function with the same arguments, do I always get
> the same result?
> 2) Is it true that the only reason you would ever call this function
> is to obtain the value that is returned from it?
>
> If the answer to both of these questions is Yes, then you are looking
> at a pure function.



So back to my example:

(def forty-two 42)

(defn func [] (* forty-two forty-two))

(defn other-func [] (binding [forty-two 6] (func)))


"func" is impure, and "other-func" is pure.  It's really nothing to do
with whether the "binding" keyword is used in the function...  I think
I took the sentence from the book too literally.



[snip]
> The earmuffs are the idiomatic Clojure way of indicating that
> something is intended to be dynamically bound. The caller must bind
> *something* to a value or this code will not work. This is what
> "Programming Clojure" means when it states: "Functions that use
> dynamic bindings are not pure functions..", it is not referring to
> functions which use binding internally (as in your example) but to
> functions which depend on values that are dynamically bound outside of
> said function.
>
[snip]

Pefect, thank you.  :)


-- 
Paul Richards
@pauldoo

-- 
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: Why does using a dynamic binding make a function impure?

2010-07-19 Thread Paul Richards
On 17 July 2010 23:57, Laurent PETIT  wrote:
> Hi,
>
> 2010/7/17 Paul Richards 
>>
>> The "Programming Clojure" book states: "Functions that use dynamic
>> bindings are not pure functions.."  (P2.0, page 174).
>>
>> I do not understand why this must be the case, can someone explain why?
>
> Because then the result of the function does not *only* depend on its input
> arguments.
>

Hm, I'm still a little confused..

Are you saying that if a function make use of any value which is def'd
from outside, then it is not pure functional?

In this small example:

(def forty-two 42)

(defn func [] (* forty-two forty-two))

(defn other-func [] (binding [forty-two 6] (func)))


In this example, which of these functions would be considered side
effect free, and which would be considered pure functional?  Is it the
case that both are side effect free, but only "other-func" is pure?
(This would seem to go against what the book says)

According to the book "other-func" is impure (since it uses "binding"
- aka dynamic bindings)..  Yet in this example it seems more pure than
"func".


-- 
Paul Richards
@pauldoo

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


Why does using a dynamic binding make a function impure?

2010-07-17 Thread Paul Richards
The "Programming Clojure" book states: "Functions that use dynamic
bindings are not pure functions.."  (P2.0, page 174).

I do not understand why this must be the case, can someone explain why?


PS.  I tried to post this on the discussion page for the book
(http://forums.pragprog.com/forums/91), but I could not register and
login correctly.

-- 
Paul Richards
@pauldoo

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


Clojure REPL prompt Java applet

2010-07-14 Thread Paul Richards
Does there exist a Java applet on the web which just presents an
interactive Clojure REPL prompt?

It would be a nice way to tinker with Clojure without downloading or
installing anything.


-- 
Paul Richards
@pauldoo

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


Executable clojure scripts (#!/usr/bin/env clj)

2010-07-13 Thread Paul Richards
I'm new to Clojure, and I've found it possible to make Clojure scripts
executable by adding '#!/usr/bin/env clj' as the first line (and
'chmod +x' of course).

E.g. My sample script:

#!/usr/bin/env clj

(println "Hello World")



This seems like a very convenient way to dabble with Clojure, yet I
have not seen it suggested anywhere.  Is this method discouraged?



-- 
Paul Richards
@pauldoo

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