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 provided by the `recur` call. If you continue with the function call metaphor The `loop` call defines 3 things: - the starting point of the function - the argument name of the function - the **initial values** of those arguments When you need to call again that function with new arguments, you use `recur` with **new values**. When you don't need to recur, well... dont call `recur` :) and just evaluate a last expression which is the result of the `loop` expression. regards Laurent Le dimanche 26 décembre 2021 à 02:35:47 UTC+1, [email protected] a écrit : > 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 form that was working '(.append > etc..') doesn't and the same error remains. > > user> (pt5 myfile) > > Execution error (IllegalArgumentException) at java.lang.Character/toChars > (Character.java:8572). > Not a valid Unicode code point: 0xFFFFFFFF > > (defn pt5 [file] > > (let [afr (FileReader. file); instances of FileReader, BufferedReader, > StringBuffer > bfr (BufferedReader. afr) > ct (StringBuilder.) > this-list (list afr bfr ct)] > ; (apply println this-list) > (loop [val (.read bfr)] > (when (not (= val -1)) > (.append ct (Character/toChars (.read bfr)))) > (recur val)) > ; when finished... > (.toString ct))) > > Harder then it seemed at first sight... > -- Hank > > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/66318891-e779-4a3c-818c-a235f7b32550n%40googlegroups.com.
