Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Clojure Design
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
Colour
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Undo
Redo
Keyboard Shortcuts Help
<p>A lot of things are 'rangeable'. Anything that has a logical 'next' to it can be a range. Since you can get an integer from a character by calling <code>int</code> on it, that applies to them as well. Thus, I wrote a char-range function that was promptly (and understandably) denied: <a href="http://dev.clojure.org/jira/browse/CLJ-717">http://dev.clojure.org/jira/browse/CLJ-717</a></p> <p>Stu makes some good points here:</p> <ul> <li>Performance. I'm not all that great with squeezing every ounce of performance out of things, thus my char-range function is probably the best you'll get from me. I don't know the real performance implications.</li> <li>If many things can be rangeable, they should probably be polymorphic.</li> <li>Are there things that might need to be rangeable in more than one way?</li> </ul> <p>I have some design ideas on of my own, mostly char-range specific:</p> <ul> <li>Should char-range's upper bound be exclusive? How intuitive and easy would that be to work with? It would mean that, to get the lower-case alphabet, you'd have to do <code>(char-range \a \\\{)</code> rather than <code>(char-range \a \z)</code>. That is awkward and unreadable. Ultimately, it's a difficult decision to make between consistency and usability.</li> <li>char-range should be as flexible as possible. The priority should be on ultimately flexibility and not how easy it is to get a range of lower-case and upper-case letters.</li> <li>Being polymorphic opens a huge can of worms. If we have a Rangeable protocol, none of the range functions can have a no-argument version. I imagine we'd have a 'range' function that would be a wrapper around the protocol. It's possible that, for no argument, this function could default to what the range function defaults to right now, which is a range of numbers from 0 to infinity.</li> <li>Being polymorphic also makes differences in behavior ugly. Inclusive vs exclusive will become a huge problem in all of this. Ruby gets away with this by making exclusive behavior optional with a default argument. We could possibly do something similar.</li> </ul> <p>Sorry for the first example's curly bracket not coming out right. It appears to be impossible to escape it and show a backslash in this markup language. If somebody else can manage it, please do so.</p> <p>My implementation is of a very Haskell-like range. In Haskell, to get a string of the lower-case and upper-case alphabet, you'd use two ranges.</p> <table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> Prelude> ['a'..'z'] ++ ['A'..'Z'] "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" </pre></td></tr></table> <p>And following that, my implementation was this:</p> <table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> (defn char-range "Returns a lazy seq of chars from start to end (inclusive), by step, where start defaults to Character/MIN_VALUE, step to 1, and end to Character/MAX_VALUE." ([] (char-range (Character/MIN_VALUE) (Character/MAX_VALUE) 1)) ([end] (char-range (Character/MIN_VALUE) end 1)) ([start end] (char-range start end 1)) ([start end step] (map char (range (int start) (inc (int end)) step)))) </pre></td></tr></table> <p>The above Haskell example translated to Clojure using char-range:</p> <table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> user=> (concat (char-range \a \z) (char-range \A \Z)) (\a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \y \z \A \B \C \D \E \F \G \H \I \J \K \L \M \N \O \P \Q \R \S \T \U \V \W \X \Y \Z) </pre></td></tr></table> <p>I did a little research into Ruby's ranges, and they appear to be extremely flexible (too flexible?) polymorphic ranges. Documentation is here: <a href="http://www.ruby-doc.org/core/classes/Range.html">http://www.ruby-doc.org/core/classes/Range.html</a></p>
Attachments
Labels
Location
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced