Re: Land of lisp to Clojure

2014-07-12 Thread Cecil Westerhof
2014-07-09 5:11 GMT+02:00 Timothy Baldridge tbaldri...@gmail.com:

 Prefer vectors over quoted lists '(1 2) vs [1 2]. There's rarely a case
 (outside of macros) that you want the former.


​I did this mostly. The exception is:
(def nodes {
 :living-room   ['(You are in the living-room.)
 '(A wizard is snoring loudly on the couch.)]
 :garden['(You are in a beautiful garden.)
 '(There is a well in front of you.)]
 :attic ['(You are in the attic.)
 '(There is a giant welding torch in the corner.)]
 :dummy ['(Only for testing purposes.)]
 })

Because this is only accessed sequential, I would think it would be more
efficient as a list then as a vector. (It is certainly less work to enter.)
Or would a vector be here more efficient also?

-- 
Cecil Westerhof

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


Re: Land of lisp to Clojure

2014-07-09 Thread Cecil Westerhof
2014-07-09 2:24 GMT+02:00 Bruce Wang br...@brucewang.net:

 You might want to check out this
 https://github.com/quux00/land-of-lisp-in-clojure


​I will look into it. But I learn most if I do it myself. ;-)​


-- 
Cecil Westerhof

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


Re: Land of lisp to Clojure

2014-07-09 Thread Cecil Westerhof
2014-07-09 5:11 GMT+02:00 Timothy Baldridge tbaldri...@gmail.com:

 Prefer vectors over quoted lists '(1 2) vs [1 2]. There's rarely a case
 (outside of macros) that you want the former.

 Instead of quoted lists of symbols: '(You cannot get that.) try strings
 You cannot get that


​That is what Conrad uses. I would think that strings are much better also,
but he says that there is a good reason to use a quoted list of symbols.
And I have not finished the book yet. So maybe he is right.

​


 Don't use defs inside defs. Instead move the defs to a global position and
 then use binding or set-var-root! to set them.


​I was not happy with it, but did not know better. At the moment I get
binding and set-var-root! not working.

​


 Better yet, use atoms to hold their contents, even better yet, pass the
 game state into each function and have each function return a new game
 state.

 Instead of:

 (defn walk [direction]
   ...
   (def ^:dynamic *location* (first edge))

 Use atoms like this:

 (def location (atom nil))

 (defn walk [direction]
   ...
   (reset! location (first edge))


​Yep, that would be better. I al-ready use atom in error-in-datastruct-p,
so why not here?

​


 Once you replace symbol lists with strings, you can easily do this instead
 of syntax quoting:

 (str There is a  (nth edge 2)  going  (nth edge 1) from here)


​As said: that was my idea also. I just finish the book to see if there is
a real reason to use a quoted list. If not I replace it.



 On Tue, Jul 8, 2014 at 6:24 PM, Bruce Wang br...@brucewang.net wrote:

 Hi Cecil,

 You might want to check out this
 https://github.com/quux00/land-of-lisp-in-clojure

 Cheers,
 Bruce


 On Wed, Jul 9, 2014 at 9:49 AM, Cecil Westerhof cldwester...@gmail.com
 wrote:

 I received the book land of lisp as a gift. I am trying to translate it
 to Clojure. In chapter 5 there is a text game engine. In the attachment my
 translation. What do you think of it?

 There are a few problems.
 - 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?

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

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


-- 
Cecil Westerhof

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


Re: Land of lisp to Clojure

2014-07-09 Thread Cecil Westerhof
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.


Re: Land of lisp to Clojure

2014-07-09 Thread Cecil Westerhof
2014-07-09 9:39 GMT+02:00 Cecil Westerhof cldwester...@gmail.com:

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



​Solved it without reverting to stings. See attachment. The only 'problem'
are the parentheses. How to get rid of those?

​


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


​Got also rid of the dynamic variables.

-- 
Cecil Westerhof

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


land-of-lisp-text-game.clj
Description: Binary data


Re: Land of lisp to Clojure

2014-07-09 Thread Cecil Westerhof
2014-07-09 10:38 GMT+02:00 Cecil Westerhof cldwester...@gmail.com:

 2014-07-09 9:39 GMT+02:00 Cecil Westerhof cldwester...@gmail.com:

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



 ​Solved it without reverting to stings. See attachment. The only 'problem'
 are the parentheses. How to get rid of those?


​Solved that one also:
(defn look []
  (doseq [d (concat (describe-location @location nodes)
(describe-paths@location edges)
(describe-objects  @location objects object-locations))]
(apply println d)))

-- 
Cecil Westerhof

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


Re: Land of lisp to Clojure

2014-07-09 Thread John Mastro
Cecil Westerhof cldwester...@gmail.com wrote:
 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?

Nope, none that I've come across anyway. Dynamic variables can have very
surprising effects if you're not aware you're dealing with them. This is
more of an issue in Common Lisp than in Clojure because in CL you can
rebind both dynamic and lexical variables with `let`, whereas in Clojure
`let` always produces a lexical binding (`binding` creates dynamic
bindings). With Atoms, the worst that happens is you forget to deref one
and you get an NPE or whatever.

Land of Lisp sounds like a fun book. My books to read stack is pretty
massive but I'll get to it eventually.

All the best,

John

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


Land of lisp to Clojure

2014-07-08 Thread Cecil Westerhof
I received the book land of lisp as a gift. I am trying to translate it to
Clojure. In chapter 5 there is a text game engine. In the attachment my
translation. What do you think of it?

There are a few problems.
- 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?

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

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

-- 
Cecil Westerhof

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


land-of-lisp-text-game.clj
Description: Binary data


Re: Land of lisp to Clojure

2014-07-08 Thread Bruce Wang
Hi Cecil,

You might want to check out this
https://github.com/quux00/land-of-lisp-in-clojure

Cheers,
Bruce


On Wed, Jul 9, 2014 at 9:49 AM, Cecil Westerhof cldwester...@gmail.com
wrote:

 I received the book land of lisp as a gift. I am trying to translate it to
 Clojure. In chapter 5 there is a text game engine. In the attachment my
 translation. What do you think of it?

 There are a few problems.
 - 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?

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

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

 --
 Cecil Westerhof

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




-- 
simple is good
http://brucewang.net
http://twitter.com/number5

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


Re: Land of lisp to Clojure

2014-07-08 Thread Timothy Baldridge
A few notes:

Prefer vectors over quoted lists '(1 2) vs [1 2]. There's rarely a case
(outside of macros) that you want the former.

Instead of quoted lists of symbols: '(You cannot get that.) try strings
You cannot get that

Don't use defs inside defs. Instead move the defs to a global position and
then use binding or set-var-root! to set them. Better yet, use atoms to
hold their contents, even better yet, pass the game state into each
function and have each function return a new game state.

Instead of:

(defn walk [direction]
  ...
  (def ^:dynamic *location* (first edge))

Use atoms like this:

(def location (atom nil))

(defn walk [direction]
  ...
  (reset! location (first edge))


Once you replace symbol lists with strings, you can easily do this instead
of syntax quoting:

(str There is a  (nth edge 2)  going  (nth edge 1) from here)



That's all I have for now.

Timothy



On Tue, Jul 8, 2014 at 6:24 PM, Bruce Wang br...@brucewang.net wrote:

 Hi Cecil,

 You might want to check out this
 https://github.com/quux00/land-of-lisp-in-clojure

 Cheers,
 Bruce


 On Wed, Jul 9, 2014 at 9:49 AM, Cecil Westerhof cldwester...@gmail.com
 wrote:

 I received the book land of lisp as a gift. I am trying to translate it
 to Clojure. In chapter 5 there is a text game engine. In the attachment my
 translation. What do you think of it?

 There are a few problems.
 - 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?

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

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

 --
 Cecil Westerhof

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




 --
 simple is good
 http://brucewang.net
 http://twitter.com/number5

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




-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

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


Re: Land of lisp to Clojure

2014-07-08 Thread John Mastro
Hi Cecil,

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

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

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

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.

Hope that helps,

John

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