Search code examples
clojure

Clojure: Is there an equivalent to Perl/Ruby's __DATA__ / __END__ special literals?


An example of this feature in Ruby:

# After the magic __END__, anything left in the file is treated as unescaped string data,
# which can be read from a file handle named DATA.
class Foo
  STUFF = DATA
  puts STUFF.read
end
__END__
This is the stuff!

Does Clojure have something similar?


Solution

  • For Clojure source code files, no.

    There are strings enclosed in double quotes that can contain newlines that do no need to be escaped, but several other special characters, and double quote characters, of course, that do need a backslash before them to escape them.

    There are regexes like #"foo.*bar" where you do not need to escape backslash characters, thankfully, since those are so prevalent in regexes.

    It is reasonably common to put long-ish strings into data files instead of source code.