Dan, I’m with James here. Your code as presented is really hard to read for 
folks used to the "standard Clojure style" - the strange layout of parentheses 
is very distracting. The use of underscore instead of hyphen is also a bit 
jarring.

I’m guessing your background is C/C++/Java and you think the standard Clojure 
style of formatting looks weird? You’ll get used to it. Especially if you set 
your editor up to auto-close / auto-match parentheses for you and use some sort 
of "rainbow parentheses" setting (so matching parens are the same color, and 
each matched pair is different to its neighbor).

(defn simplify 
  "Replace expression with simplified expressions, using
  {s-substring s-replace-character} map of replacements"
  [s-expr map-translations]
  (if (= (count s-expr) 1)
    s-expr
    (let [next-expr (reduce-kv clojure.string/replace s-expr map-translations)]
      (if (< (count next-expr))
        (count s-expr))
      (recur next-expr map-translations))))

Here's how that looks in my editor:

https://www.dropbox.com/s/fwyrn0k9vbtljs2/Screenshot%202014-11-23%2014.19.22.png?dl=0
 
<https://www.dropbox.com/s/fwyrn0k9vbtljs2/Screenshot%202014-11-23%2014.19.22.png?dl=0>

I think your < test is incorrect (now that I can clearly see the code): (< 
(count next-expr)) is always true and then you’re throwing away the value of 
the `if` (either (count s-expr) or nil since you have no then-expression). Did 
you mean this, perhaps?

      (if (< (count s-expr) (count next-expr))
        s-expr
        (recur next-expr map-translations))

Sean

On Nov 23, 2014, at 12:45 PM, James Reeves <ja...@booleanknot.com> wrote:
> I'd strongly suggest following standard Clojure formatting, otherwise you're 
> going to run into problems. If you use your own custom formatting that only 
> you can read easily, then people are going to find it very difficult to help 
> or collaborate with you. Deliberately putting up barriers to communication is 
> a strong incentive for people to pass over your posts - why should they have 
> to reformat your code just to understand it?
> 
> - James
> 
> On 23 November 2014 at 20:05, Dan Campbell <dcwhat...@gmail.com> wrote:
> 
> Yep, sure enough, works like a gem, thanks.  I had originally tried reduce, 
> but wasn't able to get it to work, in this context.  reduce-kv would have 
> saved a lot of time, on previous code.
> 
> 
> Sorry about the formatting, James.  I structure my code differently than the 
> standard Clojure format, and some of the tab sizes (2 or 3 spaces) got lost 
> in the copying & pasting.  Here's my final version, which works for several 
> input strings:
> 
> ; Credit to James Reeves
> (defn simplify 
>     "Replace expression with simplified expressions, using
>       { s_substring, s_replace-character } map of replacements
>     "
>     [ s_expr map_translations ]
>     (if (= (count s_expr) 1)
>       s_expr
>     (
>       let 
>         [ next-expr ( reduce-kv clojure.string/replace s_expr 
> map_translations )]
>         (if ( < (count next-expr) )
>           (count s_expr) 
>         )
>         (recur next-expr map_translations )
>     )  ; else let
>     )  ; if (= (count s_expr) 1)
> )


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