On Sun, Feb 22, 2009 at 1:34 PM, David Nolen <dnolen.li...@gmail.com> wrote:
> In general, I find that multiple arguments types for a function confusing.
> If dotimes is going to take multiple types it should be a multifn. That
> seems to imply a performance hit.
> I think Clojure wisely does not (or rarely does not?) allow for multiple
> types to be passed into a function.
> On top of that it's trivial to produce a macro on top of dotimes that does
> what you want that doesn't spend time checking the type of it's argument.

Really my main goal is to make Clojure code as easy to read as
possible. In this particular case, I think code like this:

(dotimes [n 3] (println "knock"))

leaves the reader wondering "What is the n for?".

Someone suggested this:

(dotimes [_ 3] (println "knock"))

That still seems like too much to read for what I'm getting.

OTOH, (dotimes 3 (println "knock")) isn't likely to confuse anybody.

Sure, I could get what I want by writing my own macro. The problem I
have with that is that I don't want to litter my code with calls to
custom macros that readers of my code have to figure out. I prefer to
use functions that readers will already be familiar with unless
introducing my own macros is going to significantly shorten the code.

> On Sat, Feb 21, 2009 at 11:10 PM, Mark Volkmann <r.mark.volkm...@gmail.com>
> wrote:
>>
>> On Sat, Feb 21, 2009 at 8:53 PM, André Thieme
>> <splendidl...@googlemail.com> wrote:
>> >
>> > On 21 Feb., 18:24, Mark Volkmann <r.mark.volkm...@gmail.com> wrote:
>> >> Currently the dotimes macro requires its first argument to be a vector
>> >> for binding a variable to the number of times the body should be
>> >> executed. Inside the body, that variable is bound to the values from 0
>> >> to that number minus 1. How about changing this macro to also accept
>> >> an integer as the first argument instead of a binding vector for cases
>> >> where the number isn't needed in the body.
>> >
>> > I don't find this very interesting.
>> > There several variants of how dotimes could be, but the one that we
>> > currently have is the one that is used since a few decades in Lisp,
>> > and it is the one that makes very much sense.
>> >
>> >> For example,
>> >>
>> >> (print "Santa says")
>> >> (dotimes 3 (print "Ho"))
>> >> (.flush *out*)
>> >
>> > (print "Santa saysHoHoHo")
>> >
>> > How often do you really want to repeat the same side effect many times
>> > in a row?
>> > Why does it hurt to just say (dotimes [i 100] ...)?
>> > This will not reduce readability dramatically, but is a consistant
>> > use of dotimes. It also does not reduce productivity.
>> > Why make a breaking change for this?
>>
>> Why do you say it would be a breaking change? I just got the following
>> to work with minimal changes to the dotimes macro.
>>
>> (dotimes 3 (println "Ho"))
>> (dotimes [n 4] (println n))
>>
>> So both forms work with a single macro definition.
>>
>> Here's what I did.
>>
>> 1) Wrap the body of the macro inside the following:
>>
>>  (let [new-bindings (if (integer? bindings) ['n bindings] bindings)]
>>    ...
>>  )
>>
>>  This creates the required binding when only an integer is passed and
>> using the supplied value for bindings otherwise.
>>
>> 2) Change every occurrence of "bindings" in the body to "new-bindings".
>>
>> 3) Move the (defmacro dotimes ... ) to just before (defn make-array ...).
>>    That's the first time it's used in core.clj and it will not be
>> after the definition of "integer?".
>>
>> Is there a reason to not make this change?

-- 
R. Mark Volkmann
Object Computing, Inc.

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

Reply via email to