123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
- <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
- <head>
- <title>Introduction</title>
- <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
- <link rel="stylesheet" type="text/css" href="kawa.css"/>
- <script src="kawa-ebook.js" type="text/javascript"/>
- <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
- <link rel="prev" href="tutorial-index.xhtml" title="Kawa Scheme Tutorial"/>
- <link rel="next" href="tutorial-Booleans.xhtml" title="Booleans"/>
- </head>
- <body>
- <header/>
- <section class="sect1" title="Introduction" epub:type="subchapter" id="Tutorial---Introduction">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">Introduction</h2>
- </div>
- </div>
- </div>
- <p>You’ve heard about all the hot scripting languages
- – you might even be tired of hearing about them.
- But Kawa offers you something different than the
- scripting-language <span class="emphasis"><em>du-jour</em></span> can.
- You may be interested in one that runs on the Java virtual machine,
- either because you have to interact with other Java tools,
- or because you like having access to all the Java packages out there.
- Or maybe you don’t care about Java, but you care about performance.
- If so, let me tell you about Kawa, which is actually one of the
- very oldest language implementations running on the Java Virtual Machine,
- dating back to 1996.
- </p>
- <p>The Kawa language is a dialect/implementation of the Scheme language.
- (The Kawa project also supports other languages, including
- <a class="ulink" href="http://www.w3.org/XML/Query" target="_top">XQuery</a>
- and <a class="ulink" href="http://jemacs.sourceforge.net" target="_top">Emacs Lisp</a>,
- as well as tools for implementing mew programming languages,
- but we won’t cover that in this tutorial.)
- </p>
- <p><a class="ulink" href="http://www.schemers.org/" target="_top">Scheme</a>
- is an established language with many
- <a class="ulink" href="http://community.schemewiki.org/?scheme-faq-standards#implementations" target="_top">implementations</a>,
- a <a class="ulink" href="http://www.schemers.org/Documents/Standards/" target="_top">standard</a> specification
- (the traditional <a class="ulink" href="http://www.schemers.org/Documents/Standards/R5RS/" target="_top">R5RS</a>,
- <a class="ulink" href="http://www.r6rs.org/" target="_top">R6RS</a> which was ratified in 2007,
- and <a class="ulink" href="http://www.r7rs.org/" target="_top">R7RS</a> which was ratified in 2013),
- and is used by universities for both teaching and research.
- Scheme also has a reputation for being difficult to learn,
- with a weird parenthesis-heavy syntax,
- and hard-to-understand concepts like <a class="ulink" href="http://en.wikipedia.org/wiki/Continuation" target="_top">continuations</a>.
- Luckily, you don’t need to understand continuations!
- (Kawa doesn’t fully implement them anyway.)
- </p>
- <p>The following assumes that Kawa is already installed on your computer;
- if not see these <a class="link" href="Installation.xhtml" title="Getting and installing Kawa">installation instructions</a>.
- Running the <code class="literal">kawa</code> command in interactive mode
- is a good way start learning Kawa:
- </p>
- <pre class="screen"><span class="prompt">$ </span><strong class="userinput"><code>kawa</code></strong>
- <span class="prompt">#|kawa:1|# </span><strong class="userinput"><code/></strong>
- </pre>
- <p>If you don’t have <code class="literal">kawa</code> but you have a
- Kawa “jar” and you have Java installed you can instead do:
- </p>
- <pre class="screen"><span class="prompt">$ </span><strong class="userinput"><code>java -jar kawa-<em class="replaceable"><code>version-number</code></em>.jar</code></strong>
- <span class="prompt">#|kawa:1|# </span><strong class="userinput"><code/></strong>
- </pre>
- <p>The prompt string has the form of a Scheme comment,
- to make it easier to cut-and-paste.
- Kawa is expecting you type in an expression or command,
- which it will evaluate, and then print out the result.
- For example, a quoted string is a simple expression that evaluates to a
- string value, which will print as itself, before printing the next prompt:
- </p>
- <pre class="screen"><span class="prompt">#|kawa:1|# </span><strong class="userinput"><code>"Hello, world!"</code></strong>
- Hello, world!
- <span class="prompt">#|kawa:2|# </span><strong class="userinput"><code/></strong>
- </pre>
- <p>The most noticable difference from most other programming languages
- is that Scheme uses “prefix” notation for function calls.
- For example Kawa has a function <code class="literal">max</code> which returns the
- largest value of the arguments.
- Instead of <code class="literal">max(5, 7, 3)</code>
- you write <code class="literal">(max 5 7 3)</code>:
- </p>
- <pre class="screen">(max 5 7 3) ⇒ 7
- </pre>
- <p>(We use the <code class="literal">⇒</code> symbol above to indicate that
- the expression <code class="literal">(max 5 7 3)</code> evaluates to the
- value <code class="literal">7</code>.)
- </p>
- <p>The prefix notation may feel a bit weird, but you quickly
- get used to it, and it has some advantages.
- One is consistency: What are special infix operators in most languages
- are just regular functions in Scheme.
- For example, addition is just a regular function call,
- and <code class="literal">+</code> is just a regular function name:
- </p>
- <pre class="screen">(+ 2.5 1.2) ⇒ 3.7
- </pre>
- <p>The same prefix notation is used for special operations like assignments:
- </p>
- <pre class="screen"><span class="prompt">#|kawa:1|# </span><strong class="userinput"><code>(set! sqrt-of-2 (sqrt 2))</code></strong>
- <span class="prompt">#|kawa:2|# </span><strong class="userinput"><code>sqrt-of-2</code></strong>
- 1.4142135623730951
- </pre>
- </section>
- <footer>
- <div class="navfooter">
- <p>
- Up: <a accesskey="u" href="tutorial-index.xhtml">Kawa Scheme Tutorial</a></p>
- <p>
- Next: <a accesskey="n" href="tutorial-Booleans.xhtml">Booleans</a></p>
- </div>
- </footer>
- </body>
- </html>
|