2014-07-09 5:30 GMT+02:00 John Mastro <john.b.mas...@gmail.com>:

> Cecil Westerhof <cldwester...@gmail.com> wrote:
> > - The book displays all the lines of a look on separate lines. In my
> > case it is just one long line. Am I doing something wrong?
>
> No, you're not doing anything wrong. There's nothing in that data
> structure which would inherently cause it to print on multiple lines.
>
> If you're using Cider, you can enable automatic pretty-printing in the
> REPL, which would likely cause it to print on multiple lines. I think
> it's M-x cider-repl-toggle-pretty-printing.
>
> Or you could use a definition of look more like this, which uses println
> to print each item on its own line (not sure if you wanted to retain the
> parens or not, but both are easily doable).
>
>     (defn look []
>       (doseq [d [(describe-location *location* nodes)
>                  (describe-paths *location* edges)
>                  (describe-objects *location* objects *object-locations*)]]
>         (println d)))
>

​That certainly looks better. The only problem is that the lines of the
different calls are still printed as one. But rewriting to use strings
would solve that problem. I just have to finish the book, to see if I can
change the lists to strings.​



> - In Emacs Lisp you can use a function A in the definition of another
> > function B before you declared function A. Is it correct that this is
> > not possible in Clojure?
>
> Correct, though you can declare it without defining it, e.g.
> (declare function-a).
>

​OK, good to know.​




> > - Al variables in land of lisp begin and end with an asterisk. As I
> > understood it, you only do this for variables that can be changed. So
> > I renamed some variables. Did I understand this correctly, or is the
> > usage of asterisks for something else?
>
> The "earmuffs" convention is related to dynamic variables. All global
> variables are dynamic in Common Lisp, but that's not the case in
> Clojure. You're creating dynamic variables (by using :dynamic metadata
> in your defs) but I didn't notice anywhere where you're using this
> feature (i.e. no binding or set! forms). Long story short, I would use
> earmuffs if the variables are dynamic but not otherwise.
>

​I read a little about it. And no, I do not use dynamic binding. So I
probably should use atoms. Is there a convention how to name atoms?​




> Speaking of global variables, I'd recommend only using def at top level
> (it creates global vars regardless of where you use it). Perhaps it
> would work to initialize them at top level with a "null value", like
> (def something (atom nil)), and then set it later if/when appropriate,
> like (reset! something (first whatever)). As a plus, if you use
> atoms like this you most likely won't need dynamic variables, even if
> you need to start changing global variable values later on.
>

​Yep, I should do that.​




> Hope that helps,
>

​Certainly.

-- 
Cecil Westerho
​f​

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to