heredoc?

52 views
Skip to first unread message

Robin

unread,
Mar 21, 2008, 2:09:42 PM3/21/08
to Clojure
I was wondering if it fits into Clojure's design to include heredoc
syntax?

Or even let the user select an alternative quote character like
Ruby's: %q{this is a "special" string}

Remembering to escape special characters in strings can be repetitive
and error prone.

Could this be accomplished with a normal macro, or would this require
adding the feature to the reader?

thanks,

Robin

Rich Hickey

unread,
Mar 24, 2008, 10:04:30 AM3/24/08
to Clojure
It would require reader support. I understand the problem, but am
concerned about user-defined-delimiters producing unreadable code.
It's also an editor burden.

Rich

Robin

unread,
Mar 24, 2008, 11:02:53 AM3/24/08
to Clojure
That's true people could make unreadable code.

What about Python's """? It could solve the quoting problem and still
be very readable.

What about string templates and expansions?

Like Ruby's: "this is a #{template} string"

Would something like this be possible?: `"this is a ~template string"

toString() would be called on template returning a String.

Just an idea,

Robin

Rich Hickey

unread,
Mar 24, 2008, 1:21:11 PM3/24/08
to Clojure


On Mar 24, 11:02 am, Robin <robi...@gmail.com> wrote:
> That's true people could make unreadable code.
>
> What about Python's """? It could solve the quoting problem and still
> be very readable.
>

That's one alternative I'm considering.

> What about string templates and expansions?
>
> Like Ruby's: "this is a #{template} string"
>
> Would something like this be possible?: `"this is a ~template string"
>
> toString() would be called on template returning a String.

String interpolation has also been proposed - I think any system must
be delimited, like the Ruby example, else the interpolated string must
be followed by a space.

Rich

Robin

unread,
Mar 24, 2008, 1:35:32 PM3/24/08
to Clojure
String interpolation could be done via fn or macro no?

(defn template [] "foo")
(interpolate """this is a "~(template)" string""")
=> "this is a \"foo\" string"

Folks could use the interpolation that suits the task, or write their
own without touching the Reader.

Robin
Reply all
Reply to author
Forward
0 new messages