Re: can't see the error

2011-09-27 Thread Dennis Haupt
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Am 27.09.2011 06:27, schrieb Baishampayan Ghose:
 i wasn't really trying to achieve anything useful - just messing 
 around and see where i get.
 
 now i'm here: (defrecord point [x y z]) (defn genPoints [n] (let
 [random (new Random) randomInt #(.nextInt random) randomPoint
 #(new point (randomInt) (randomInt) (randomInt))] (repeatedly n
 randomPoint)))
 
 is there a way to avoid writing (randomInt)(randomInt)(randomInt)
 and instead something like (magic (repeatedly 3 randomInt))?
 
 This is how I would write it -
 
 (defrecord Point [x y z])
 
 ;;; Only needed in pre Clojure 1.3.0 ;;; In Clojure 1.3.0, -Point
 will be generated automatically ;; (defn -Point ;;   [x y z] ;;
 (Point. x y z))
 
 (defn gen-points [n] (let [random (java.util.Random.) random-int
 #(.nextInt random) random-point #(apply -Point (repeatedly 3
 random-int))] (repeatedly n random-point)))
 
 Hope this helps.
 
 Regards, BG
 

yes it does :)

- -- 

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOght3AAoJENRtux+h35aG+AIP/j3ufGpS74wSSDv1RyAJjx2V
S7cdRuF4U00tanW1OAn/PYY93iT0wcXBgKowuo/jD9+C0TV5K7/he33KeSRrJCnb
vLEq8B1Um4JOc1V7MZZBaqtIfJcaQ3s5fcPtPdITX97dX79A3WSItU3/Fc+UYC2i
eF7p99dNLToF2KQhQPZ0Wb37gyIit/XExWiuTx8FIkNzLsL/cPQFMJpcG5Thw9pF
6EKImZOH2A6zOgO68nbynxV4D2vOW7VKkJb7B61XgRILf9bfLqspg/GmEeXaBTrp
gNXSbE7AFAHp6bA08nvydfr9H68z1H53i79mLxlDVXsq3MjGiHVddDa1SaG9SwwV
Vt7K0IndKqFonoI5WUj9CRnxWDoDhy35zwSolJOZhAjSSBHDdZCa9fa0BUU5HXu6
15z3RTG9nOk6OIQJeJiKNGaHtPdplJ0ugHFCDhLpsQZoG8z6QWT6n6BxDwRU9w3i
bEobBms8PqEsTWf1MmwJxLPyA/UC0wVKNiMdqheyydVZ/siGJzXN6fgJYFFUXPhT
KElmSJPeV6Ee56GG2ttDFSSblP+At2Kv3zJZQqUnbEhiu6a3L6ofrybTkaUjASWK
KXcnTYEy/ARi2lc+lD39pgM9YKJOOvgX9f3cGFe8mi4B1nZ5nlzrciyN3eJy8QaL
/MJvl1yQRxdWqQX1xLsQ
=vR6l
-END PGP SIGNATURE-

-- 
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: can't see the error

2011-09-26 Thread Dennis Haupt
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

i don't have the magic eye to spot the parenthesis-errors yet

Am 25.09.2011 22:15, schrieb Mark Rathwell:
 (let [rand (new java.util.Random) nextInt (fn [a] (.nextInt
 rand))] ((map (print) (iterate ((nextInt dummy) 0)
 
 extra parenthesis in three places, and the first argument to
 iterate is a function, not a long:
 
 (let [rand (new java.util.Random) nextInt (fn [a] (.nextInt
 rand))] (map print (iterate nextInt 0)))
 
 
 On Sun, Sep 25, 2011 at 3:51 PM, Dennis Haupt
 d.haup...@googlemail.com wrote: (let [rand (new java.util.Random)
 nextInt (fn [a] (.nextInt rand))] ((map (print) (iterate ((nextInt
 dummy) 0)
 
 
 the error is: java.lang.ClassCastException: java.lang.Integer
 cannot be cast to clojure.lang.IFn (NO_SOURCE_FILE:0)
 
 why does it want to cast my 0 to a function? and how can i get
 rid of the dummy parameter [a]?
 
 
 -- 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
 


- -- 

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOgLayAAoJENRtux+h35aG5UgQAJMV850ntNNio3g2HCcaVj4E
LH4KfnIhC0otFrEQQfHg3ha+mBuo9flt55NnHGMfEBNdxCTkfpm0SDzqt6QTKBRA
aGDDJuTyAbmnSvGnOkk60RRqeVS1QOErRyjzrMugNxguNQ5ZUKmZ5GeTndLHn0w0
g81CRfF0CSLD8j9ng98iJOdn/VwyijeATQo2b/DQhkyKHyFzlyGT3LXrRgWYAI5o
NbCzMC1K/0o9LPyP9TGBvOoRrKQ28WzMsJGWhV0bWNmsMzeZokE99UDSUvYpRM+f
OpyL/4MCkW6f1imGWzLpSBMHZqLSwkXX7U2fNrMGj1zi4knir/D3LF+aw5XLmkms
oS6IO5qnttQ1IHCsdC9nflYfk891CNEwgGS9jG7RPJ75Zls6VzYL6zT8V/RN1xr3
3s2fYVH2elIM1SVXphTRsY5bqw7xNa0Jti8ual9j5+t+HiQ8qyqX6Yxf6KQZ+9Ux
EkfpjjFw2Fh4JpJ9dYK1sOncho9j18TLE6afUuTLPYqPlhV5b0AcpPJ3XEA0ayef
U2Plapgp4Jxk6IMGAoMyD/fyaRkiOKIQw+TucWc4F2icX10LjVbM2eacyKLwvwPo
gmgGHfNyRj4dHOmRv40x9JheRiqJdXtuoWEks9wSY3D6sUS3qWNplCwfpJMWhIhT
Dc/HVQYRIunjZ+cGALHQ
=It6H
-END PGP SIGNATURE-

-- 
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: can't see the error

2011-09-26 Thread Dennis Haupt
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

i wasn't really trying to achieve anything useful - just messing
around and see where i get.

now i'm here:
(defrecord point [x y z])
(defn genPoints [n]
  (let [random (new Random)
randomInt #(.nextInt random)
randomPoint #(new point (randomInt) (randomInt) (randomInt))]
(repeatedly n randomPoint)))

is there a way to avoid writing (randomInt)(randomInt)(randomInt) and
instead something like (magic (repeatedly 3 randomInt))?

Am 25.09.2011 22:14, schrieb Baishampayan Ghose:
 On Mon, Sep 26, 2011 at 1:21 AM, Dennis Haupt
 d.haup...@googlemail.com wrote:
 (let [rand (new java.util.Random) nextInt (fn [a] (.nextInt
 rand))] ((map (print) (iterate ((nextInt dummy) 0)
 
 
 the error is: java.lang.ClassCastException: java.lang.Integer
 cannot be cast to clojure.lang.IFn (NO_SOURCE_FILE:0)
 
 why does it want to cast my 0 to a function? and how can i get
 rid of the dummy parameter [a]?
 
 You have too many parentheses in your code. The error is coming 
 because of the ``((nextInt dummy) 0)'' line where you are trying
 to call an integer (the result of calling nextInt on dummy) as a 
 function.
 
 I don't know what exactly you are trying to achieve here, but
 assuming that you want n consecutive pseudo-random integers, I
 would write it like this -
 
 (let [rnd (java.util.Random.) next-int #(.nextInt rnd)] (repeatedly
 10 next-int)) ; substitute 10 with desired number
 
 Regards, BG
 


- -- 

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOgO+8AAoJENRtux+h35aGF2kP/3MGVpxqqkax5O0kmX/Kh9u5
b48b6YrlgPwbSvTra2aqs+4rLF4U8mUUN82XyacB+PFAc6PeE3I8/aJudUvFO0RP
c8qL31NKPSm8RTvhPWzBejh2pyu1cP4qZtmgrSFfSan34n/oadfi0w8c1AjHsQqr
MVMMo2gY/U4J68wG2I7bNdbx3VT1OtmZlY04UBh5D9F6NXJ11+hEZLS89K32F6up
hi0EoruOxgeJnWDMLdTsKCUiSzlI8m6ZSlRVu8aj/xkdfcDXQhNVLp/UEmKhX355
wdkZm7VHHKop1c057vlXO8Fz6eUZ2E1RV3jf2osieg3Exj5s4cHncUES5cxZ14NF
6b0Avqxf69yX5ids2OOTaTqWrniRVqhf2KyDZGmgJfgwDyfLxMeephp/3glfYrbf
L3CIsXmjwebtFkwDm9LJvO8DXsOY+NU2ZgwfGCRqbwNxQU+0TMsGGgIypvD2rnM1
zAQE9kmcKLALLOwFcu6hN/OntpjtOk5e51hA7V/1oAk8H0BWOEKW1aYMggwoySgG
ti9BPg8MqyTBtZmqFUyOPFH3EQr8sEjRXpu2Wf1RxATShfNWwalqeOHbEhV/vJkO
SunWpUn/eqKaTzAq+ZI9VrWteMrmklHDlo7PhEwkp6JVFxUj3psfkQeqdY9fSRjz
Ei2jqCQXBMRO2CGEC/+R
=bKcz
-END PGP SIGNATURE-

-- 
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: can't see the error

2011-09-26 Thread Andy Fingerhut
This:

randomPoint #(apply new point (repeatedly 3 randomInt))

does not work, but is almost what you want.  It doesn't work because new is
a macro, and apply only works with functions as the first arg.

Using the following two lines, first to define a function, then to use it
with apply, seems like it ought to work.  Not sure whether it is magic
enough for you, though :-)

newpt #(new point %1 %2 %3)
randomPoint #(apply newpt (repeatedly 3 randomInt))

Andy


On Mon, Sep 26, 2011 at 3:49 PM, Jeremy Heiler jeremyhei...@gmail.comwrote:

 On Mon, Sep 26, 2011 at 5:33 PM, Dennis Haupt d.haup...@googlemail.com
 wrote:
  now i'm here:
  (defrecord point [x y z])
  (defn genPoints [n]
   (let [random (new Random)
 randomInt #(.nextInt random)
 randomPoint #(new point (randomInt) (randomInt) (randomInt))]
 (repeatedly n randomPoint)))
 
  is there a way to avoid writing (randomInt)(randomInt)(randomInt) and
  instead something like (magic (repeatedly 3 randomInt))?

 I'm not sure if this the best way, but it would work.

 (eval `(new point ~@(take 3 (repeatedly #(rand-int 10)

 --
 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: can't see the error

2011-09-26 Thread Baishampayan Ghose
 i wasn't really trying to achieve anything useful - just messing
 around and see where i get.

 now i'm here:
 (defrecord point [x y z])
 (defn genPoints [n]
  (let [random (new Random)
        randomInt #(.nextInt random)
        randomPoint #(new point (randomInt) (randomInt) (randomInt))]
    (repeatedly n randomPoint)))

 is there a way to avoid writing (randomInt)(randomInt)(randomInt) and
 instead something like (magic (repeatedly 3 randomInt))?

This is how I would write it -

(defrecord Point [x y z])

;;; Only needed in pre Clojure 1.3.0
;;; In Clojure 1.3.0, -Point will be generated automatically
;; (defn -Point
;;   [x y z]
;;   (Point. x y z))

(defn gen-points [n]
  (let [random (java.util.Random.)
random-int #(.nextInt random)
random-point #(apply -Point (repeatedly 3 random-int))]
(repeatedly n random-point)))

Hope this helps.

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at gmail.com

-- 
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: can't see the error

2011-09-25 Thread Daniel Solano Gomez
On Sun Sep 25 21:51 2011, Dennis Haupt wrote:
 (let [rand (new java.util.Random) nextInt (fn [a] (.nextInt rand))]
 ((map (print) (iterate ((nextInt dummy) 0)
 
 
 the error is:
 java.lang.ClassCastException: java.lang.Integer cannot be cast to
 clojure.lang.IFn (NO_SOURCE_FILE:0)
 
 why does it want to cast my 0 to a function? and how can i get rid
 of the dummy parameter [a]?

I don't think it's trying to cast your zero to a function.  Instead,
here's what I think is going on:

In this expression:

  ((nextInt dummy) 0) 

The inner expression gets evaluated to some integer.  The end result is:

  (some int 0)

And that is where an integer is trying to be invoked as a function.

Ultimately, I am not sure that 'iterate' is really the function you
want.  If you want an infinite lazy sequence of random integers, you
probably want something more like 'repeatedly':

(let [rand (java.util.Random.)
  nextInt #(.nextInt rand)]
  (map print (repeatedly nextInt)))

Note that this sequence, being infinite, will not terminate.  If you
only want to print the first five random numbers, you can do something
like:

(let [rand (java.util.Random.)
  nextInt #(.nextInt rand)]
  (map print (take 5 (repeatedly nextInt

I hope this helps.

Sincerely,

Daniel Solano Gómez


signature.asc
Description: Digital signature


Re: can't see the error

2011-09-25 Thread Baishampayan Ghose
On Mon, Sep 26, 2011 at 1:21 AM, Dennis Haupt d.haup...@googlemail.com wrote:
 (let [rand (new java.util.Random) nextInt (fn [a] (.nextInt rand))]
 ((map (print) (iterate ((nextInt dummy) 0)


 the error is:
 java.lang.ClassCastException: java.lang.Integer cannot be cast to
 clojure.lang.IFn (NO_SOURCE_FILE:0)

 why does it want to cast my 0 to a function? and how can i get rid
 of the dummy parameter [a]?

You have too many parentheses in your code. The error is coming
because of the ``((nextInt dummy) 0)'' line where you are trying to
call an integer (the result of calling nextInt on dummy) as a
function.

I don't know what exactly you are trying to achieve here, but assuming
that you want n consecutive pseudo-random integers, I would write it
like this -

(let [rnd (java.util.Random.)
   next-int #(.nextInt rnd)]
  (repeatedly 10 next-int)) ; substitute 10 with desired number

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at gmail.com

-- 
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: can't see the error

2011-09-25 Thread Mark Rathwell
 (let [rand (new java.util.Random) nextInt (fn [a] (.nextInt rand))]
 ((map (print) (iterate ((nextInt dummy) 0)

extra parenthesis in three places, and the first argument to iterate
is a function, not a long:

(let [rand (new java.util.Random) nextInt (fn [a] (.nextInt rand))]
  (map print (iterate nextInt 0)))


On Sun, Sep 25, 2011 at 3:51 PM, Dennis Haupt d.haup...@googlemail.com wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 (let [rand (new java.util.Random) nextInt (fn [a] (.nextInt rand))]
 ((map (print) (iterate ((nextInt dummy) 0)


 the error is:
 java.lang.ClassCastException: java.lang.Integer cannot be cast to
 clojure.lang.IFn (NO_SOURCE_FILE:0)

 why does it want to cast my 0 to a function? and how can i get rid
 of the dummy parameter [a]?

 -BEGIN PGP SIGNATURE-
 Version: GnuPG v2.0.14 (MingW32)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

 iQIcBAEBAgAGBQJOf4ZIAAoJENRtux+h35aG19UP/1tWgqcQifwUI5zHdkKWTcY8
 iY9vXGEr3IvTC2nB1yXJESJ6T/4OTpGhUT9ctX+6xGxPHFC9OPUdvnp5gGUOjCFQ
 Qa9G8Qc6Za1uc0HFzbWYxP9yi8TAPg1WVA3RF046kKuS/m9X8uUMtCulSJH8y6m4
 VmREcGlyQNjgCDMSRmMX5Y7vVuU2e6KoV6VjSopBHzX/sXBsMd0AZcnCRokBUKre
 7J1PyK3YKBmRLZ6gdvnOTz4kDBoKE7yrbh2gpIsQciqsawZ0wWYlBou7JceSxtN3
 Zwzm64YLxW8f6DjaRL7ZUAwTVMBkIru86hgm2bMK5pFX5f8bzBcmx09eIgd1fgLV
 c3bHtFYWzVrCRAGA+7iqeedQiFmkX2aK6yIcEma8KvoPXRlU5XhTiTN4B4sfPrpC
 qHM0U30WVIV05qs9E8rW2JDmpm1X7RpkZ9P3PEQXgYV1yJaSjPPyxRC1R0wi7f0o
 KUEXu+WO0egLyh3d8kfD1GMR/ztRGlS0UbJ3htqso710uD+R4GzFvRcitF99bQtm
 cOgz7sLB0hJTS3AblNhRzwt0CRdsPjHfBixrqbxGbXcLvkXFyoZMebuJwMZNcpzY
 wFhgEGyVxShXQASNub3dzNS8peU5fgoAGLexHh46e02K8a1YWjK3OOokZ3W9uCpt
 ghqI1/wkly1r9F/FroFo
 =+5YI
 -END PGP SIGNATURE-

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