Rich Hickey | 1 Dec 2008 01:14
Picon
Gravatar

Re: infix operators


On Nov 30, 2008, at 5:47 PM, Randall R Schulz wrote:

>
> On Sunday 30 November 2008 13:30, André Thieme wrote:
>> ...
>>
>> Although a standard reader macro for infix syntax would be a nice
>> thing to have in Clojure.
>> ...
>
> Am I the only person who thinks this is a dead-end proposal that  
> should
> be dropped because our BDFL will simply not consider it?
>
>
> Rich? Will you let us know if this is something we can move on
> from 'cause you're simply not going to do it?
>

Yes please, move on. These things get proposed perennially for Lisps,  
but gain no traction because they are not in fact enhancements. People  
are free to write their own macros, but I'm not interested in infix  
for Clojure.

Rich

Chouser | 1 Dec 2008 01:47
Picon

Re: loop recur vs recursion


On Sun, Nov 30, 2008 at 5:52 PM, rzezeski <at> gmail.com <RZezeski <at> gmail.com> wrote:
>
> Any other solutions that would avoid a helper function?  Not just
> for my particular case, but anytime that one is calling recur from a
> catch clause?

Generally, collect the information you need from the catch clause and
return it to a context where recur can be called if needed.

(defn prompt-for-int [prompt junk-allowed default]
  (let [input (prompt-read prompt)
        num (try (Integer/valueOf input)
              (catch Exception _ :fail))]
    (if (= num :fail)
      (if junk-allowed
        default
        (recur prompt junk-allowed default))
      num)))

Note that the above ugliness is caused at least in part by a mismatch
between the Java API and Clojure idioms.  If 'Integer/valueOf' were a
Clojure function, I would expect nil to signal an error and any
Integer returned to be valid:

(defn parse-int [string]
  (try (Integer. string) (catch Exception _)))

This would allow for a much cleaner definition of prompt-for-int:

(Continue reading)

Chouser | 1 Dec 2008 02:03
Picon

Re: Help with xml-seq


On Sun, Nov 30, 2008 at 5:12 PM, Joel L <joel.leslie <at> gmail.com> wrote:
>
> I've hit a wall trying to work with tree like data structures,
> specifically the xml-seq.  I want to translate clojure.xml's xml
> representation into something close to compojure's html data
> structure.
>
> eg:
>  {:tag :div :attrs {:class "foo"}
>   :content
>    [{:tag :h1 :attrs nil :content ["Title"]}
>     {:tag :p :attrs nil :content ["Test"]}]}
>
> ->
>
>  [:div {:class "foo"} [:h1 "Title"] [:p "Test"]]

This has not been deeply tested:

(defn f [{:keys [tag attrs content] :as other}]
  (if tag
    (vec (concat [tag]
                 (when attrs [attrs])
                 (when-let [s (map f content)] (vec s))))
    other))

--Chouser

(Continue reading)

Joel L | 1 Dec 2008 02:26
Picon

Re: Help with xml-seq


Thanks! This is actually kinda close to a solution that I've just
managed to come up with, though mine is somehow twice as long :).
Correct me if I'm wrong, but this could eat up the stack when parsing
a large document?  I'm totally fine with it for my current needs,
though I'm curious to see a solution that doesn't.

Thanks again!
-Joel

On Dec 1, 1:03 am, Chouser <chou... <at> gmail.com> wrote:
> On Sun, Nov 30, 2008 at 5:12 PM, Joel L <joel.les... <at> gmail.com> wrote:
>
> > I've hit a wall trying to work with tree like data structures,
> > specifically the xml-seq.  I want to translate clojure.xml's xml
> > representation into something close to compojure's html data
> > structure.
>
> > eg:
> >  {:tag :div :attrs {:class "foo"}
> >   :content
> >    [{:tag :h1 :attrs nil :content ["Title"]}
> >     {:tag :p :attrs nil :content ["Test"]}]}
>
> > ->
>
> >  [:div {:class "foo"} [:h1 "Title"] [:p "Test"]]
>
> This has not been deeply tested:
>
(Continue reading)

harrison clarke | 1 Dec 2008 02:40
Picon

Re: quit

another issue would be that your function call would have to be on one line.
(the nested ones could have multiple lines, since they'd be in parens)

Chouser | 1 Dec 2008 02:49
Picon

Re: Help with xml-seq


On Sun, Nov 30, 2008 at 8:26 PM, Joel L <joel.leslie <at> gmail.com> wrote:
>
> Thanks! This is actually kinda close to a solution that I've just
> managed to come up with, though mine is somehow twice as long :).
> Correct me if I'm wrong, but this could eat up the stack when parsing
> a large document?  I'm totally fine with it for my current needs,
> though I'm curious to see a solution that doesn't.

Yes, "deep" documents could overflow the stack.  In general as long as
the stack depth mimics the actual depth of something else (like the
document) vs. translating iterations into stack depth, you'll be okay.
 That's no promise, of course, but building a nested structure like
this using only tail recursion sounds messier than I'd like to deal
with at the moment.  :-)

--Chouser

rzezeski@gmail.com | 1 Dec 2008 03:41
Picon

Re: loop recur vs recursion


On Nov 30, 7:47 pm, Chouser <chou... <at> gmail.com> wrote:
> On Sun, Nov 30, 2008 at 5:52 PM, rzeze... <at> gmail.com <RZeze... <at> gmail.com> wrote:
>
> > Any other solutions that would avoid a helper function?  Not just
> > for my particular case, but anytime that one is calling recur from a
> > catch clause?
>
> Generally, collect the information you need from the catch clause and
> return it to a context where recur can be called if needed.
>
> (defn prompt-for-int [prompt junk-allowed default]
>   (let [input (prompt-read prompt)
>         num (try (Integer/valueOf input)
>               (catch Exception _ :fail))]
>     (if (= num :fail)
>       (if junk-allowed
>         default
>         (recur prompt junk-allowed default))
>       num)))
>
> Note that the above ugliness is caused at least in part by a mismatch
> between the Java API and Clojure idioms.  If 'Integer/valueOf' were a
> Clojure function, I would expect nil to signal an error and any
> Integer returned to be valid:
>
> (defn parse-int [string]
>   (try (Integer. string) (catch Exception _)))
>
> This would allow for a much cleaner definition of prompt-for-int:
(Continue reading)

rzezeski@gmail.com | 1 Dec 2008 04:17
Picon

Re: Clojure at RubyConf


On Nov 30, 10:16 am, Paul Barry <pauljbar... <at> gmail.com> wrote:
> I just watched Jim Weirich's talk from RubyConf.  He does a good job
> of showing the basics of why concurrent programming is hard, and
> briefly talks about Erlang and Clojure at the end.  I recommend it to
> anyone interested in Clojure:
>
> http://rubyconf2008.confreaks.com/what-all-rubyist-should-know-about-...

Nice presentation.  It's a shame he didn't get to spend more time on
Erlang and Clojure.

Here is the URL at the end if anyone is interested:
git://github.com/jimweirich/presentation_enterprise_mom.git

It contains the Ruby, Erlang, and Clojure source.

-Ryan

Vincent Foley | 1 Dec 2008 04:32
Picon
Gravatar

abs function


It was mentioned in the IRC channel on 30-Nov-2008 by arohner that
java.lang.Math/abs did not work for ratios and bignums.  Here is a
simple patch to add an abs function into Clojure.

http://groups.google.com/group/clojure/web/abs.patch
samppi | 1 Dec 2008 05:36
Picon

Newbie: Flattening any collection


For any given collection [3 2 [3 5 1] 1 [3 4 1] 0], how may I get [3 2
3 5 1 1 3 4 1 0]?

Thanks in advance!

Gmane