Hello World (Clojure)

From LiteratePrograms

Jump to: navigation, search
Other implementations: Ada | ALGOL 68 | Alice ML | Amiga E | Applescript | AspectJ | Assembly Intel x86 Linux | Assembly Intel x86 NetBSD | AWK | bash | BASIC | Batch files | C | C, Cairo | C, Xlib | Candle | Clojure | C++ | C# | Delphi | Dylan | E | Eiffel | Erlang | Forth | FORTRAN | Fortress | Go | Groovy | Haskell | Hume | IBM PC bootstrap | Inform 7 | Java | Java, Swing | JavaScript | LaTeX | Lisp | Logo | Lua | Maple | MATLAB | Mercury | OCaml/F Sharp | occam | Oz | Pascal | Perl | PHP | Pic | PIR | PLI | PostScript | Prolog | Python | Rexx | Ruby | Scala | Scheme | Seed7 | sh | Smalltalk | SQL | Standard ML | SVG | Tcl | Tcl Tk | Visual Basic | Visual Basic .NET | XSL

(Clojure)

There are a lot of different ways to print "Hello World" on the console.

All functions print the same string to the console, but there are some minor differences:

The following function prints the string and appends a newline.

<<hello.clj>>=
(println "Hello World")

This function just prints the string.

<<hello.clj>>=
(print "Hello World")

This function prints the string in READable form and appends a newline.

<<hello.clj>>=
(prn "Hello World")

This function just prints the string in READable form.

<<hello.clj>>=
(pr "Hello World")

The .. macro can be used to invoke methods in Java.

This prints the string by invoking System.out.println in Java.

<<hello.clj>>=
(.. System out (println "Hello World"))

In a REPL, this prints the string by invoking the write method on the *out* PrintStream.

<<hello.clj>>=
(.. *out* (write "Hello World"))

Then again, in a REPL, the string itself can be evaluated.

<<hello.clj>>=
"Hello World"
Download code
Views
Personal tools