This is embarassing. ;-) Thanks
--
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
Hank,
Your last version does not work because your `if` condition is wrong, your
code stops on the first read ;)
Laurent
Le lundi 27 décembre 2021 à 21:34:05 UTC+1, hank@gmail.com a écrit :
> Ooops my bad, there's a typo in '(.toString sb1)' which sould be 'sb'.
> It doesn't change anythin
Ooops my bad, there's a typo in '(.toString sb1)' which sould be 'sb'.
It doesn't change anything, it still won't work, only Laurent's version
works.
user> (defn pt%% [file]
(let [afr (FileReader. file)
bfr (BufferedReader. afr)]
(loop [x (.read bfr)
sb (StringB
Hi --
Thanks so much, Laurent!
I was actually kind of close (you told me not to peep, so I didn't hehe).
(defn pt30 [file]
(def ^:dynamic *asb* (StringBuilder.))
(let [afr (FileReader. file)
bfr (BufferedReader. afr)]
(loop [x (.read bfr)
*asb* (StringBuilder
Hank,
Just a message to give you the solution [spoiler alert]
Don't read it, if you still want to search :)
SPOILER
SPOILER
;; ugly version using the fact that java objects are mutable in place
(defn ugly-read-chars-one-by-one
[reader]
(let [sb (StringBuilder.)]
Hi Hank,
That loop/recur is still wrong because `loop` set bindings to define names
and gives initial values but `recur` does *not set bindings*, it just
provides new values.
So `recur` does not need a vector of bindings like `loop`
The pattern is as follow:
(loop [a-local-var "initial-value"
Hi --
Thanks for taking the time to help me.
As far as I understand the examples, loop has this template:
loop [binding]
(condition
(statement)
(recur (binding)))
And in 'recur' the loop is re-executed with new bindings.
There was indeed an issue with the 'recur' outside 'when'. T
Hank
Your loop/recur in your pt5 function is still not good. Take the time to
read the loop/recur documentation and to understand examples.
A Clojure loop/recur is not really a loop like in other procedural
languages.
It is more akin to a new function call at the `loop` point with new args
pro
Hi,
In the quoted example the `recur` call is *inside* the `when` which is a
huge difference because there is in this case an halting condition to get
out of the loop ;)
regards
Laurent
Le dimanche 26 décembre 2021 à 14:41:15 UTC+1, hank@gmail.com a écrit :
> 2021-12-25, 21:11:46 UTC-3, La
2021-12-25, 21:11:46 UTC-3, LaurentJ wrote:
"Hi,
Your loop/recur usage is wrong, your error may be because your loop has no
halting condition."
Hi Laurent --
I actually took inspiration from one of the sources you posted:
(import '(javax.sound.sampled AudioSystem AudioFormat$Encoding))
(let [mp
Thanks, Harold.
You see, that was an exercise in Java interop - I know about slurp, but I
was trying to understand what was going on there.
-- Hank
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegro
Hank,
Welcome. Great efforts- it certainly seems like you're learning a lot, and
quickly.
`clojure.core/slurp` is related, in case you haven't seen it
yet: https://clojuredocs.org/clojure.core/slurp
The implementation may also be
enlightening:
https://github.com/clojure/clojure/blob/clojure-
Thank for the answers.
Trying to recur with '(recur (.read bfr))' resulted in a:
Syntax error (UnsupportedOperationException) compiling recur at
(*cider-repl ~:localhost:41097(clj)*:237:9).
Can only recur from tail position
So I changed the code (see below).
And now it complains that a previous
I think at least part of the problem is your use of val in the let
statement. Inside the loop, you're testing (not (= val -1)), but val is an
immutable value defined above the loop as being the first character read
from the buffer, so it will always loop until it reads in the 0xFFF
that makes
Hi,
Your loop/recur usage is wrong, your error may be because your loop has no
halting condition.
https://clojure.org/reference/special_forms#loop
https://clojuredocs.org/clojure.core/loop
Regards
Laurent
Le samedi 25 décembre 2021 à 20:23:37 UTC+1, hank@gmail.com a écrit :
>
> Hello --
>
Hello --
I'm learning Clojure and its Java interop stuff. I am trying to emulate
this function:
public String readAllCharsOneByOne(BufferedReader bufferedReader) throws
IOException {
StringBuilder content = new StringBuilder();
int value;
while ((value = bufferedReader.re
16 matches
Mail list logo