(Arne Babenhauserheide)
2015-03-19: merge SRFI draft, curly-infix by default, REPL delayed output fix, stable v0.8.2 merge SRFI draft, curly-infix by default, REPL delayed output fix, examples, tests and generalized shell-call.
diff --git a/.bugs/bugs b/.bugs/bugs --- a/.bugs/bugs +++ b/.bugs/bugs @@ -12,6 +12,7 @@ wisp: handle general paren prefixes like throw an exception when reducing indentation to an unknown indentation level. | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:424186bd85f186b7279c5c59e2bd42f847284719, time:1376003568.91 wisp-in-wisp: only parses the first 272 lines, for some reason. | owner:, open:False, id:4cb6c556d7136609e2da9ab3fc045a39847f1ef3, time:1377014682.98 adjust runtests.sh to use testrunner.w | owner:, open:False, id:4d4e76343fe09f0ec72a3e5eb0077bd16e12f9d5, time:1415127234.43 +wisp-scheme: REPL: sometimes the output of a command is only shown after typing the next non-empty line. | owner:, open:False, id:56d2f81e9c89accb0b0bc668ddc8feed3b60e9b2, time:1416584789.23 implement wisp in wisp | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:6299306916706410702029289bf32edab1e7f17c, time:1367113341.49 support other types of brackets, like square brackets. | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:6749f3abcb9455eac9271efd8265797bce114239, time:1389134151.98 linebreaks in parens still break | owner:, open:False, id:6797987c7834a53358fb4ebbd8b9b36c2c4a8f01, time:1379004764.14 @@ -19,7 +20,9 @@ wisp-guile.w does not yet remove the lea inline ' : should be '( | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:72d534a8b23b4cb168017f1bb7d8816f0ea170c4, time:1366497335.26 failing test tests/shebang.w | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:74a851f83af8996465a7b24d8453161beb0f0fd5, time:1379106761.57 non-nested multiline comments with #! !#. Requires restructuring. | owner:, open:False, id:7a57614fa920b2ddad002d044b144d0bb7c34f84, time:1389364108.01 +wisp-scheme: interpret , : as ,() similar to : , | owner:Arne Babenhauserheide <bab@draketo.de>, open:True, id:85e150dcb10c49d8f51db525e07d24e83bdba0f1, time:1416432201.21 wisp-guile: support nested multi-line comments with #| ... |#: multiline comments (srfi-30). Requires restructuring. | owner:Arne Babenhauserheide <bab@draketo.de>, open:True, id:8cf6202873d4454f57813dd17cf60432059f7c62, time:1389569421.6 +wisp-scheme: Does not recognize the . #!curly-infix request for curly-infix or other reader syntax. | owner:Arne Babenhauserheide <bab@draketo.de>, open:True, id:91f27adb7d4e378e034b3408b6e4616f707f9587, time:1418162368.88 wisp-guile: the repl does not require 3 returns when you use a single char as function, or rather only does so every second time | owner:, open:True, id:9cedd0bdbf4a3b17add4bfe86ad5a23e500cfc6c, time:1379064870.78 wisp-guile.w breaks on ";" and complex brackets with bracket char literals. See wisp-guile.w::91 | owner:, open:False, id:9d8b6f87fa5365733fc8655614dbf2a9ba5bd054, time:1377533321.27 wisp-scheme: treat quote quasiquote syntax quasisyntax and so on similar to the dot. | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:9e587f38115099c0825c13a2159605e5f560aeec, time:1413623986.49 diff --git a/NEWS b/NEWS --- a/NEWS +++ b/NEWS @@ -1,3 +1,18 @@ +wisp 0.8.2 (2015-03-18): +- resolve REPL delayed output bug. +- forbid dot at the end of a line and as only symbol in a line to reserve them for future use. +- generalized the shell-call to guile: It gets the parentdir from $0. +- note curly braces, neoteric expressions and dual-wisp-sweet syntax. +- added tests: sxml, self-referencial function, curly-infix. +- new example: beautiful factorial. +- new example: ensemble estimation with ensemble square root filter. Uses python driven by an output-pipe as a plotting tool. +- SRFI 119 in draft. + +wisp 0.8.1 (2014-11-19): +- srfi: polish implementation notes. +- add the requirements to the syntax-examples. +- wisp-scheme.w works completely again. + wisp 0.8.0 (2014-11-03): - the testsuite is defined in terms of the code-tree, not in terms of the readable file. Implemented in testrunner.w diff --git a/README b/README --- a/README +++ b/README @@ -4,18 +4,21 @@ Wisp: Whitespace to Lisp define : hello (define (hello) display "Hello World" ⇒ (display "Hello World")) +<a name="fibonacci"></a> define : fibonacci n (define (fibonacci n) let rek : (i 0) (u 1) (v 1) (let rek ((i 0) (u 1) (v 1)) - if : >= i : - n 2 ⇒ (if (>= i (- n 2)) + if : >= i {n - 2} ⇒ (if (>= i (- n 2)) . v v - rek (+ i 1) v (+ u v) (rek (+ i 1) v (+ u v))))) + rek {i + 1} v {u + v} (rek (+ i 1) v (+ u v))))) -Wisp turns indentation based syntax into Lisp. The conversion is homoiconic[^h], generic[^g], and backwards-compatible[^b]. It is inspired by [project readable][], but tries to keep itself simple (and stupid: just a preprocessor). More information on the [wisp-website][] and code in the [wisp-repository][]. +Wisp turns indentation based syntax into Lisp. The conversion is homoiconic[^h], generic[^g], and backwards-compatible[^b]. It is inspired by [project readable][], but tries to keep itself simple (and stupid: just add parens for indentation). More information is available on the [wisp-website][], and code in the [wisp-repository][]. For a short presentation, see [Why Wisp?](why-wisp.html) +Note that this is full-fledged scheme, with all its capabilities like hygienic macros (programmable syntax!) and full tail recursion. + [wisp-website]: http://draketo.de/light/english/wisp-lisp-indentation-preprocessor "wisp: Whitespace to Lisp: An indentation to parentheses preprocessor to get more readable Lisp" [wisp-repository]: http://draketo.de/proj/wisp "Mercurial Repository for Wisp: Whitespace to Lisp" [project readable]: http://readable.sourceforge.net/ "Readable Lisp S-expressions Project" @@ -40,24 +43,15 @@ Usage Wisp and curly infix (SRFI-105) ------------------------------- -Wisp treats braces "{}" the same as parentheses "()" and square brackets "[]", so you can use it with curly infix ([SRFI-105](http://srfi.schemers.org/srfi-105/srfi-105.html)) to get more customary math expressions. In Guile Scheme with Wisp you can activate curly infix using the following line `. #!curly-infix ` (with a final space!) - -<a name="fibonacci"></a>By combining curly-infix and wisp, the well-known Fibonacci sequence can be defined as follows: - - . #!curly-infix - define : fibonacci n - let rek : (i 0) (u 1) (v 1) - if {i >= {n - 2}} - . v - rek {i + 1} v {u + v} - -Note that this is full-fledged scheme, with all its capabilities like hygienic macros (programmable syntax!) and full tail recursion. +Wisp treats braces "{}" the same as parentheses "()" and square brackets "[]", so you can use it with curly infix ([SRFI-105](http://srfi.schemers.org/srfi-105/srfi-105.html)) to get more customary math expressions. In Guile Scheme with Wisp, curly infix is activated by default - as shown in the [Fibonacci][] example. If you want to use a curly-infix expression starting a line, you have to prefix it with a dot: . {1 + 1} ; = 2 +[Fibonacci]: #fibonacci "Generation of the fibonacci sequence in wisp and s-expressions" + Notes ----- diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ dnl run `autoreconf -i` to generate a configure script. dnl Then run ./configure to generate a Makefile. dnl Finally run make to generate the project. -AC_INIT([wisp], [0.8.1], +AC_INIT([wisp], [0.8.2], [arne_bab@web.de]) # Check for programs I need for my build AC_CANONICAL_TARGET diff --git a/docs/srfi-from-template.html b/docs/srfi-from-template.html new file mode 100644 --- /dev/null +++ b/docs/srfi-from-template.html @@ -0,0 +1,756 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> + <head> + <title>SRFI 119: wisp: simpler indentation-sensitive scheme</title> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + </head> + <body> + +<H1>Title</H1> + +wisp: simpler indentation-sensitive scheme + +<H1>Author</H1> + +Arne Babenhauserheide + +<H1>Status</H1> + +<p> +This SRFI is currently in ``draft'' status. +To see an explanation of +each status that a SRFI can hold, see <a +href="http://srfi.schemers.org/srfi-process.html">here</a>. + +To provide input on this SRFI, please +<a href="mailto:srfi minus 119 at srfi dot schemers dot org">mail to +<code><srfi minus 119 at srfi dot schemers dot org></code></a>. See +<a href="../srfi-list-subscribe.html">instructions here</a> to +subscribe to the list. You can access previous messages via +<a href="mail-archive/maillist.html">the archive of the mailing list</a>. +</p><ul> + <li>Received: <a + href="http://srfi.schemers.org/cgi-bin/viewcvs.cgi/*checkout*/srfi/srfi-119/srfi-119.html?rev=1.1">2015/01/25</a></li> + <li>Draft: 2015/02/03-2015/04/03</li> +</ul> + + +<h3>Acknowledgments</h3> +<ul> +<li>Thanks for many constructive discussions goes to Alan Manuel K. Gloria and David A. Wheeler. +</li> +<li>Also thanks to Mark Weaver for his help with the wisp parser and the guile integration - including a 20x speedup. +</li> +</ul> + +<H1>Abstract</H1> + +<p> +This SRFI describes a simple syntax which allows making scheme easier to read for newcomers while keeping the simplicity, generality and elegance of s-expressions. Similar to <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a>, <a href="http://srfi.schemers.org/srfi-49/srfi-49.html">SRFI 49</a> and Python it uses indentation to group expressions. Like <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> wisp is general and homoiconic. +</p> + +<p> +Different from its predecessors, wisp only uses the absolute minimum of additional syntax-elements which are required for writing and exchanging arbitrary code-structures. As syntax elements it only uses a colon surrounded by whitespace, the period followed by whitespace as first code-character on the line and optional underscores followed by whitespace at the beginning of the line. +</p> + +<p> +It resolves a limitation of <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> and <a href="http://srfi.schemers.org/srfi-49/srfi-49.html">SRFI 49</a>, both of which force the programmer to use a single argument per line if the arguments to a procedure need to be continued after a procedure-call. +</p> + +<p> +Wisp expressions can include any s-expressions and as such provide backwards compatibility. +</p> + +<table><tr><th>wisp</th><th>s-exp</th></tr><tr><td> +<pre><b>define</b> : <i>hello</i> who + <i>format</i> #t "Hello ~A!\n" + . who +<i>hello</i> "Wisp" +</pre> +</td><td> +<pre>(<b>define</b> (<i>hello</i> who) + (<i>format</i> #t "Hello ~A!\n" + who)) +(<i>hello</i> "S-exp") +</pre> +</td></tr></table> + +<H1>Issues</H1> + +<ul> +<li>wisp-scheme: REPL: sometimes the output of a command is only shown after typing the next non-empty line.</li></ul> + +<H1>Rationale</H1> + +<p>A big strength of Scheme and other lisp-like languages is their minimalistic syntax. By using only the most common characters like the period, the comma, the quote and quasiquote, the hash, the semicolon and the parens for the syntax (<code>.,"'`#;()</code><!--"-->), they are very close to natural language.<a href="#common-letters" name="common-letters-reference">⁽¹⁾</a> Along with the minimal list-structure of the code, this gives these languages a timeless elegance.</p> + +<p>But as <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> explains very thoroughly (which we need not repeat here), the parentheses at the beginning of lines hurt readability and scare away newcomers. Additionally using indentation to mark the structure of the code follows naturally from the observation that most programmers use indentation, with many programmers letting their editor indent code automatically to fit the structure. Indentation is an important way how programmers understand code and using it directly to define the structure avoids errors due to mismatches between indentation and actual meaning.</p> + +<p>As a solution to this, <a href="http://srfi.schemers.org/srfi-49/srfi-49.html">SRFI 49</a> and <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> provide a way to write whitespace sensitive scheme, but both have their share of issues.</p> + +<p>As noted in <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a>, there are a number of implementation-problems in <a href="http://srfi.schemers.org/srfi-49/srfi-49.html">SRFI 49</a>, as well as specification shortcomings like choosing the name “group” for the construct which is necessary to represent double parentheses. In addition to the problems named in <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a>, <a href="http://srfi.schemers.org/srfi-49/srfi-49.html">SRFI 49</a> is not able to continue the arguments to a procedure on one line, if a prior argument was a procedure call. The following example shows the difference between wisp and <a href="http://srfi.schemers.org/srfi-49/srfi-49.html">SRFI 49</a> for a very simple code snippet:</p> + +<table><tr><th>wisp</th><th><a href="http://srfi.schemers.org/srfi-49/srfi-49.html">SRFI 49</a></th></tr><tr><td> +<pre> + <i>*</i> 5 + <i>+</i> 4 3 + . 2 1 +</pre> +</td><td> +<pre> + <i>*</i> 5 + <i>+</i> 4 3 + 2 + 1 +</pre> +</td></tr></table> + +<p>Here wisp uses the leading period to mark a line as continuing the argument list.<a href="#period-concept" name="period-concept-reference">⁽²⁾</a></p> + +<p><a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> improves a lot over <a href="http://srfi.schemers.org/srfi-49/srfi-49.html">SRFI 49</a>. It resolves the group-naming and reduces the need to continue the argument-list by introducing 3 different grouping syntax forms (<code>$</code>, <code>\\</code> and <code><* *></code>). These additional syntax-elements however hurt readability for newcomers (obviously the authors of <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> disagree with this assertion. Their view is discussed in <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> in the section about wisp). The additional syntax elements lead to structures like the following (taken from examples from the readable project):</p> + + +<table><tr><th><a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> / readable</th></tr><tr><td> +<pre> + <i>myprocedure</i> + x: \\ original-x + y: \\ <i>calculate-y</i> original-y +</pre> +</td></tr><tr><td> +<pre> + <i>a</i> b $ <i>c</i> d e $ <i>f</i> g +</pre> +</td></tr><tr><td> +<pre> + let <* <i>x</i> <i>getx</i>() \\ <i>y</i> <i>gety</i>() *> + ! {{x * x} + {y * y}} +</pre> +</td></tr></table> + +<p>This is not only hard to read, but also makes it harder to work with the code, because the programmer has to learn these additional syntax elements and keep them in mind before being able to understand the code.</p> + +<p>Like <a href="http://srfi.schemers.org/srfi-49/srfi-49.html">SRFI 49</a> <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> also cannot continue the argument-list without resorting to single-element lines, though it reduces this problem by the above grouping syntax forms and advertising the use of neoteric expressions from <a href="http://srfi.schemers.org/srfi-105/srfi-105.html">SRFI 105</a>.</p> + +<h2>Wisp example</h2> + +Since an example speaks more than a hundred explanations, the following shows wisp exploiting all its features - including curly-infix from <a href="http://srfi.schemers.org/srfi-105/srfi-105.html">SRFI 105</a>: + +<blockquote> +<pre> +<b>define</b> : <i>factorial</i> n +__ <b>if</b> : <i>zero?</i> n +____ . 1 +____ <i>*</i> n : <i>factorial</i> {n - 1} + +<i>display</i> : <i>factorial</i> 5 +<i>newline</i> +</pre> +</blockquote> + +<h2>Advantages of Wisp</h2> + +<p>Wisp draws on the strength of <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> but avoids its complexities. It was conceived and improved in the discussions within the readable-project which preceded <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> and there is a comparison between readable in wisp in <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a>.</p> + +<p>Like <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a>, wisp is general and homoiconic and interacts nicely with <a href="http://srfi.schemers.org/srfi-105/srfi-105.html">SRFI 105</a> (neoteric expressions and curly infix). Like <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a>, the expressions are the same in the REPL and in code-files. Like <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a>, wisp has been used for implementing multiple smaller programs, though the biggest program in wisp is still its implementations (written in wisp and bootstrapped via a simpler wisp preprocessor).</p> + +<p>But unlike <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a>, wisp only uses the minimum of additional syntax-elements which are necessary to support arbitrary code-structures with indentation-sensitive code which is intended to be shared over the internet. To realize these syntax-elements, it generalizes existing syntax and draws on the most common non-letter non-math characters in prose. This allows keeping the actual representation of the code elegant and inviting to newcomers.</p> + +<p>Wisp expressions are not as sweet as <a href="http://readable.sf.net">readable</a>, but they KISS.</p> + +<h2>Disadvantages of Wisp</h2> + +<p>Using the colon as syntax element keeps the code very close to written prose, but it can interfere with type definitions as for example used in Typed Racket.<a href="#typed-racket" name="typed-racket-reference">⁽³⁾</a> This can be mitigated in let- and lambda-forms by using the parenthesized form. When doing so, wisp avoids the double-paren for type-declarations and as such makes them easier to catch by eye. For procedure definitions (the only <code>define</code> call where type declarations are needed in typed-racket), a <code>declare</code> macro directly before the <code>define</code> should work well.</p> + +<p>Using the period to continue the argument list is unusual compared to other languages and as such can lead to errors when trying to return a variable from a procedure and forgetting the period.</p> + + +<h2>Related SRFIs</h2> +<ul> +<li><a href="http://srfi.schemers.org/srfi-49/srfi-49.html">SRFI 49</a> (Indentation-sensitive syntax): superseded by this SRFI, +</li> +<li><a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> (Sweet-expressions (t-expressions)): alternative to this SRFI, +</li> +<li><a href="http://srfi.schemers.org/srfi-105/srfi-105.html">SRFI 105</a> (neoteric expressions and curly infix): supported in this SRFI by treating curly braces like brackets and parentheses. Curly infix is required by the implementation and the testsuite. +</li> +<li><a href="http://srfi.schemers.org/srfi-30/srfi-30.html">SRFI 30</a> (Nested Multi-line comments): complex interaction. Should be avoided at the beginning of lines, because it can make the indentation hard to distinguish for humans. <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a> includes them, so there might be value in adding them. The wisp reference implementation does not treat them specially, though, which might create arbitrary complications. +</li> +</ul> + + +<h2>Footnotes</h2> + +<ul><li><a name="common-letters" href="#common-letters-reference">⁽¹⁾</a> The most common non-letter, non-math characters in prose are <code>.,":'_#?!;</code><!--"-->, in the given order as derived from newspapers and other sources (for the ngram assembling scripts, see the <a href="http://bitbucket.org/ArneBab/evolve-keyboard-layout">evolve keyboard layout project</a>).</li> + <li><a name="period-concept" href="#period-concept-reference">⁽²⁾</a> Conceptually, continuing the argument list with a period uses syntax to mark the rare case of not calling a procedure as opposed to marking the common case of calling a procedure. To back the claim, that calling a procedure is actually the common case in scheme-code, grepping the the modules in the Guile source code shows over 27000 code-lines which start with a paren and only slightly above 10000 code-lines which start with a non-paren, non-comment character. Since wisp-syntax mostly follows the regular scheme indentation guidelines (as realized for example by Emacs), the whitespace in front of lines does not need to change.</li> + <li><a name="typed-racket" href="#typed-racket-reference">⁽³⁾</a> Typed Racket uses calls of the form <code>(: x Number)</code> to declare types. These forms can still be used directly in parenthesized form, but in wisp-form the colon has to be replaced with <code>\:</code>. In most cases type-declarations are not needed in typed racket, since the type can be inferred. See <a href="http://docs.racket-lang.org/ts-guide/more.html?q=typed#%28part._when-annotations~3f%29">When do you need type annotations?</a></li> +</ul> + +<H1>Specification</H1> + +<p>The specification is separated into four parts: A general overview of the syntax, a more detailed description, justifications for each added syntax element and clarifications for technical details.</p> + +<h2>Overview</h2> + +<p>The basics of wisp syntax can be defined in 4 rules, each of which emerges directly from a requirement:</p> + +<h3>Wisp syntax 1/4: procedure calls</h3> + +<p>Indentation:</p> + +<pre> +<i>display</i> + + 3 4 5 +<i>newline</i> +</pre> + +<p>becomes</p> + +<pre> +(<i>display</i> + (+ 3 4 5)) +(<i>newline</i>) +</pre> + +<p><i>requirement: call procedure without parenthesis.</i></p> + +<h3>Wisp syntax 2/4: Continue Argument list</h3> + +<p>The period:</p> + +<pre> +<i>+</i> 5 + <i>*</i> 4 3 + . 2 1 +</pre> + +<p>becomes</p> + +<pre> +(<i>+</i> 5 + (<i>*</i> 4 3) + 2 1) +</pre> + +<p>This also works with just one argument after the period. To start a line without a procedure call, you have to prefix it with a period followed by whitespace.</p> + +<p><i>requirement: continue the argument list of a procedure after an intermediate call to another procedure.</i></p> + +<h3>Wisp syntax 3/4: Double Parens</h3> + +<p>The colon:</p> + +<pre> +<b>let</b> + : x 1 + y 2 + z 3 + <i>body</i> +</pre> + +<p>becomes</p> + +<pre> +(<b>let</b> + ((x 1) + (y 2) + (z 3)) + (<i>body</i>)) +</pre> + +<p><i>requirement: represent code with two adjacent blocks in double-parentheses.</i></p> + +<h3>Wisp syntax 4/4: Resilient Indentation</h3> + +<p>The underscore (optional):</p> + +<pre> +<b>let</b> +_ : x 1 +__ y 2 +__ z 3 +_ <i>body</i> +</pre> + +<p>becomes</p> + +<pre> +(<b>let</b> + ((x 1) + (y 2) + (z 3)) + (<i>body</i>)) +</pre> + +<p><i>requirement: share code in environments which do not preserve whitespace.</i></p> + +<h3>Summary</h3> + +<p>The syntax shown here is the minimal syntax required for the goal of wisp: indentation-based, general lisp with a simple preprocessor, and code which can be shared easily on the internet:</p> + +<ul><li><code>.</code> to continue the argument list</li> + <li><code>:</code> for double parens</li> + <li><code>_</code> to survive HTML</li></ul> + + +<h3>More detailed: Wisp syntax rules</h3> + + +<h4>Unindented line</h4> + +<p> +<b>A line without indentation is a procedure call</b>, just as if it would start with a parenthesis. +</p> + + + +<pre><i>display</i> "Hello World!" ; (<i>display</i> "Hello World!") +</pre> + + + +<h4>Sibling line</h4> + +<p> +<b>A line which is more indented than the previous line is a sibling to that line</b>: It opens a new parenthesis. +</p> + + + +<pre><i>display</i> ; (<i>display</i> + <i>string-append</i> "Hello " "World!" ; (<i>string-append</i> "Hello " "World!")) +</pre> + + + +<h4>Closing line</h4> + +<p> +<b>A line which is not more indented than previous line(s) closes the parentheses of all previous lines which have higher or equal indentation</b>. You should only reduce the indentation to indentation levels which were already used by parent lines, else the behaviour is undefined. +</p> + + + +<pre><i>display</i> ; (<i>display</i> + <i>string-append</i> "Hello " "World!" ; (<i>string-append</i> "Hello " "World!")) +<i>display</i> "Hello Again!" ; (<i>display</i> "Hello Again!") +</pre> + + + + + +<h4>Prefixed line</h4> + +<p> +<b>To add any of ' , ` #' #, #` or #@, to the first parenthesis on a line, just prefix the line with that symbol</b> followed by at least one space. Implementations are free to add more prefix symbols. +</p> + + + +<pre>' "Hello World!" ; '("Hello World!") +</pre> + + + + + + +<h4>Continuing line</h4> + +<p> +<b>A line whose first non-whitespace characters is a dot followed by a space (". ") does not open a new parenthesis: it is treated as simple continuation of the first less indented previous line</b>. In the first line this means that this line does not start with a parenthesis and does not end with a parenthesis, just as if you had directly written it in lisp without the leading ". ". +</p> + + + +<pre><i>string-append</i> "Hello" ; (<i>string-append</i> "Hello" + <i>string-append</i> " " "World" ; (<i>string-append</i> " " "World") + . "!" ; "!") +</pre> + + + + + + +<h4>Empty indentation level</h4> + +<p> +<b>A line which contains only whitespace and a colon (":") defines an indentation level at the indentation of the colon</b>. It opens a parenthesis which gets closed by the next line which has less or equal indentation. If you need to use a colon by itself. you can escape it as "\:". +</p> + + + +<pre><b>let</b> ; (<b>let</b> + : ; ( + <i>msg</i> "Hello World!" ; (<i>msg</i> "Hello World!")) + <i>display</i> msg ; (<i>display</i> msg)) +</pre> + + + + + + +<h4>Inline Colon</h4> + +<p> +<b>A colon surrounded by whitespace (" : ") starts a parenthesis which gets closed at the end of the line</b>. +</p> + + + +<pre><b>define</b> : <i>hello</i> who ; (<b>define</b> (<i>hello</i> who) + <i>display </i> ; (<i>display</i> + <i>string-append</i> "Hello " who "!" ; (<i>string-append</i> "Hello " who "!"))) +</pre> + + +<p> +If the colon starts a line which also contains other non-whitespace characters, it starts a parenthesis which gets closed at the end of the line <b>and</b> defines an indentation level at the position of the colon. +</p> + +<p> +If the colon is the last non-whitespace character on a line, it represents an empty pair of parentheses: +</p> + + + +<pre><b>let</b> : ; (<b>let</b> () + <i>display</i> "Hello" ; (<i>display</i> "Hello")) +</pre> + + + + + +<h4>Initial Underscores</h4> + +<p> +<b>You can replace any number of consecutive initial spaces by underscores</b>, as long as at least one whitespace is left between the underscores and any following character. You can escape initial underscores by prefixing the first one with \ ("\___ a" → "(_ a)"), if you have to use them as procedure names. +</p> + + + +<pre><b>define</b> : <i>hello</i> who ; (<b>define</b> (<i>hello</i> who) +_ <i>display</i> ; (<i>display</i> +___ <i>string-append</i> "Hello " who "!" ; (<i>string-append</i> "Hello " who "!"))) +</pre> + + + + + +<h4>Parens and Strings</h4> + +<p> +<b>Linebreaks inside parentheses and strings are not considered linebreaks</b> for parsing indentation. To use parentheses at the beginning of a line without getting double parens, prefix the line with a period. +</p> + + + +<pre><b>define</b> : <i>stringy</i> s + <i>string-append</i> s " reversed and capitalized: + " ; linebreaks in strings do not affect wisp parsing + . (<i>string-capitalize</i> ; same for linebreaks in parentheses + (<i>string-reverse</i> s)) +</pre> + + +<p> +Effectively code in parentheses and strings is interpreted directly as Scheme. This way you can simply copy a thunk of scheme into wisp. The following is valid wisp: +</p> + + + +<pre><b>define</b> foo (<i>+</i> 1 + (<i>*</i> 2 3)) ; defines foo as 7 +</pre> + + + + + + +<h3>Clarifications</h3> + +<ul> +<li>Code-blocks end after 2 empty lines followed by a newline. Indented non-empty lines after 2 empty lines should be treated as error. A line is empty if it only contains whitespace. A line with a comment is never empty. +</li> + +<li>Inside parentheses, wisp parsing is disabled. Consequently linebreaks inside parentheses are not considered linebreaks for wisp-parsing. For the parser everything which happens inside parentheses is treated as a black box. +</li> + +<li>Square brackets and curly braces should be treated the same way as parentheses: They stop the indentation processing until they are closed. +</li> + +<li>Likewise linebreaks inside strings are not considered linebreaks for wisp-parsing. +</li> + +<li>A colon (:) at the beginning of a line adds an extra open parentheses that gets closed at end-of-line <b>and</b> defines an indentation level. +</li> + +<li>Using a quote to escape a symbol separated from it by whitespace is forbidden. This would make the meaning of quoted lines ambiguous. +</li> + +<li>Curly braces should be treated as curly-infix following <a href="http://srfi.schemers.org/srfi-105/srfi-105.html">SRFI 105</a>. This makes most math look natural to newcomers. +</li> + +<li>Neoteric expressions from <a href="http://srfi.schemers.org/srfi-105/srfi-105.html">SRFI 105</a> are not required because they create multiple ways to represent the same code. In wisp they add much less advantages than in sweet expressions from <a href="http://srfi.schemers.org/srfi-110/srfi-110.html">SRFI 110</a>, because wisp can continue the arguments to a procedure after a procedure call (with the leading period) and the inline colon provides most of the benefits neoteric expressions give to sweet. However implementations providing wisp should give users the option to activate neoteric expressions as by <a href="http://srfi.schemers.org/srfi-105/srfi-105.html">SRFI 105</a> to allow experimentation and evolution (<a href="http://sourceforge.net/p/readable/mailman/message/33068104/">discussion</a>). +</li> + +<li>It is possible to write code which is at the same time valid wisp and sweet. The readable mailing list <a href="http://sourceforge.net/p/readable/mailman/message/33058992/">contains details</a>. +</li> + +<li>The suggested suffix for files using wisp-syntax is <code>.w</code>. + +<li>To represent tail notation like <code>(define (foo . args))</code>, either avoid a linebreak before the dot as in <code>define : foo . args</code> or use a double dot to start the line: <code>. . args</code>. The first dot mark the line as continuation, the second enters the scheme code.</li> + +<li>A dot as symbol at the end of a line is reserved for potential future use. It should be a syntax error if the next non-empty line starts with non-zero indentation. A lone dot at the end of a line calls for hard to catch errors.</li> + +<li>A dot as only symbol in a line has no useful meaning: the line is by definition empty. As such, a dot as only symbol on a line is also reserved for future use and should be treated as a syntax error to avoid locking out future possibilities.</li> + +</ul> + + +<h2>Syntax justification</h2> + +<p> +<i>I do not like adding any unnecessary syntax element to lisp. So I want to show explicitly why the syntax elements are required.</i> +</p> + +<p> +<small> +See also <a href="http://draketo.de/light/english/wisp-lisp-indentation-preprocessor#sec-4">http://draketo.de/light/english/wisp-lisp-indentation-preprocessor#sec-4</a> +</small> +</p> + + + +<h3> . (the dot)</h3> +<p> +To represent general code trees, we have to be able to represent continuation of the arguments of a procedure with an intermediate call to another (or the same) procedure. +</p> + +<p> +The dot at the beginning of the line as marker of the continuation of a variable list is a generalization of using the dot as identity procedure - which is an implementation detail in many lisps. +</p> + +<blockquote> +<p> +<code>(. a)</code> is just <code>a</code> +</p> +</blockquote> + +<p> +So for the single variable case, this would not even need additional parsing: wisp could just parse <code>. a</code> to <code>(. a)</code> and produce the correct result in most lisps. But forcing programmers to always use separate lines for each parameter would be very inconvenient, so the definition of the dot at the beginning of the line is extended to mean “take every element in this line as parameter to the parent procedure”. +</p> + +<blockquote> +<p> +<code>(. a)</code> → <code>a</code> is generalized to <code>(. a b c)</code> → <code>a b c</code>. +</p> +</blockquote> + +<p> +At its core, this dot-rule means that we mark variables in the code instead of procedure calls. We do so, because variables at the beginning of a line are much rarer in Scheme than in other programming languages. +</p> + + + +<h3> : (the colon)</h3> + +<p> +For double parentheses and for some other cases we must have a way to mark indentation levels which do not contain code. Wisp uses the colon, because it is the most common non-alpha-numeric character in normal prose which is not already reserved as syntax by Scheme when it is surrounded by whitespace, and because it already gets used without surrounding whitespace for marking keyword arguments to procedures in Emacs Lisp and Common Lisp, so it does not add completely alien concepts. +</p> + +<p> +The inline procedure call via inline " : " is a limited generalization of using the colon to mark an indentation level: If we add a syntax-element, we should use it as widely as possible to justify adding syntax overhead. +</p> + +<p> +But if you need to use <code>:</code> as variable or procedure name, you can still do so by escaping it with a backslash (<code>\:</code>), so this does not forbid using the character. +</p> + +<p> +For simple cases, the colon could be replaced by clever whitespace parsing, but there are complex cases which make this impossible. The minimal example is a theoretical doublelet which does not require a body. The example uses a double let without action as example for the colon-syntax, even though that does nothing, because that makes it impossible to use later indentation to mark an intermediate indentation-level. Another reason why I would not use later indentation to define whether something earlier is a single or double indent is that this would call for subtle and really hard to find errors. +</p> + + +<pre>(<i>doublelet</i> + ((foo bar)) + ((bla foo))) +</pre> + + +<p> +The wisp version of this is +</p> + +<pre><i>doublelet</i> + : + foo bar + : ; <- this empty back step is the real issue + bla foo +</pre> + + +<p> +or shorter with inline colon (which you can use only if you don’t need further indentation-syntax inside the assignment). +</p> + + + +<pre><i>doublelet</i> + : foo bar + : bla foo +</pre> + + +<p> +The need to be able to represent arbitrary syntax trees which can contain expressions like this is the real reason, why the colon exists. The inline and start-of-line use is only a generalization of that principle (we add a syntax-element, so we should see how far we can push it to reduce the effective cost of introducing the additional syntax). +</p> + + + +<h4>Clever whitespace-parsing which would not work</h4> + +<p> +There are two alternative ways to tackle this issue: deferred level-definition and fixed-width indentation. +</p> + +<p> +Defining intermediate indentation-levels by later elements (deferred definition) would be a problem, because it would create code which is really hard to understand. An example is the following: +</p> + + + +<pre><b>define</b> (<i>flubb</i>) + nubb + hubb + subb + gam +</pre> + + +<p> +would become +</p> + + + +<pre>(<b>define</b> (<i>flubb</i>) + ((nubb)) + ((hubb)) + ((subb)) + (gam)) +</pre> + + +<p> +while +</p> + + + +<pre><b>define</b> (<i>flubb</i>) + nubb + hubb + subb +</pre> + + +<p> +would become +</p> + + + +<pre>(<b>define</b> (<i>flubb</i>) + (nubb) + (hubb) + (subb)) +</pre> + + +<p> +Knowledge of later parts of the code would be necessary to understand the parts a programmer is working on at the moment. This would call for subtle errors which would be hard to track down, because the effect of a change in code would not be localized at the point where the change is done but could propagate backwards. +</p> + +<p> +Fixed indentation width (alternative option to inferring it from later lines) would make it really hard to write readable code. Stuff like this would not be possible: +</p> + + + +<pre><b>when</b> + <i>equal?</i> wrong + <i>isright?</i> stuff + <i>fixstuff</i> +</pre> + + + + + +<h3> _ (the underscore)</h3> + +<p> +In Python the whitespace hostile html already presents problems with sharing code - for example in email list archives and forums. But Python-programmers can mostly infer the indentation by looking at the previous line: If that ends with a colon, the next line must be more indented (there is nothing to clearly mark reduced indentation, though). In wisp we do not have this support, so we need a way to survive in the hostile environment of today's web. +</p> + +<p> +The underscore is commonly used to denote a space in URLs, where spaces are inconvenient, but it is rarely used in Scheme (where the dash ("-") is mostly used instead), so it seems like a a natural choice. +</p> + +<p> +You can still use underscores anywhere but at the beginning of the line, and even at the beginning of the line you simply need to escape it by prefixing the first underscore with a backslash ("\____"). +</p> + + + +<H1>Implementation</H1> + +<p>The reference implementation realizes a specialized parser for Scheme. It uses <a href="https://gnu.org/s/guile" title="GNU Guile: The GNU extension language">GNU Guile</a> and can also be used at the REPL.</p> + +<p>The wisp code also contains a general wisp-preprocessor which can be used for any lisp-like language and can used as an external program which gets called on reading. It does not actually have to understand the code itself.</p> + +<p>To allow for easy re-implementation, the chapter after the implementation itself contains a test-suite with commonly used wisp constructs and parenthesized counterparts.</p> + +<p>The wisp preprocessor implementation can be found in the <a href="http://draketo.de/proj/wisp">wisp code repository</a>. Both implementations are explicitly licensed to allow inclusion in an SRFI.</p> + +<p>The reference implementation linked below generates a syntax tree from wisp which can be executed. It is written in indentation-based wisp-syntax and converted with the preprocessor from the code repository (wisp-guile.w) to parenthesized scheme syntax.</p> + +<ul> + <li><A HREF="http://draketo.de/proj/wisp/srfi-reference.scm">Source for the reference implementation</A>.</li> + <li><A HREF="http://draketo.de/proj/wisp/srfi-testsuite.html">Basic Testsuite for wisp implementations</A>. <br>(a more exhaustive testsuite is available in the <a href="http://draketo.de/proj/wisp">wisp code repository</a>)</li> +</ul> + +<H1>Copyright</H1> +Copyright (C) Arne Babenhauserheide (2014). All Rights Reserved. +<p> +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: +<p> +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +<p> +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + + <hr> + <address>Editor: <a href="mailto:srfi-editors at srfi dot schemers dot org">Michael Sperber</a></address> +<!-- Created: Tue Sep 29 19:20:08 EDT 1998 --> +<!-- hhmts start --> +Last modified: Tue Mar 11 21:25:26 MET 2015 +<!-- hhmts end --> + </body> +</html> diff --git a/docs/srfi-testsuite.html b/docs/srfi-testsuite.html new file mode 100644 --- /dev/null +++ b/docs/srfi-testsuite.html @@ -0,0 +1,957 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> +<head> +<title>Test Suite</title> +<!-- 2014-12-23 Di 22:50 --> +<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> +<meta name="generator" content="Org-mode" /> +<meta name="author" content="Arne Babenhauserheide" /> +<style type="text/css"> + <!--/*--><![CDATA[/*><!--*/ + .title { text-align: center; } + .todo { font-family: monospace; color: red; } + .done { color: green; } + .tag { background-color: #eee; font-family: monospace; + padding: 2px; font-size: 80%; font-weight: normal; } + .timestamp { color: #bebebe; } + .timestamp-kwd { color: #5f9ea0; } + .right { margin-left: auto; margin-right: 0px; text-align: right; } + .left { margin-left: 0px; margin-right: auto; text-align: left; } + .center { margin-left: auto; margin-right: auto; text-align: center; } + .underline { text-decoration: underline; } + #postamble p, #preamble p { font-size: 90%; margin: .2em; } + p.verse { margin-left: 3%; } + pre { + border: 1px solid #ccc; + box-shadow: 3px 3px 3px #eee; + padding: 8pt; + font-family: monospace; + overflow: auto; + margin: 1.2em; + } + pre.src { + position: relative; + overflow: visible; + padding-top: 1.2em; + } + pre.src:before { + display: none; + position: absolute; + background-color: white; + top: -10px; + right: 10px; + padding: 3px; + border: 1px solid black; + } + pre.src:hover:before { display: inline;} + pre.src-sh:before { content: 'sh'; } + pre.src-bash:before { content: 'sh'; } + pre.src-emacs-lisp:before { content: 'Emacs Lisp'; } + pre.src-R:before { content: 'R'; } + pre.src-perl:before { content: 'Perl'; } + pre.src-java:before { content: 'Java'; } + pre.src-sql:before { content: 'SQL'; } + + table { border-collapse:collapse; } + caption.t-above { caption-side: top; } + caption.t-bottom { caption-side: bottom; } + td, th { vertical-align:top; } + th.right { text-align: center; } + th.left { text-align: center; } + th.center { text-align: center; } + td.right { text-align: right; } + td.left { text-align: left; } + td.center { text-align: center; } + dt { font-weight: bold; } + .footpara:nth-child(2) { display: inline; } + .footpara { display: block; } + .footdef { margin-bottom: 1em; } + .figure { padding: 1em; } + .figure p { text-align: center; } + .inlinetask { + padding: 10px; + border: 2px solid gray; + margin: 10px; + background: #ffffcc; + } + #org-div-home-and-up + { text-align: right; font-size: 70%; white-space: nowrap; } + textarea { overflow-x: auto; } + .linenr { font-size: smaller } + .code-highlighted { background-color: #ffff00; } + .org-info-js_info-navigation { border-style: none; } + #org-info-js_console-label + { font-size: 10px; font-weight: bold; white-space: nowrap; } + .org-info-js_search-highlight + { background-color: #ffff00; color: #000000; font-weight: bold; } + /*]]>*/--> +</style> +<script type="text/javascript"> +/* +@licstart The following is the entire license notice for the +JavaScript code in this tag. + +Copyright (C) 2012-2013 Free Software Foundation, Inc. + +The JavaScript code in this tag is free software: you can +redistribute it and/or modify it under the terms of the GNU +General Public License (GNU GPL) as published by the Free Software +Foundation, either version 3 of the License, or (at your option) +any later version. The code is distributed WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. + +As additional permission under GNU GPL version 3 section 7, you +may distribute non-source (e.g., minimized or compacted) forms of +that code without the copy of the GNU GPL normally required by +section 4, provided you include this license notice and a URL +through which recipients can access the Corresponding Source. + + +@licend The above is the entire license notice +for the JavaScript code in this tag. +*/ +<!--/*--><![CDATA[/*><!--*/ + function CodeHighlightOn(elem, id) + { + var target = document.getElementById(id); + if(null != target) { + elem.cacheClassElem = elem.className; + elem.cacheClassTarget = target.className; + target.className = "code-highlighted"; + elem.className = "code-highlighted"; + } + } + function CodeHighlightOff(elem, id) + { + var target = document.getElementById(id); + if(elem.cacheClassElem) + elem.className = elem.cacheClassElem; + if(elem.cacheClassTarget) + target.className = elem.cacheClassTarget; + } +/*]]>*///--> +</script> +</head> +<body> +<div id="content"> +<h1 class="title">Test Suite</h1> +<p> +The wisp test-suite consists of a large number of wisp-snippets and the corresponding scheme-code. +</p> + +<p> +A wisp-implementation may call itself compliant with the wisp test-suite if the code tree parsed from the wisp file is the same as a code tree parsed from the equivalent Scheme file. +</p> + +<p> +A wisp-implementation may call itself a compliant wisp pre-processor if it successfully converts each wisp-snippet into the corresponging scheme-snippet. Blank lines at the end of the file and non-functional white-space in the produced scheme-file do not matter for this purpose. +</p> + +<p> +This test-suite is also available in the <a href="http://draketo.de/proj/wisp">wisp repository</a> along with a script-runner (runtests.sh) which tests the reference wisp-implementation with GNU Guile against this testsuite.<sup><a id="fnr.1" name="fnr.1" class="footref" href="#fn.1">1</a></sup> +</p> + +<div id="outline-container-sec-1" class="outline-2"> +<h2 id="sec-1"><span class="section-number-2">1</span> tests/syntax-underscore.w</h2> +<div class="outline-text-2" id="text-1"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">a</span> b c +<span style="color: #0000ff;">_ d</span> e +<span style="color: #0000ff;">___ f</span> +<span style="color: #0000ff;">___</span> g h +<span style="color: #0000ff;">__</span><span style="color: #a020f0;"> . </span>i + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">_</span> +<span style="color: #0000ff;">_ display</span> <span style="color: #8b2252;">"hello\n"</span> + +<span style="color: #0000ff;">\_</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-2" class="outline-2"> +<h2 id="sec-2"><span class="section-number-2">2</span> tests/syntax-underscore.scm</h2> +<div class="outline-text-2" id="text-2"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">a</span> b c) + (d e + (f) + (g h) + i)) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">_</span>) + (display <span style="color: #8b2252;">"hello\n"</span>)) + +(_) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-3" class="outline-2"> +<h2 id="sec-3"><span class="section-number-2">3</span> tests/syntax-strings-parens.w</h2> +<div class="outline-text-2" id="text-3"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #b22222;">; </span><span style="color: #b22222;">Test linebreaks in strings and brackets</span> + +<span style="color: #a020f0;">. </span><span style="color: #8b2252;">"flubbub</span> + +<span style="color: #8b2252;">flabbab"</span> + +hrug (<span style="color: #0000ff;">nadda</span> +<span style="color: #0000ff;">madda</span> gadda <span style="color: #8b2252;">"shoktom</span> +<span style="color: #8b2252;"> mee"</span> <span style="color: #8b2252;">" sep </span> +<span style="color: #8b2252;">ka"</span> +<span style="color: #0000ff;"> hadda)</span> +<span style="color: #0000ff;"> gom</span> + +<span style="color: #0000ff;">flu</span> + +<span style="color: #0000ff;">sum</span> [foo +<span style="color: #0000ff;">bar]</span> barz {1 + [* <span style="color: #008b8b;">2</span> <span style="color: #008b8b;">2</span>]} + +<span style="color: #0000ff;">mara</span> { +<span style="color: #0000ff;">li</span> +<span style="color: #0000ff;">+</span> +<span style="color: #0000ff;">lo</span> - (<span style="color: #0000ff;">mabba</span>) +<span style="color: #0000ff;">}</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-4" class="outline-2"> +<h2 id="sec-4"><span class="section-number-2">4</span> tests/syntax-strings-parens.scm</h2> +<div class="outline-text-2" id="text-4"> +<div class="org-src-container"> + +<pre class="src src-scheme"><span style="color: #b22222;">; </span><span style="color: #b22222;">Test linebreaks in strings and brackets</span> + +<span style="color: #8b2252;">"flubbub</span> + +<span style="color: #8b2252;">flabbab"</span> + +(hrug (nadda +madda gadda <span style="color: #8b2252;">"shoktom</span> +<span style="color: #8b2252;"> mee"</span> <span style="color: #8b2252;">" sep </span> +<span style="color: #8b2252;">ka"</span> + hadda) + (gom)) + +(flu) + +(sum [foo +bar] barz {1 + [* 2 2]}) + +(mara { +li ++ +lo - (mabba) +}) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-5" class="outline-2"> +<h2 id="sec-5"><span class="section-number-2">5</span> tests/syntax-indent.w</h2> +<div class="outline-text-2" id="text-5"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span> +<span style="color: #0000ff;"> hello</span> who +<span style="color: #0000ff;"> format</span> <span style="color: #008b8b;">#t</span> <span style="color: #8b2252;">"Hello ~A\n"</span> who + +<span style="color: #483d8b;">define</span> + <span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> :</span> +<span style="color: #0000ff;"> a</span> <span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> b</span> <span style="color: #008b8b;">2</span> +<span style="color: #0000ff;"> c</span> <span style="color: #008b8b;">3</span> +<span style="color: #0000ff;"> format</span> <span style="color: #008b8b;">#t</span> <span style="color: #8b2252;">"a: ~A, b: ~A, c: ~A"</span> +<span style="color: #0000ff;"> +</span> a <span style="color: #008b8b;">2</span> +<span style="color: #a020f0;"> . </span> b c +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6" class="outline-2"> +<h2 id="sec-6"><span class="section-number-2">6</span> tests/syntax-indent.scm</h2> +<div class="outline-text-2" id="text-6"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> + (hello who) + (format #t <span style="color: #8b2252;">"Hello ~A\n"</span> who)) + +(<span style="color: #a020f0;">define</span> + (<span style="color: #a020f0;">let</span> + ( + (a 1) + (b 2) + (c 3)) + (format #t <span style="color: #8b2252;">"a: ~A, b: ~A, c: ~A"</span> + (+ a 2) + b c))) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-7" class="outline-2"> +<h2 id="sec-7"><span class="section-number-2">7</span> tests/syntax-empty.w</h2> +<div class="outline-text-2" id="text-7"> +<div class="org-src-container"> + +<pre class="src src-wisp"></pre> +</div> +</div> +</div> +<div id="outline-container-sec-8" class="outline-2"> +<h2 id="sec-8"><span class="section-number-2">8</span> tests/syntax-empty.scm</h2> +<div class="outline-text-2" id="text-8"> +<div class="org-src-container"> + +<pre class="src src-scheme"></pre> +</div> +</div> +</div> +<div id="outline-container-sec-9" class="outline-2"> +<h2 id="sec-9"><span class="section-number-2">9</span> tests/syntax-dot.w</h2> +<div class="outline-text-2" id="text-9"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">foo</span> +<span style="color: #a020f0;"> . </span><span style="color: #8b2252;">"bar"</span> + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">bar</span> +<span style="color: #0000ff;"> '</span> <span style="color: #008b8b;">1</span> +<span style="color: #a020f0;"> . . </span><span style="color: #008b8b;">2</span> <span style="color: #b22222;">; </span><span style="color: #b22222;">pair</span> + +<span style="color: #0000ff;">display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">foo</span> +<span style="color: #0000ff;">newline</span> +<span style="color: #0000ff;">display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">bar</span> +<span style="color: #0000ff;">newline</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-10" class="outline-2"> +<h2 id="sec-10"><span class="section-number-2">10</span> tests/syntax-dot.scm</h2> +<div class="outline-text-2" id="text-10"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">foo</span>) + <span style="color: #8b2252;">"bar"</span>) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">bar</span>) + '(1 + . 2 ))<span style="color: #b22222;">; </span><span style="color: #b22222;">pair</span> + +(display (foo)) +(newline) +(display (bar)) +(newline) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-11" class="outline-2"> +<h2 id="sec-11"><span class="section-number-2">11</span> tests/syntax-colon.w</h2> +<div class="outline-text-2" id="text-11"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> :</span> +<span style="color: #0000ff;"> a</span> <span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> b</span> <span style="color: #008b8b;">2</span> + <span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> :</span> +<span style="color: #a020f0;"> :</span> +<span style="color: #a020f0;"> . </span>c <span style="color: #008b8b;">3</span> +<span style="color: #0000ff;"> format</span> <span style="color: #008b8b;">#t</span> <span style="color: #8b2252;">"a: ~A, b: ~A, c: ~A"</span> +<span style="color: #a020f0;"> . </span> a b c + +<span style="color: #a020f0;">: </span>a + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">hello</span> +<span style="color: #0000ff;"> display</span> <span style="color: #8b2252;">"hello\n"</span> + +<span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">a</span> <span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> b</span> <span style="color: #008b8b;">2</span> +<span style="color: #0000ff;"> format</span> <span style="color: #008b8b;">#t</span> <span style="color: #8b2252;">"a: ~A, b: ~A"</span> +<span style="color: #a020f0;"> . </span> a b + +<span style="color: #483d8b;">let</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">:</span> a ' : + +<span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> : </span> <span style="color: #b22222;">; </span><span style="color: #b22222;">foo</span> +<span style="color: #0000ff;"> a</span> + ' + +<span style="color: #a020f0;">:</span> + a + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">\:</span> +<span style="color: #0000ff;"> hello</span> + +<span style="color: #0000ff;">\:</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-12" class="outline-2"> +<h2 id="sec-12"><span class="section-number-2">12</span> tests/syntax-colon.scm</h2> +<div class="outline-text-2" id="text-12"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">let</span> + ( + (a 1) + (b 2)) + (<span style="color: #a020f0;">let</span> + ( + ( + c 3)) + (format #t <span style="color: #8b2252;">"a: ~A, b: ~A, c: ~A"</span> + a b c))) + +((a)) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">hello</span>) + (display <span style="color: #8b2252;">"hello\n"</span>)) + +(<span style="color: #a020f0;">let</span> + ((a 1) + (b 2)) + (format #t <span style="color: #8b2252;">"a: ~A, b: ~A"</span> + a b)) + +(<span style="color: #a020f0;">let</span> ((a '()))) + +(<span style="color: #a020f0;">let</span> + ( <span style="color: #b22222;">; </span><span style="color: #b22222;">foo</span> + (a + '()))) + +( + (a)) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">:</span>) + (hello)) + +(:) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-13" class="outline-2"> +<h2 id="sec-13"><span class="section-number-2">13</span> tests/sublist.w</h2> +<div class="outline-text-2" id="text-13"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #b22222;">; </span><span style="color: #b22222;">sublists allow to start single line function calls with a colon ( : ).</span> + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">a</span> b c + <span style="color: #483d8b;">let</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">:</span> e<span style="color: #a020f0;"> . </span>f +<span style="color: #a020f0;"> . </span>g +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-14" class="outline-2"> +<h2 id="sec-14"><span class="section-number-2">14</span> tests/sublist.scm</h2> +<div class="outline-text-2" id="text-14"> +<div class="org-src-container"> + +<pre class="src src-scheme"><span style="color: #b22222;">; </span><span style="color: #b22222;">sublists allow to start single line function calls with a colon ( : ).</span> + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">a</span> b c) + (<span style="color: #a020f0;">let</span> ((e . f)) + g)) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-15" class="outline-2"> +<h2 id="sec-15"><span class="section-number-2">15</span> tests/hashbang.w</h2> +<div class="outline-text-2" id="text-15"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #b22222;">#!/usr/bin/wisp.py # !#</span> +<span style="color: #b22222;">; </span><span style="color: #b22222;">This tests hashbang lines</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-16" class="outline-2"> +<h2 id="sec-16"><span class="section-number-2">16</span> tests/hashbang.scm</h2> +<div class="outline-text-2" id="text-16"> +<div class="org-src-container"> + +<pre class="src src-scheme">#!/usr/bin/wisp.py # !# +<span style="color: #b22222;">; </span><span style="color: #b22222;">This tests hashbang lines</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-17" class="outline-2"> +<h2 id="sec-17"><span class="section-number-2">17</span> tests/readable-tests.w</h2> +<div class="outline-text-2" id="text-17"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">fibfast</span> n + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;"><</span> n <span style="color: #008b8b;">2</span> +<span style="color: #a020f0;"> . </span>n +<span style="color: #0000ff;"> fibup</span> n <span style="color: #008b8b;">2</span> <span style="color: #008b8b;">1</span> <span style="color: #008b8b;">0</span> + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">fibup</span> maxnum count n-1 n-2 + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">=</span> maxnum count +<span style="color: #0000ff;"> +</span> n-1 n-2 +<span style="color: #0000ff;"> fibup</span> maxnum +<span style="color: #0000ff;"> +</span> count <span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> +</span> n-1 n-2 +<span style="color: #a020f0;"> . </span>n-1 + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> n + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;"><=</span> n <span style="color: #008b8b;">1</span> +<span style="color: #a020f0;"> . </span><span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> *</span> n +<span style="color: #0000ff;"> factorial</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">-</span> n <span style="color: #008b8b;">1</span> + +<span style="color: #483d8b;">define</span> (<span style="color: #0000ff;">gcd</span> x y) + <span style="color: #483d8b;">if</span> (<span style="color: #0000ff;">=</span> y <span style="color: #008b8b;">0</span>) +<span style="color: #a020f0;"> . </span>x +<span style="color: #0000ff;"> gcd</span> y +<span style="color: #0000ff;"> rem</span> x y + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">add-if-all-numbers</span> lst +<span style="color: #0000ff;"> call/cc</span> +<span style="color: #0000ff;"> lambda</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">exit</span> + <span style="color: #483d8b;">let</span> loop +<span style="color: #a020f0;"> : </span> +<span style="color: #0000ff;"> lst</span> lst +<span style="color: #0000ff;"> sum</span> <span style="color: #008b8b;">0</span> + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">null?</span> lst +<span style="color: #a020f0;"> . </span>sum + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #483d8b;">not</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">number?</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">car</span> lst +<span style="color: #0000ff;"> exit</span> <span style="color: #008b8b;">#f</span> +<span style="color: #0000ff;"> +</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">car</span> lst +<span style="color: #0000ff;"> loop</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">cdr</span> lst +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-18" class="outline-2"> +<h2 id="sec-18"><span class="section-number-2">18</span> tests/readable-tests.scm</h2> +<div class="outline-text-2" id="text-18"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">fibfast</span> n) + (<span style="color: #a020f0;">if</span> (< n 2)) + n + (fibup n 2 1 0 )) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">fibup</span> maxnum count n-1 n-2) + (<span style="color: #a020f0;">if</span> (= maxnum count) + (+ n-1 n-2) + (fibup maxnum + (+ count 1 ) + (+ n-1 n-2 ) + n-1))) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">factorial</span> n) + (<span style="color: #a020f0;">if</span> (<= n 1) + 1 + (* n + (factorial (- n 1))))) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">gcd</span> x y) + (<span style="color: #a020f0;">if</span> (= y 0)) + x + (gcd y + (rem x y))) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">add-if-all-numbers</span> lst) + (<span style="color: #a020f0;">call/cc</span> + (<span style="color: #a020f0;">lambda</span> (exit) + (<span style="color: #a020f0;">let</span> <span style="color: #0000ff;">loop</span> + ( + (lst lst ) + (sum 0)) + (<span style="color: #a020f0;">if</span> (null? lst) + sum + (<span style="color: #a020f0;">if</span> (not (number? (car lst))) + (exit #f) + (+ (car lst) + (loop (cdr lst))))))))) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-19" class="outline-2"> +<h2 id="sec-19"><span class="section-number-2">19</span> tests/quotecolon.w</h2> +<div class="outline-text-2" id="text-19"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #b22222;">#!/home/arne/wisp/wisp-multiline.sh </span> +<span style="color: #b22222;">; </span><span style="color: #b22222;">!#</span> +<span style="color: #483d8b;">define</span> a <span style="color: #008b8b;">1</span> <span style="color: #b22222;">; </span><span style="color: #b22222;">test whether ' : correctly gets turned into '(</span> +<span style="color: #b22222;">; </span><span style="color: #b22222;">and whether brackets in commments are treated correctly.</span> + +<span style="color: #483d8b;">define</span> a '<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">1</span> <span style="color: #008b8b;">2</span> <span style="color: #008b8b;">3</span> + +<span style="color: #483d8b;">define</span> +<span style="color: #0000ff;"> a</span> b +<span style="color: #0000ff;"> c</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-20" class="outline-2"> +<h2 id="sec-20"><span class="section-number-2">20</span> tests/quotecolon.scm</h2> +<div class="outline-text-2" id="text-20"> +<div class="org-src-container"> + +<pre class="src src-scheme">#!/home/arne/wisp/wisp-multiline.sh +<span style="color: #b22222;">; </span><span style="color: #b22222;">!#</span> +(<span style="color: #a020f0;">define</span> <span style="color: #0000ff;">a</span> 1 )<span style="color: #b22222;">; </span><span style="color: #b22222;">test whether ' : correctly gets turned into '(</span> +<span style="color: #b22222;">; </span><span style="color: #b22222;">and whether brackets in commments are treated correctly.</span> + +(<span style="color: #a020f0;">define</span> <span style="color: #0000ff;">a</span> '(1 2 3)) + +(<span style="color: #a020f0;">define</span> + (a b) + (c)) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-21" class="outline-2"> +<h2 id="sec-21"><span class="section-number-2">21</span> tests/namedlet.w</h2> +<div class="outline-text-2" id="text-21"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #b22222;">#!/home/arne/wisp/wisp-multiline.sh </span> +<span style="color: #b22222;">; </span><span style="color: #b22222;">!#</span> +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">hello</span> who +<span style="color: #0000ff;"> display</span> who + +<span style="color: #483d8b;">let</span> hello +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">who</span> <span style="color: #008b8b;">0</span> + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">=</span> who <span style="color: #008b8b;">5</span> +<span style="color: #0000ff;"> display</span> who +<span style="color: #0000ff;"> hello</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">+</span> <span style="color: #008b8b;">1</span> who +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-22" class="outline-2"> +<h2 id="sec-22"><span class="section-number-2">22</span> tests/namedlet.scm</h2> +<div class="outline-text-2" id="text-22"> +<div class="org-src-container"> + +<pre class="src src-scheme">#!/home/arne/wisp/wisp-multiline.sh +<span style="color: #b22222;">; </span><span style="color: #b22222;">!#</span> +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">hello</span> who) + (display who)) + +(<span style="color: #a020f0;">let</span> <span style="color: #0000ff;">hello</span> + ((who 0)) + (<span style="color: #a020f0;">if</span> (= who 5) + (display who) + (hello (+ 1 who)))) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-23" class="outline-2"> +<h2 id="sec-23"><span class="section-number-2">23</span> tests/flexible-parameter-list.w</h2> +<div class="outline-text-2" id="text-23"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #b22222;">; </span><span style="color: #b22222;">Test using a . as first parameter on a line by prefixing it with a second .</span> +<span style="color: #483d8b;">define</span> +<span style="color: #0000ff;"> a</span> i +<span style="color: #a020f0;"> . . </span>b +<span style="color: #0000ff;"> unless</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">>=</span> i<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">length</span> b +<span style="color: #0000ff;"> display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">number->string</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">length</span> b +<span style="color: #0000ff;"> display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">list-ref</span> b i +<span style="color: #0000ff;"> newline</span> +<span style="color: #0000ff;"> apply</span> a ( <span style="color: #0000ff;">+</span> i <span style="color: #008b8b;">1</span> ) b + + +<span style="color: #0000ff;">a</span> <span style="color: #008b8b;">0</span> <span style="color: #8b2252;">"123"</span> <span style="color: #8b2252;">"345"</span> <span style="color: #8b2252;">"567"</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-24" class="outline-2"> +<h2 id="sec-24"><span class="section-number-2">24</span> tests/flexible-parameter-list.scm</h2> +<div class="outline-text-2" id="text-24"> +<div class="org-src-container"> + +<pre class="src src-scheme"><span style="color: #b22222;">; </span><span style="color: #b22222;">Test using a . as first parameter on a line by prefixing it with a second .</span> +(<span style="color: #a020f0;">define</span> + (a i + . b) + (unless (>= i (length b)) + (display (number->string (length b ))) + (display (list-ref b i)) + (newline) + (apply a ( + i 1 ) b))) + + +(a 0 <span style="color: #8b2252;">"123"</span> <span style="color: #8b2252;">"345"</span> <span style="color: #8b2252;">"567"</span>) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-25" class="outline-2"> +<h2 id="sec-25"><span class="section-number-2">25</span> tests/factorial.w</h2> +<div class="outline-text-2" id="text-25"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #b22222;">;; </span><span style="color: #b22222;">short version</span> +<span style="color: #b22222;">; </span><span style="color: #b22222;">note: once you use one inline colon, all the following forms on that</span> +<span style="color: #b22222;">; </span><span style="color: #b22222;">line will get closed at the end of the line</span> + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> n + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">zero?</span> n +<span style="color: #a020f0;"> . </span><span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> *</span> n<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">-</span> n <span style="color: #008b8b;">1</span> + +<span style="color: #0000ff;">display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> <span style="color: #008b8b;">5</span> + + +<span style="color: #b22222;">;; </span><span style="color: #b22222;">more vertical space, less colons</span> +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> n + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">zero?</span> n +<span style="color: #a020f0;"> . </span><span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> *</span> n +<span style="color: #0000ff;"> factorial</span> +<span style="color: #0000ff;"> -</span> n <span style="color: #008b8b;">1</span> + +<span style="color: #0000ff;">display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> <span style="color: #008b8b;">5</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-26" class="outline-2"> +<h2 id="sec-26"><span class="section-number-2">26</span> tests/factorial.scm</h2> +<div class="outline-text-2" id="text-26"> +<div class="org-src-container"> + +<pre class="src src-scheme"><span style="color: #b22222;">;; </span><span style="color: #b22222;">short version</span> +<span style="color: #b22222;">; </span><span style="color: #b22222;">note: once you use one inline colon, all the following forms on that</span> +<span style="color: #b22222;">; </span><span style="color: #b22222;">line will get closed at the end of the line</span> + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">factorial</span> n) + (<span style="color: #a020f0;">if</span> (zero? n) + 1 + (* n (factorial (- n 1))))) + +(display (factorial 5 )) + + +<span style="color: #b22222;">;; </span><span style="color: #b22222;">more vertical space, less colons</span> +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">factorial</span> n) + (<span style="color: #a020f0;">if</span> (zero? n) + 1 + (* n + (factorial + (- n 1))))) + +(display (factorial 5 )) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-27" class="outline-2"> +<h2 id="sec-27"><span class="section-number-2">27</span> tests/example.w</h2> +<div class="outline-text-2" id="text-27"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span> (<span style="color: #0000ff;">a</span> b c) + <span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> : </span> +<span style="color: #0000ff;"> d</span> <span style="color: #8b2252;">"i am a string</span> +<span style="color: #8b2252;">do not break me!"</span> +<span style="color: #a020f0;"> : </span> + <span style="color: #b22222;">; </span><span style="color: #b22222;">comment: 0</span> + f +<span style="color: #b22222;">; </span><span style="color: #b22222;">comment : 1</span> +<span style="color: #0000ff;"> `</span> g <span style="color: #b22222;">; </span><span style="color: #b22222;">comment " : " 2</span> +<span style="color: #a020f0;"> : </span> +<span style="color: #0000ff;"> h</span> (<span style="color: #0000ff;">I</span> am in brackets: +<span style="color: #0000ff;"> do</span> <span style="color: #483d8b;">not</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">change</span> <span style="color: #8b2252;">"me"</span>) +<span style="color: #a020f0;"> . </span>i +<span style="color: #0000ff;"> ,</span><span style="color: #008b8b;"> 'j</span> k + +<span style="color: #a020f0;"> . </span>l + +<span style="color: #b22222;">; </span><span style="color: #b22222;">comment</span> + +<span style="color: #0000ff;"> a</span> c + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">b</span> :n o +<span style="color: #a020f0;"> . </span><span style="color: #8b2252;">"second defun : with a docstring!"</span> +<span style="color: #0000ff;"> message</span> <span style="color: #8b2252;">"I am here"</span> +<span style="color: #a020f0;"> . </span>t + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">c</span> e f +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">g</span> +<span style="color: #a020f0;"> :</span> +<span style="color: #0000ff;"> h</span> +<span style="color: #0000ff;"> i</span> +<span style="color: #0000ff;"> j</span> +<span style="color: #0000ff;"> '</span> : +<span style="color: #0000ff;"> k</span> +<span style="color: #a020f0;"> . </span>l +<span style="color: #a020f0;"> . </span>: <span style="color: #0000ff;">m</span> + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">_</span> \: +<span style="color: #0000ff;">__</span> +<span style="color: #0000ff;">__</span><span style="color: #a020f0;"> . </span>\: + +<span style="color: #0000ff;">\_</span> b + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">d</span> + <span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">a</span> b +<span style="color: #0000ff;"> c</span> d + +<span style="color: #0000ff;">a</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">:</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">c</span> + +<span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">a</span> b + c + +<span style="color: #483d8b;">let</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">:</span> a b + +<span style="color: #a020f0;">. </span>a +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-28" class="outline-2"> +<h2 id="sec-28"><span class="section-number-2">28</span> tests/example.scm</h2> +<div class="outline-text-2" id="text-28"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">a</span> b c) + (<span style="color: #a020f0;">let</span> + ( + (d <span style="color: #8b2252;">"i am a string</span> +<span style="color: #8b2252;">do not break me!"</span>) + ( + <span style="color: #b22222;">; </span><span style="color: #b22222;">comment: 0</span> + (f) +<span style="color: #b22222;">; </span><span style="color: #b22222;">comment : 1</span> + `(g ))<span style="color: #b22222;">; </span><span style="color: #b22222;">comment " : " 2</span> + ( + (h (I am in brackets: + do not : change <span style="color: #8b2252;">"me"</span>)) + i))) + ,('j k) + + l + +<span style="color: #b22222;">; </span><span style="color: #b22222;">comment</span> + + (a c)) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">b</span> <span style="color: #483d8b;">:n</span> o) + <span style="color: #8b2252;">"second defun : with a docstring!"</span> + (message <span style="color: #8b2252;">"I am here"</span>) + t) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">c</span> e f) + ((g)) + ( + (h + (i)) + (j)) + '(()) + (k) + l + (m)) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">_</span> :) + + :) + +(_ b) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">d</span>) + (<span style="color: #a020f0;">let</span> + ((a b) + (c d)))) + +(a (((c)))) + +(<span style="color: #a020f0;">let</span> + ((a b) + (c))) + +(<span style="color: #a020f0;">let</span> ((a b))) + +a +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-29" class="outline-2"> +<h2 id="sec-29"><span class="section-number-2">29</span> tests/continuation.w</h2> +<div class="outline-text-2" id="text-29"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">a</span> b c d e +<span style="color: #a020f0;"> . </span>f g h +<span style="color: #a020f0;"> . </span>i j k + +<span style="color: #0000ff;">concat</span> <span style="color: #8b2252;">"I want "</span> +<span style="color: #0000ff;"> getwish</span> from me +<span style="color: #a020f0;"> . </span><span style="color: #8b2252;">" - "</span> username +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-30" class="outline-2"> +<h2 id="sec-30"><span class="section-number-2">30</span> tests/continuation.scm</h2> +<div class="outline-text-2" id="text-30"> +<div class="org-src-container"> + +<pre class="src src-scheme">(a b c d e + f g h + i j k) + +(concat <span style="color: #8b2252;">"I want "</span> + (getwish from me) + <span style="color: #8b2252;">" - "</span> username) +</pre> +</div> +</div> +</div> +<div id="footnotes"> +<h2 class="footnotes">Footnotes: </h2> +<div id="text-footnotes"> + +<div class="footdef"><sup><a id="fn.1" name="fn.1" class="footnum" href="#fnr.1">1</a></sup> <p> +To run the tests in the wisp testsuite with a separately built GNU Guile, you can use any given guile interpreter by adjusting the following command: <code>PATH=~/guile-2.0.11/meta:${PATH} ./runtests.sh</code> +</p></div> + + +</div> +</div></div> +<div id="postamble" class="status"> +<p class="author">Author: Arne Babenhauserheide</p> +<p class="date">Created: 2014-12-23 Di 22:50</p> +<p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.3.1 (<a href="http://orgmode.org">Org</a> mode 8.2.6)</p> +<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p> +</div> +</body> +</html> diff --git a/docs/srfi.html b/docs/srfi.html new file mode 100644 --- /dev/null +++ b/docs/srfi.html @@ -0,0 +1,1885 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> +<head> +<title>SRFI: wisp: simpler indentation-sensitive scheme</title> +<!-- 2014-12-23 Di 17:17 --> +<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> +<meta name="generator" content="Org-mode" /> +<meta name="author" content="Arne Babenhauserheide" /> +<style type="text/css"> + <!--/*--><![CDATA[/*><!--*/ + .title { text-align: center; } + .todo { font-family: monospace; color: red; } + .done { color: green; } + .tag { background-color: #eee; font-family: monospace; + padding: 2px; font-size: 80%; font-weight: normal; } + .timestamp { color: #bebebe; } + .timestamp-kwd { color: #5f9ea0; } + .right { margin-left: auto; margin-right: 0px; text-align: right; } + .left { margin-left: 0px; margin-right: auto; text-align: left; } + .center { margin-left: auto; margin-right: auto; text-align: center; } + .underline { text-decoration: underline; } + #postamble p, #preamble p { font-size: 90%; margin: .2em; } + p.verse { margin-left: 3%; } + pre { + border: 1px solid #ccc; + box-shadow: 3px 3px 3px #eee; + padding: 8pt; + font-family: monospace; + overflow: auto; + margin: 1.2em; + } + pre.src { + position: relative; + overflow: visible; + padding-top: 1.2em; + } + pre.src:before { + display: none; + position: absolute; + background-color: white; + top: -10px; + right: 10px; + padding: 3px; + border: 1px solid black; + } + pre.src:hover:before { display: inline;} + pre.src-sh:before { content: 'sh'; } + pre.src-bash:before { content: 'sh'; } + pre.src-emacs-lisp:before { content: 'Emacs Lisp'; } + pre.src-R:before { content: 'R'; } + pre.src-perl:before { content: 'Perl'; } + pre.src-java:before { content: 'Java'; } + pre.src-sql:before { content: 'SQL'; } + + table { border-collapse:collapse; } + caption.t-above { caption-side: top; } + caption.t-bottom { caption-side: bottom; } + td, th { vertical-align:top; } + th.right { text-align: center; } + th.left { text-align: center; } + th.center { text-align: center; } + td.right { text-align: right; } + td.left { text-align: left; } + td.center { text-align: center; } + dt { font-weight: bold; } + .footpara:nth-child(2) { display: inline; } + .footpara { display: block; } + .footdef { margin-bottom: 1em; } + .figure { padding: 1em; } + .figure p { text-align: center; } + .inlinetask { + padding: 10px; + border: 2px solid gray; + margin: 10px; + background: #ffffcc; + } + #org-div-home-and-up + { text-align: right; font-size: 70%; white-space: nowrap; } + textarea { overflow-x: auto; } + .linenr { font-size: smaller } + .code-highlighted { background-color: #ffff00; } + .org-info-js_info-navigation { border-style: none; } + #org-info-js_console-label + { font-size: 10px; font-weight: bold; white-space: nowrap; } + .org-info-js_search-highlight + { background-color: #ffff00; color: #000000; font-weight: bold; } + /*]]>*/--> +</style> +<script type="text/javascript"> +/* +@licstart The following is the entire license notice for the +JavaScript code in this tag. + +Copyright (C) 2012-2013 Free Software Foundation, Inc. + +The JavaScript code in this tag is free software: you can +redistribute it and/or modify it under the terms of the GNU +General Public License (GNU GPL) as published by the Free Software +Foundation, either version 3 of the License, or (at your option) +any later version. The code is distributed WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. + +As additional permission under GNU GPL version 3 section 7, you +may distribute non-source (e.g., minimized or compacted) forms of +that code without the copy of the GNU GPL normally required by +section 4, provided you include this license notice and a URL +through which recipients can access the Corresponding Source. + + +@licend The above is the entire license notice +for the JavaScript code in this tag. +*/ +<!--/*--><![CDATA[/*><!--*/ + function CodeHighlightOn(elem, id) + { + var target = document.getElementById(id); + if(null != target) { + elem.cacheClassElem = elem.className; + elem.cacheClassTarget = target.className; + target.className = "code-highlighted"; + elem.className = "code-highlighted"; + } + } + function CodeHighlightOff(elem, id) + { + var target = document.getElementById(id); + if(elem.cacheClassElem) + elem.className = elem.cacheClassElem; + if(elem.cacheClassTarget) + target.className = elem.cacheClassTarget; + } +/*]]>*///--> +</script> +</head> +<body> +<div id="content"> +<h1 class="title">SRFI: wisp: simpler indentation-sensitive scheme</h1> +<div class="abstract"> +<p> +This SRFI describes a simple syntax which allows making scheme easier to read for newcomers while keeping the simplicity, generality and elegance of s-expressions. Similar to SRFI-110, SRFI-49 and Python it uses indentation to group expressions. Like SRFI-110 wisp is general and homoiconic. +</p> + +<p> +Different from its precedessors, wisp only uses the absolute minimum of additional syntax-elements which are required for writing and exchanging arbitrary code-structures. As syntax elements it only uses a colon surrounded by whitespace, the period followed by whitespace as first code-character on the line and optional underscores followed by whitespace at the beginning of the line. +</p> + +<p> +It resolves a limitation of SRFI-110 and SRFI-49, both of which force the programmer to use a single argument per line if the arguments to a function need to be continued after a function-call. +</p> + +<p> +Wisp expressions can include any s-expressions and as such provide backwards compatibility. +</p> + +<table><tr><th>wisp</th><th>s-exp</th></tr><tr><td> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">hello</span> who +<span style="color: #0000ff;"> format</span> <span style="color: #008b8b;">#t</span> <span style="color: #C33;">"~A ~A!\n"</span> +<span style="color: #a020f0;"> . </span><span style="color: #C33;">"Hello"</span> who +<span style="color: #0000ff;">hello</span> <span style="color: #C33;">"Wisp"</span> +</pre> +</div> +</td><td> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">hello</span> who) + (format #t <span style="color: #C33;">"~A ~A!\n"</span> + <span style="color: #C33;">"Hello"</span> who)) +(hello <span style="color: #C33;">"S-exp"</span>) +</pre> +</div> +</td></tr></table> + +</div> + +<div id="table-of-contents"> +<h2>Table of Contents</h2> +<div id="text-table-of-contents"> +<ul> +<li><a href="#sec-1">1. Authors</a> +<ul> +<li><a href="#sec-1-1">1.1. Acknowledgments</a></li> +</ul> +</li> +<li><a href="#sec-2">2. Related SRFIs</a></li> +<li><a href="#sec-3">3. Rationale</a> +<ul> +<li><a href="#sec-3-1">3.1. Wisp example</a></li> +<li><a href="#sec-3-2">3.2. Advantages of Wisp</a></li> +<li><a href="#sec-3-3">3.3. Disadvantages of Wisp</a></li> +</ul> +</li> +<li><a href="#sec-4">4. Specification</a> +<ul> +<li><a href="#sec-4-1">4.1. Overview</a></li> +<li><a href="#sec-4-2">4.2. More detailed: Wisp syntax rules</a></li> +<li><a href="#sec-4-3">4.3. Clarifications</a></li> +</ul> +</li> +<li><a href="#sec-5">5. Syntax justification</a> +<ul> +<li><a href="#sec-5-1">5.1. . (the dot)</a></li> +<li><a href="#sec-5-2">5.2. : (the colon)</a></li> +<li><a href="#sec-5-3">5.3. _ (the underscore)</a></li> +</ul> +</li> +<li><a href="#sec-6">6. Implementation</a> +<ul> +<li><a href="#sec-6-1">6.1. The generic wisp processor (code)</a></li> +<li><a href="#sec-6-2">6.2. Test Suite</a></li> +</ul> +</li> +<li><a href="#sec-7">7. Copyright</a></li> +</ul> +</div> +</div> + +<div id="outline-container-sec-1" class="outline-2"> +<h2 id="sec-1"><span class="section-number-2">1</span> Authors</h2> +<div class="outline-text-2" id="text-1"> +<ul class="org-ul"> +<li>Arne Babenhauserheide +</li> +</ul> +</div> + +<div id="outline-container-sec-1-1" class="outline-3"> +<h3 id="sec-1-1"><span class="section-number-3">1.1</span> Acknowledgments</h3> +<div class="outline-text-3" id="text-1-1"> +<ul class="org-ul"> +<li>Thanks for many constructive discussions goes to Alan Manuel K. Gloria and David A. Wheeler. +</li> +<li>Also thanks to Mark Weaver for his help with the wisp parser and the guile integration - including a 20x speedup. +</li> +</ul> +</div> +</div> +</div> + +<div id="outline-container-sec-2" class="outline-2"> +<h2 id="sec-2"><span class="section-number-2">2</span> Related SRFIs</h2> +<div class="outline-text-2" id="text-2"> +<ul class="org-ul"> +<li>SRFI-49 (Indentation-sensitive syntax): superceded by this SRFI, +</li> +<li>SRFI-110 (Sweet-expressions (t-expressions)): alternative to this SRFI, +</li> +<li>SRFI-105 (neoteric expressions and curly infix): supported in this SRFI by treating curly braces like brackets and parentheses. Curly infix is required by the implementation and the testsuite. +</li> +<li>SRFI-30 (Nested Multi-line comments): complex interaction. Should be avoided at the beginning of lines, because it can make the indentation hard to distinguish for humans. SRFI-110 includes them, so there might be value in adding them. The wisp reference implementation does not treat them specially, though, which might create arbitrary complications. +</li> +</ul> +</div> +</div> + +<div id="outline-container-sec-3" class="outline-2"> +<h2 id="sec-3"><span class="section-number-2">3</span> Rationale</h2> +<div class="outline-text-2" id="text-3"> +<p> +A big strength of Scheme and other lisp-like languages is their minimalistic syntax. By using only the most common characters like the period, the comma, the quote and quasiquote, the hash, the semicolon and the parens for the syntax (<code>.,"'`#;()</code>), they are very close to natural language<sup><a id="fnr.1" name="fnr.1" class="footref" href="#fn.1">1</a></sup>. Along with the minimal list-structure of the code, this gives these languages a timeless elegance. +</p> + +<p> +But as SRFI-110 explains very thoroughly (which we need not repeat here), the parentheses at the beginning of lines hurt readability and scare away newcomers. Additionally using indentation to mark the structure of the code follows naturally from the observation that most programmers use indentation, with many programmers letting their editor indent code automatically to fit the structure. Indentation is an important way how programmers understand code and using it directly to define the structure avoids errors due to mismatches between indentation and actual meaning. +</p> + +<p> +As a solution to this, SRFI-49 and SRFI-110 provide a way to write whitespace sensitive scheme, but both have their share of issues. +</p> + +<p> +As noted in SRFI-110, there are a number of implementation-problems in SRFI-49, as well as specification shortcomings like choosing the name “group” for the construct which is necessary to represent double parentheses. In addition to the problems named in SRFI-110, SRFI-49 is not able to continue the arguments to a function on one line, if a prior argument was a function call. The following example shows the difference between wisp and SRFI-49 for a very simple code snippet: +</p> + +<table><tr><th>wisp</th><th>SRFI-49</th></tr><tr><td> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">*</span> <span style="color: #008b8b;">5</span> +<span style="color: #0000ff;"> +</span> <span style="color: #008b8b;">4</span> <span style="color: #008b8b;">3</span> +<span style="color: #a020f0;"> . </span><span style="color: #008b8b;">2</span> <span style="color: #008b8b;">1</span> +</pre> +</div> +</td><td> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">*</span> <span style="color: #008b8b;">5</span> +<span style="color: #0000ff;"> +</span> <span style="color: #008b8b;">4</span> <span style="color: #008b8b;">3</span> +<span style="color: #0000ff;"> 2</span> +<span style="color: #0000ff;"> 1</span> +</pre> +</div> +</td></tr></table> + +<p> +SRFI-110 improves a lot over the implementation of SRFI-49. It resolves the group-naming and reduces the need to continue the argument-list by introducing 3 different grouping syntaxes (<code>$</code>, <code>\\</code> and <code><* *></code>). These additional syntax-elements however hurt readability for newcomers (obviously the authors of SRFI-110 disagree with this assertion. Their view is discussed in SRFI-110 in the section about wisp). The additional syntax elements lead to structures like the following (taken from examples from the readable project): +</p> +<div class="org-src-container"> + +<pre class="src src-scheme">myfunction + x: \\ original-x + y: \\ calculate-y original-y +</pre> +</div> + +<div class="org-src-container"> + +<pre class="src src-scheme">a b $ c d e $ f g +</pre> +</div> + +<div class="org-src-container"> + +<pre class="src src-scheme">let <* x getx() \\ y gety() *> +! {{x * x} + {y * y}} +</pre> +</div> + +<p> +This is not only hard to read, but also makes it harder to work with the code, because the programmer has to learn these additional syntax elements and keep them in mind before being able to understand the code. +</p> + +<p> +Like SRFI-49 SRFI-110 also cannot continue the argument-list without resorting to single-element lines, though it reduces this problem by the above grouping syntaxes and advertising the use of neoteric expressions from SRFI-105. +</p> +</div> + +<div id="outline-container-sec-3-1" class="outline-3"> +<h3 id="sec-3-1"><span class="section-number-3">3.1</span> Wisp example</h3> +<div class="outline-text-3" id="text-3-1"> +<p> +Since an example speaks more than a hundred explanations, the following shows wisp exploiting all its features - including curly-infix from SRFI-105: +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> n +<span style="color: #0000ff;">__</span> <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">zero?</span> n +<span style="color: #0000ff;">____</span><span style="color: #a020f0;"> . </span><span style="color: #008b8b;">1</span> +<span style="color: #0000ff;">____ *</span> n<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> {n - 1} + +<span style="color: #0000ff;">display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> <span style="color: #008b8b;">5</span> +<span style="color: #0000ff;">newline</span> +</pre> +</div> +</div> +</div> + +<div id="outline-container-sec-3-2" class="outline-3"> +<h3 id="sec-3-2"><span class="section-number-3">3.2</span> Advantages of Wisp</h3> +<div class="outline-text-3" id="text-3-2"> +<p> +Wisp draws on the strength of SRFI-110 but avoids its complexities. It was conceived and improved in the discussions within the readable-project which preceded SRFI-110 and there is a comparison between readable in wisp in SRFI-110. +</p> + +<p> +Like SRFI-110, wisp is general and homoiconic and interacts nicely with SRFI-105 (neoteric expressions and curly infix). Like SRFI-110, the expressions are the same in the REPL and in code-files. Like SRFI-110, wisp has been used for implementing multiple smaller programs, though the biggest program in wisp is still its implementations (written in wisp and bootstrapped via a simpler wisp preprocessor). +</p> + +<p> +But unlike SRFI-110, wisp only uses the minimum of additional syntax-elements which are necessary to support arbitrary code-structures with indentation-sensitive code which is intended to be shared over the internet. To realize these syntax-elements, it generalizes existing syntax and draws on the most common non-letter non-math characters in prose. This allows keeping the actual representation of the code elegant and inviting to newcomers. +</p> + +<p> +Wisp expressions are not as sweet as <a href="http://readable.sf.net">readable</a>, but they KISS. +</p> +</div> +</div> + +<div id="outline-container-sec-3-3" class="outline-3"> +<h3 id="sec-3-3"><span class="section-number-3">3.3</span> Disadvantages of Wisp</h3> +<div class="outline-text-3" id="text-3-3"> +<p> +Using the colon as syntax element keeps the code very close to written prose, but it can interfere with type definitions as for example used in Typed Racket<sup><a id="fnr.2" name="fnr.2" class="footref" href="#fn.2">2</a></sup>. This can be mitigated in let- and lambda-forms by using the parenthesized form. When doing so, wisp avoids the double-paren for type-declarations and as such makes them easier to catch by eye. For function definitions (the only <code>define</code> call where type declarations are needed in typed-racket<sup><a id="fnr.3" name="fnr.3" class="footref" href="#fn.3">3</a></sup>), a <code>declare</code> macro directly before the <code>define</code> should work well. +</p> + +<p> +Using the period to continue the argument list is unusual compared to other languages and as such can lead to errors when trying to return a variable from a procedure and forgetting the period. +</p> +</div> +</div> +</div> + +<div id="outline-container-sec-4" class="outline-2"> +<h2 id="sec-4"><span class="section-number-2">4</span> Specification</h2> +<div class="outline-text-2" id="text-4"> +<p> +The specification is separated into four parts: A general overview of the syntax, a more detailed description, justifications for each added syntax element and clarifications for technical details. +</p> +</div> + +<div id="outline-container-sec-4-1" class="outline-3"> +<h3 id="sec-4-1"><span class="section-number-3">4.1</span> Overview</h3> +<div class="outline-text-3" id="text-4-1"> +<p> +The basics of wisp syntax can be defined in 4 rules, each of which emerges directly from a requirement: +</p> +</div> + +<div id="outline-container-sec-4-1-1" class="outline-4"> +<h4 id="sec-4-1-1"><span class="section-number-4">4.1.1</span> Wisp syntax 1/4: function calls</h4> +<div class="outline-text-4" id="text-4-1-1"> +<p> +Indentation: +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">display</span> +<span style="color: #0000ff;"> +</span> <span style="color: #008b8b;">3</span> <span style="color: #008b8b;">4</span> <span style="color: #008b8b;">5</span> +<span style="color: #0000ff;">newline</span> +</pre> +</div> + +<p> +becomes +</p> + +<div class="org-src-container"> + +<pre class="src src-scheme">(display + (+ 3 4 5)) +(newline) +</pre> +</div> + +<p> +<i>requirement: call functions without parenthesis.</i> +</p> +</div> +</div> + +<div id="outline-container-sec-4-1-2" class="outline-4"> +<h4 id="sec-4-1-2"><span class="section-number-4">4.1.2</span> Wisp syntax 2/4: Continue Argument list</h4> +<div class="outline-text-4" id="text-4-1-2"> +<p> +The period: +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">+</span> <span style="color: #008b8b;">5</span> +<span style="color: #0000ff;"> *</span> <span style="color: #008b8b;">4</span> <span style="color: #008b8b;">3</span> +<span style="color: #a020f0;"> . </span><span style="color: #008b8b;">2</span> <span style="color: #008b8b;">1</span> +</pre> +</div> + +<p> +becomes +</p> + +<div class="org-src-container"> + +<pre class="src src-scheme">(+ 5 + (* 4 3) + 2 1) +</pre> +</div> + +<p> +This also works with just one argument after the period. To start a line without a function call, you have to prefix it with a period followed by whitespace.<sup><a id="fnr.4" name="fnr.4" class="footref" href="#fn.4">4</a></sup> +</p> + +<p> +<i>requirement: continue the argument list of a function after an intermediate call to another function.</i> +</p> +</div> +</div> + +<div id="outline-container-sec-4-1-3" class="outline-4"> +<h4 id="sec-4-1-3"><span class="section-number-4">4.1.3</span> Wisp syntax 3/4: Double Parens</h4> +<div class="outline-text-4" id="text-4-1-3"> +<p> +The colon:<sup><a id="fnr.5" name="fnr.5" class="footref" href="#fn.5">5</a></sup> +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">x</span> <span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> y</span> <span style="color: #008b8b;">2</span> +<span style="color: #0000ff;"> z</span> <span style="color: #008b8b;">3</span> +<span style="color: #0000ff;"> body</span> +</pre> +</div> + +<p> +becomes +</p> + +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">let</span> + ((x 1) + (y 2) + (z 3)) + (body)) +</pre> +</div> + +<p> +<i>requirement: represent code with two adjadent blocks in double-parentheses.</i> +</p> +</div> +</div> + +<div id="outline-container-sec-4-1-4" class="outline-4"> +<h4 id="sec-4-1-4"><span class="section-number-4">4.1.4</span> Wisp syntax 4/4: Resilient Indentation</h4> +<div class="outline-text-4" id="text-4-1-4"> +<p> +The underscore (optional): +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">let</span> +<span style="color: #a020f0;">_ : </span><span style="color: #0000ff;">x</span> <span style="color: #008b8b;">1</span> +<span style="color: #0000ff;">__ y</span> <span style="color: #008b8b;">2</span> +<span style="color: #0000ff;">__ z</span> <span style="color: #008b8b;">3</span> +<span style="color: #0000ff;">_ body</span> +</pre> +</div> + +<p> +becomes +</p> + +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">let</span> + ((x 1) + (y 2) + (z 3)) + (body)) +</pre> +</div> + +<p> +<i>requirement: share code in environments which do not preserve whitespace.</i> +</p> +</div> +</div> + +<div id="outline-container-sec-4-1-5" class="outline-4"> +<h4 id="sec-4-1-5"><span class="section-number-4">4.1.5</span> Summary</h4> +<div class="outline-text-4" id="text-4-1-5"> +<p> +The syntax shown here is the minimal syntax required for the goal of wisp: indentation-based, general lisp with a simple preprocessor, and code which can be shared easily on the internet: +</p> + +<ul class="org-ul"> +<li><code>.</code> to continue the argument list +</li> +<li><code>:</code> for double parens +</li> +<li><code>_</code> to survive HTML +</li> +</ul> +</div> +</div> +</div> + +<div id="outline-container-sec-4-2" class="outline-3"> +<h3 id="sec-4-2"><span class="section-number-3">4.2</span> More detailed: Wisp syntax rules</h3> +<div class="outline-text-3" id="text-4-2"> +</div><div id="outline-container-sec-4-2-1" class="outline-4"> +<h4 id="sec-4-2-1"><span class="section-number-4">4.2.1</span> Unindented line</h4> +<div class="outline-text-4" id="text-4-2-1"> +<p> +<b>A line without indentation is a function call</b>, just as if it would start with a parenthesis. +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">display</span> <span style="color: #C33;">"Hello World!"</span> <span style="color: #898887;">; </span><span style="color: #898887;">(display "Hello World!")</span> +</pre> +</div> +</div> +</div> + +<div id="outline-container-sec-4-2-2" class="outline-4"> +<h4 id="sec-4-2-2"><span class="section-number-4">4.2.2</span> Sibling line</h4> +<div class="outline-text-4" id="text-4-2-2"> +<p> +<b>A line which is more indented than the previous line is a sibling to that line</b>: It opens a new parenthesis. +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">display</span> <span style="color: #898887;">; </span><span style="color: #898887;">(display</span> +<span style="color: #0000ff;"> string-append</span> <span style="color: #C33;">"Hello "</span> <span style="color: #C33;">"World!"</span> <span style="color: #898887;">; </span><span style="color: #898887;">(string-append "Hello " "World!"))</span> +</pre> +</div> +</div> +</div> + +<div id="outline-container-sec-4-2-3" class="outline-4"> +<h4 id="sec-4-2-3"><span class="section-number-4">4.2.3</span> Closing line</h4> +<div class="outline-text-4" id="text-4-2-3"> +<p> +<b>A line which is not more indented than previous line(s) closes the parentheses of all previous lines which have higher or equal indentation</b>. You should only reduce the indentation to indentation levels which were already used by parent lines, else the behaviour is undefined. +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">display</span> <span style="color: #898887;">; </span><span style="color: #898887;">(display</span> +<span style="color: #0000ff;"> string-append</span> <span style="color: #C33;">"Hello "</span> <span style="color: #C33;">"World!"</span> <span style="color: #898887;">; </span><span style="color: #898887;">(string-append "Hello " "World!"))</span> +<span style="color: #0000ff;">display</span> <span style="color: #C33;">"Hello Again!"</span> <span style="color: #898887;">; </span><span style="color: #898887;">(display "Hello Again!")</span> +</pre> +</div> +</div> +</div> + +<div id="outline-container-sec-4-2-4" class="outline-4"> +<h4 id="sec-4-2-4"><span class="section-number-4">4.2.4</span> Prefixed line</h4> +<div class="outline-text-4" id="text-4-2-4"> +<p> +<b>To add any of ' , ` #' #, #` or #@, to the first parenthesis on a line, just prefix the line with that symbol</b> followed by at least one space. Implementations are free to add more prefix symbols. +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">'</span> <span style="color: #C33;">"Hello World!"</span> <span style="color: #898887;">; </span><span style="color: #898887;">'("Hello World!")</span> +</pre> +</div> +</div> +</div> + + +<div id="outline-container-sec-4-2-5" class="outline-4"> +<h4 id="sec-4-2-5"><span class="section-number-4">4.2.5</span> Continuing line</h4> +<div class="outline-text-4" id="text-4-2-5"> +<p> +<b>A line whose first non-whitespace characters is a dot followed by a space (". ") does not open a new parenthesis: it is treated as simple continuation of the first less indented previous line</b>. In the first line this means that this line does not start with a parenthesis and does not end with a parenthesis, just as if you had directly written it in lisp without the leading ". ". +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">string-append</span> <span style="color: #C33;">"Hello"</span> <span style="color: #898887;">; </span><span style="color: #898887;">(string-append "Hello"</span> +<span style="color: #0000ff;"> string-append</span> <span style="color: #C33;">" "</span> <span style="color: #C33;">"World"</span> <span style="color: #898887;">; </span><span style="color: #898887;">(string-append " " "World")</span> +<span style="color: #a020f0;"> . </span><span style="color: #C33;">"!"</span> <span style="color: #898887;">; </span><span style="color: #898887;">"!")</span> +</pre> +</div> +</div> +</div> + + +<div id="outline-container-sec-4-2-6" class="outline-4"> +<h4 id="sec-4-2-6"><span class="section-number-4">4.2.6</span> Empty indentation level</h4> +<div class="outline-text-4" id="text-4-2-6"> +<p> +<b>A line which contains only whitespace and a colon (":") defines an indentation level at the indentation of the colon</b>. It opens a parenthesis which gets closed by the next line which has less or equal indentation. If you need to use a colon by itself. you can escape it as "\:". +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">let</span> <span style="color: #898887;">; </span><span style="color: #898887;">(let</span> +<span style="color: #a020f0;"> : </span> <span style="color: #898887;">; </span><span style="color: #898887;">(</span> +<span style="color: #0000ff;"> msg</span> <span style="color: #C33;">"Hello World!"</span> <span style="color: #898887;">; </span><span style="color: #898887;">(msg "Hello World!"))</span> +<span style="color: #0000ff;"> display</span> msg <span style="color: #898887;">; </span><span style="color: #898887;">(display msg))</span> +</pre> +</div> +</div> +</div> + + +<div id="outline-container-sec-4-2-7" class="outline-4"> +<h4 id="sec-4-2-7"><span class="section-number-4">4.2.7</span> Inline Colon</h4> +<div class="outline-text-4" id="text-4-2-7"> +<p> +<b>A colon sourrounded by whitespace (" : ") starts a parenthesis which gets closed at the end of the line</b>. +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">hello</span> who <span style="color: #898887;">; </span><span style="color: #898887;">(define (hello who)</span> +<span style="color: #0000ff;"> display</span> <span style="color: #898887;">; </span><span style="color: #898887;">(display </span> +<span style="color: #0000ff;"> string-append</span> <span style="color: #C33;">"Hello "</span> who <span style="color: #C33;">"!"</span> <span style="color: #898887;">; </span><span style="color: #898887;">(string-append "Hello " who "!")))</span> +</pre> +</div> + +<p> +If the colon starts a line which also contains other non-whitespace characters, it starts a parenthesis which gets closed at the end of the line <b>and</b> defines an indentation level at the position of the colon. +</p> + +<p> +If the colon is the last non-whitespace character on a line, it represents an empty pair of parentheses: +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">let</span><span style="color: #a020f0;"> : </span> <span style="color: #898887;">; </span><span style="color: #898887;">(let ()</span> +<span style="color: #0000ff;"> display</span> <span style="color: #C33;">"Hello"</span> <span style="color: #898887;">; </span><span style="color: #898887;">(display "Hello"))</span> +</pre> +</div> +</div> +</div> + +<div id="outline-container-sec-4-2-8" class="outline-4"> +<h4 id="sec-4-2-8"><span class="section-number-4">4.2.8</span> Initial Underscores</h4> +<div class="outline-text-4" id="text-4-2-8"> +<p> +<b>You can replace any number of consecutive initial spaces by underscores</b>, as long as at least one whitespace is left between the underscores and any following character. You can escape initial underscores by prefixing the first one with \ ("\___ a" → "(<span class="underline">_</span> a)"), if you have to use them as function names. +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">hello</span> who <span style="color: #898887;">; </span><span style="color: #898887;">(define (hello who)</span> +<span style="color: #0000ff;">_ display</span> <span style="color: #898887;">; </span><span style="color: #898887;">(display </span> +<span style="color: #0000ff;">___ string-append</span> <span style="color: #C33;">"Hello "</span> who <span style="color: #C33;">"!"</span> <span style="color: #898887;">; </span><span style="color: #898887;">(string-append "Hello " who "!")))</span> +</pre> +</div> +</div> +</div> + +<div id="outline-container-sec-4-2-9" class="outline-4"> +<h4 id="sec-4-2-9"><span class="section-number-4">4.2.9</span> Parens and Strings</h4> +<div class="outline-text-4" id="text-4-2-9"> +<p> +<b>Linebreaks inside parentheses and strings are not considered linebreaks</b> for parsing indentation. To use parentheses at the beginning of a line without getting double parens, prefix the line with a period. +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">stringy</span> s +<span style="color: #0000ff;"> string-append</span> s <span style="color: #C33;">" reversed and capitalized:</span> +<span style="color: #C33;"> "</span> <span style="color: #898887;">; </span><span style="color: #898887;">linebreaks in strings do not affect wisp parsing</span> +<span style="color: #a020f0;"> . </span>(<span style="color: #0000ff;">string-capitalize</span> <span style="color: #898887;">; </span><span style="color: #898887;">same for linebreaks in parentheses</span> +<span style="color: #0000ff;"> (string-reverse</span> s)) +</pre> +</div> + +<p> +Effectively code in parentheses and strings is interpreted directly as Scheme. This way you can simply copy a thunk of scheme into wisp. The following is valid wisp: +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span> foo (<span style="color: #0000ff;">+</span> <span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> (*</span> <span style="color: #008b8b;">2</span> <span style="color: #008b8b;">3</span>)) <span style="color: #898887;">; </span><span style="color: #898887;">defines foo as 7</span> +</pre> +</div> +</div> +</div> +</div> + +<div id="outline-container-sec-4-3" class="outline-3"> +<h3 id="sec-4-3"><span class="section-number-3">4.3</span> Clarifications</h3> +<div class="outline-text-3" id="text-4-3"> +<ul class="org-ul"> +<li>Code-blocks end after 2 empty lines followed by a newline. Indented non-empty lines after 2 empty lines should be treated as error. A line is empty if it only contains whitespace. A line with a comment is never empty. +</li> + +<li>Inside parentheses, wisp parsing is disabled. Consequently linebreaks inside parentheses are not considered linebreaks for wisp-parsing. For the parser everything which happens inside parentheses is treated as a black box. +</li> + +<li>Square brackets and curly braces should be treated the same way as parentheses: They stop the indentation processing until they are closed. +</li> + +<li>Likewise linebreaks inside strings are not considered linebreaks for wisp-parsing. +</li> + +<li>A colon (:) at the beginning of a line adds an extra open parentheses that gets closed at end-of-line (rule 4.2.7) <b>and</b> defines an indentation level. +</li> + +<li>using a quote to escape a symbol separated from it by whitespace is forbidden. This would make the meaning of quoted lines ambigous. +</li> + +<li>Curly braces should be treated as curly-infix following SRFI-105. This makes most math look natural to newcomers. +</li> + +<li>Neoteric expressions from SRFI-105 are not required because they create multiple ways to represent the same code. In wisp they add much less advantages than in sweet expressions from SRFI-110, because wisp can continue the arguments to a function after a function call (with the leading period) and the inline colon provides most of the benefits neoteric expressions give to sweet. However implementations providing wisp should give users the option to activate neoteric expressions as by SRFI-105 to allow experimentation and evolution (<a href="http://sourceforge.net/p/readable/mailman/message/33068104/">discussion</a>). +</li> + +<li>It is possible to write code which is at the same time valid wisp and sweet. The readable mailinglist <a href="http://sourceforge.net/p/readable/mailman/message/33058992/">contains details</a>. +</li> +</ul> +</div> +</div> +</div> + +<div id="outline-container-sec-5" class="outline-2"> +<h2 id="sec-5"><span class="section-number-2">5</span> Syntax justification</h2> +<div class="outline-text-2" id="text-5"> +<p> +<i>I do not like adding any unnecessary syntax element to lisp. So I want to show explicitely why the syntax elements are required.</i> +</p> + +<small> +<p> +See also <a href="http://draketo.de/light/english/wisp-lisp-indentation-preprocessor#sec-4">http://draketo.de/light/english/wisp-lisp-indentation-preprocessor#sec-4</a> +</p> +</small> +</div> + + +<div id="outline-container-sec-5-1" class="outline-3"> +<h3 id="sec-5-1"><span class="section-number-3">5.1</span> . (the dot)</h3> +<div class="outline-text-3" id="text-5-1"> +<p> +To represent general code trees, we have to be able to represent continuation of the arguments of a function with an intermediate call to another (or the same) function. +</p> + +<p> +The dot at the beginning of the line as marker of the continuation of a variable list is a generalization of using the dot as identity function - which is an implementation detail in many lisps. +</p> + +<blockquote> +<p> +<code>(. a)</code> is just <code>a</code> +</p> +</blockquote> + +<p> +So for the single variable case, this would not even need additional parsing: wisp could just parse <code>. a</code> to <code>(. a)</code> and produce the correct result in most lisps. But forcing programmers to always use separate lines for each parameter would be very inconvenient, so the definition of the dot at the beginning of the line is extended to mean “take every element in this line as parameter to the parent function”. +</p> + +<blockquote> +<p> +<code>(. a)</code> → <code>a</code> is generalized to <code>(. a b c)</code> → <code>a b c</code>. +</p> +</blockquote> + +<p> +At its core, this dot-rule means that we mark variables in the code instead of function calls. We do so, because variables at the beginning of a line are much rarer in Scheme than in other programming languages. +</p> +</div> +</div> + +<div id="outline-container-sec-5-2" class="outline-3"> +<h3 id="sec-5-2"><span class="section-number-3">5.2</span> : (the colon)</h3> +<div class="outline-text-3" id="text-5-2"> +<p> +For double parentheses and for some other cases we must have a way to mark indentation levels which do not contain code. Wisp uses the colon, because it is the most common non-alpha-numeric character in normal prose which is not already reserved as syntax by Scheme when it is surrounded by whitespace, and because it already gets used without sourrounding whitespace for marking keyword arguments to functions in Emacs Lisp and Common Lisp, so it does not add completely alien concepts. +</p> + +<p> +The inline function call via inline " : " is a limited generalization of using the colon to mark an indentation level: If we add a syntax-element, we should use it as widely as possible to justify adding syntax overhead. +</p> + +<p> +But if you need to use <code>:</code> as variable or function name, you can still do so by escaping it with a backslash (<code>\:</code>), so this does not forbid using the character. +</p> + +<p> +For simple cases, the colon could be replaced by clever whitespace parsing, but there are complex cases which make this impossible. The minimal example is a theoretical doublelet which does not require a body:<sup><a id="fnr.6" name="fnr.6" class="footref" href="#fn.6">6</a></sup> +</p> + +<div class="org-src-container"> + +<pre class="src src-scheme">(doublelet + ((foo bar)) + ((bla foo))) +</pre> +</div> + +<p> +The wisp version of this is +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">doublelet</span> +<span style="color: #a020f0;"> :</span> +<span style="color: #0000ff;"> foo</span> bar +<span style="color: #a020f0;"> : </span><span style="color: #898887;">; </span><span style="color: #898887;"><- this empty backstep is the real issue</span> +<span style="color: #0000ff;"> bla</span> foo +</pre> +</div> + +<p> +or shorter with inline colon (which you can use only if you don’t need further indentation-syntax inside the assignment). +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">doublelet</span> +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">foo</span> bar +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">bla</span> foo +</pre> +</div> + +<p> +The need to be able to represent arbitrary syntax trees which can contain expressions like this is the real reason, why the colon exists. The inline and start-of-line use is only a generalization of that principle (we add a syntax-element, so we should see how far we can push it to reduce the effective cost of introducing the additional syntax). +</p> +</div> + +<div id="outline-container-sec-5-2-1" class="outline-4"> +<h4 id="sec-5-2-1"><span class="section-number-4">5.2.1</span> Clever whitespace-parsing which would not work</h4> +<div class="outline-text-4" id="text-5-2-1"> +<p> +There are two alternative ways to tackle this issue: deferred level-definition and fixed-width indentation. +</p> + +<p> +Defining intermediate indentation-levels by later elements (deferred definition) would be a problem, because it would create code which is really hard to understand. An example is the following: +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span> (<span style="color: #0000ff;">flubb</span>) +<span style="color: #0000ff;"> nubb</span> +<span style="color: #0000ff;"> hubb</span> +<span style="color: #0000ff;"> subb</span> +<span style="color: #0000ff;"> gam</span> +</pre> +</div> + +<p> +would become +</p> + +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">flubb</span>) + ((nubb)) + ((hubb)) + ((subb)) + (gam)) +</pre> +</div> + +<p> +while +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span> (<span style="color: #0000ff;">flubb</span>) +<span style="color: #0000ff;"> nubb</span> +<span style="color: #0000ff;"> hubb</span> +<span style="color: #0000ff;"> subb</span> +</pre> +</div> + +<p> +would become +</p> + +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">flubb</span>) + (nubb) + (hubb) + (subb)) +</pre> +</div> + +<p> +Knowledge of later parts of the code would be necessary to understand the parts a programmer is working on at the moment. This would call for subtle errors which would be hard to track down, because the effect of a change in code would not be localized at the point where the change is done but could propagate backwards. +</p> + +<p> +Fixed indentation width (alternative option to inferring it from later lines) would make it really hard to write readable code. Stuff like this would not be possible: +</p> + +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">when</span> +<span style="color: #0000ff;"> equal?</span> wrong +<span style="color: #0000ff;"> isright?</span> stuff +<span style="color: #0000ff;"> fixstuff</span> +</pre> +</div> +</div> +</div> +</div> + +<div id="outline-container-sec-5-3" class="outline-3"> +<h3 id="sec-5-3"><span class="section-number-3">5.3</span> _ (the underscore)</h3> +<div class="outline-text-3" id="text-5-3"> +<p> +In Python the whitespace hostile html already presents problems with sharing code - for example in email list archives and forums. But Python-programmers can mostly infer the indentation by looking at the previous line: If that ends with a colon, the next line must be more indented (there is nothing to clearly mark reduced indentation, though). In wisp we do not have this support, so we need a way to survive in the hostile environment of todays web. +</p> + +<p> +The underscore is commonly used to denote a space in URLs, where spaces are inconvenient, but it is rarely used in Scheme (where the dash ("-") is mostly used instead), so it seems like a a natural choice. +</p> + +<p> +You can still use underscores anywhere but at the beginning of the line, and even at the beginning of the line you simply need to escape it by prefixing the first underscore with a backslash ("\____"). +</p> +</div> +</div> +</div> + +<div id="outline-container-sec-6" class="outline-2"> +<h2 id="sec-6"><span class="section-number-2">6</span> Implementation</h2> +<div class="outline-text-2" id="text-6"> +<p> +This reference implementation realizes a specialized parser for Scheme. It uses GNU Guile and can also be used at the REPL. +</p> + +<p> +The wisp code also contains a general wisp-preprocessor which can be used for any lisp-like language and can used as an external program which gets called on reading. It does not actually have to understand the code itself. This is not part of this SRFI, though. +</p> + +<p> +To allow for easy re-implementation, the chapter after the implementation itself contains a test-suite with commonly used wisp constructs and parenthesized counterparts. +</p> + +<p> +The wisp preprocessor implementation can be found at <a href="http://draketo.de/proj/wisp">http://draketo.de/proj/wisp</a>. Both implementations are explicitly licensed to allow inclusion in an SRFI. +</p> +</div> + +<div id="outline-container-sec-6-1" class="outline-3"> +<h3 id="sec-6-1"><span class="section-number-3">6.1</span> The generic wisp processor (code)</h3> +<div class="outline-text-3" id="text-6-1"> +<p> +TODO: Include the code from <a href="http://draketo.de/proj/wisp">http://draketo.de/proj/wisp</a> +</p> +</div> +</div> + +<div id="outline-container-sec-6-2" class="outline-3"> +<h3 id="sec-6-2"><span class="section-number-3">6.2</span> Test Suite</h3> +<div class="outline-text-3" id="text-6-2"> +<p> +The wisp test-suite consists of a large number of wisp-snippets and the corresponding scheme-code. +</p> + +<p> +A wisp-implementation may call itself compliant with the wisp test-suite if the code tree parsed from the wisp file is the same as a code tree parsed from the equivalent Scheme file. +</p> + +<p> +A wisp-implementation may call itself a compliant wisp pre-processor if it successfully converts each wisp-snippet into the corresponging scheme-snippet. Blank lines at the end of the file and non-functional white-space in the produced scheme-file do not matter for this purpose. +</p> + +<p> +This test-suite is also available in the <a href="http://draketo.de/proj/wisp">wisp repository</a> along with a script-runner (runtests.sh) which tests the reference wisp-implementation with GNU Guile against this testsuite.<sup><a id="fnr.7" name="fnr.7" class="footref" href="#fn.7">7</a></sup> +</p> +</div> + +<div id="outline-container-sec-6-2-1" class="outline-4"> +<h4 id="sec-6-2-1"><span class="section-number-4">6.2.1</span> tests/syntax-underscore.w</h4> +<div class="outline-text-4" id="text-6-2-1"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">a</span> b c +<span style="color: #0000ff;">_ d</span> e +<span style="color: #0000ff;">___ f</span> +<span style="color: #0000ff;">___</span> g h +<span style="color: #0000ff;">__</span><span style="color: #a020f0;"> . </span>i + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">_</span> +<span style="color: #0000ff;">_ display</span> <span style="color: #C33;">"hello\n"</span> + +<span style="color: #0000ff;">\_</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-2" class="outline-4"> +<h4 id="sec-6-2-2"><span class="section-number-4">6.2.2</span> tests/syntax-underscore.scm</h4> +<div class="outline-text-4" id="text-6-2-2"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">a</span> b c) + (d e + (f) + (g h) + i)) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">_</span>) + (display <span style="color: #C33;">"hello\n"</span>)) + +(_) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-3" class="outline-4"> +<h4 id="sec-6-2-3"><span class="section-number-4">6.2.3</span> tests/syntax-strings-parens.w</h4> +<div class="outline-text-4" id="text-6-2-3"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #898887;">; </span><span style="color: #898887;">Test linebreaks in strings and brackets</span> + +<span style="color: #a020f0;">. </span><span style="color: #C33;">"flubbub</span> + +<span style="color: #C33;">flabbab"</span> + +hrug (<span style="color: #0000ff;">nadda</span> +<span style="color: #0000ff;">madda</span> gadda <span style="color: #C33;">"shoktom</span> +<span style="color: #C33;"> mee"</span> <span style="color: #C33;">" sep </span> +<span style="color: #C33;">ka"</span> +<span style="color: #0000ff;"> hadda)</span> +<span style="color: #0000ff;"> gom</span> + +<span style="color: #0000ff;">flu</span> + +<span style="color: #0000ff;">sum</span> [foo +<span style="color: #0000ff;">bar]</span> barz {1 + [* <span style="color: #008b8b;">2</span> <span style="color: #008b8b;">2</span>]} + +<span style="color: #0000ff;">mara</span> { +<span style="color: #0000ff;">li</span> +<span style="color: #0000ff;">+</span> +<span style="color: #0000ff;">lo</span> - (<span style="color: #0000ff;">mabba</span>) +<span style="color: #0000ff;">}</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-4" class="outline-4"> +<h4 id="sec-6-2-4"><span class="section-number-4">6.2.4</span> tests/syntax-strings-parens.scm</h4> +<div class="outline-text-4" id="text-6-2-4"> +<div class="org-src-container"> + +<pre class="src src-scheme"><span style="color: #898887;">; </span><span style="color: #898887;">Test linebreaks in strings and brackets</span> + +<span style="color: #C33;">"flubbub</span> + +<span style="color: #C33;">flabbab"</span> + +(hrug (nadda +madda gadda <span style="color: #C33;">"shoktom</span> +<span style="color: #C33;"> mee"</span> <span style="color: #C33;">" sep </span> +<span style="color: #C33;">ka"</span> + hadda) + (gom)) + +(flu) + +(sum [foo +bar] barz {1 + [* 2 2]}) + +(mara { +li ++ +lo - (mabba) +}) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-5" class="outline-4"> +<h4 id="sec-6-2-5"><span class="section-number-4">6.2.5</span> tests/syntax-indent.w</h4> +<div class="outline-text-4" id="text-6-2-5"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span> +<span style="color: #0000ff;"> hello</span> who +<span style="color: #0000ff;"> format</span> <span style="color: #008b8b;">#t</span> <span style="color: #C33;">"Hello ~A\n"</span> who + +<span style="color: #483d8b;">define</span> + <span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> :</span> +<span style="color: #0000ff;"> a</span> <span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> b</span> <span style="color: #008b8b;">2</span> +<span style="color: #0000ff;"> c</span> <span style="color: #008b8b;">3</span> +<span style="color: #0000ff;"> format</span> <span style="color: #008b8b;">#t</span> <span style="color: #C33;">"a: ~A, b: ~A, c: ~A"</span> +<span style="color: #0000ff;"> +</span> a <span style="color: #008b8b;">2</span> +<span style="color: #a020f0;"> . </span> b c +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-6" class="outline-4"> +<h4 id="sec-6-2-6"><span class="section-number-4">6.2.6</span> tests/syntax-indent.scm</h4> +<div class="outline-text-4" id="text-6-2-6"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> + (hello who) + (format #t <span style="color: #C33;">"Hello ~A\n"</span> who)) + +(<span style="color: #a020f0;">define</span> + (<span style="color: #a020f0;">let</span> + ( + (a 1) + (b 2) + (c 3)) + (format #t <span style="color: #C33;">"a: ~A, b: ~A, c: ~A"</span> + (+ a 2) + b c))) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-7" class="outline-4"> +<h4 id="sec-6-2-7"><span class="section-number-4">6.2.7</span> tests/syntax-empty.w</h4> +<div class="outline-text-4" id="text-6-2-7"> +<div class="org-src-container"> + +<pre class="src src-wisp"></pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-8" class="outline-4"> +<h4 id="sec-6-2-8"><span class="section-number-4">6.2.8</span> tests/syntax-empty.scm</h4> +<div class="outline-text-4" id="text-6-2-8"> +<div class="org-src-container"> + +<pre class="src src-scheme"></pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-9" class="outline-4"> +<h4 id="sec-6-2-9"><span class="section-number-4">6.2.9</span> tests/syntax-dot.w</h4> +<div class="outline-text-4" id="text-6-2-9"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">foo</span> +<span style="color: #a020f0;"> . </span><span style="color: #C33;">"bar"</span> + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">bar</span> +<span style="color: #0000ff;"> '</span> <span style="color: #008b8b;">1</span> +<span style="color: #a020f0;"> . . </span><span style="color: #008b8b;">2</span> <span style="color: #898887;">; </span><span style="color: #898887;">pair</span> + +<span style="color: #0000ff;">display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">foo</span> +<span style="color: #0000ff;">newline</span> +<span style="color: #0000ff;">display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">bar</span> +<span style="color: #0000ff;">newline</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-10" class="outline-4"> +<h4 id="sec-6-2-10"><span class="section-number-4">6.2.10</span> tests/syntax-dot.scm</h4> +<div class="outline-text-4" id="text-6-2-10"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">foo</span>) + <span style="color: #C33;">"bar"</span>) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">bar</span>) + '(1 + . 2 ))<span style="color: #898887;">; </span><span style="color: #898887;">pair</span> + +(display (foo)) +(newline) +(display (bar)) +(newline) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-11" class="outline-4"> +<h4 id="sec-6-2-11"><span class="section-number-4">6.2.11</span> tests/syntax-colon.w</h4> +<div class="outline-text-4" id="text-6-2-11"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> :</span> +<span style="color: #0000ff;"> a</span> <span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> b</span> <span style="color: #008b8b;">2</span> + <span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> :</span> +<span style="color: #a020f0;"> :</span> +<span style="color: #a020f0;"> . </span>c <span style="color: #008b8b;">3</span> +<span style="color: #0000ff;"> format</span> <span style="color: #008b8b;">#t</span> <span style="color: #C33;">"a: ~A, b: ~A, c: ~A"</span> +<span style="color: #a020f0;"> . </span> a b c + +<span style="color: #a020f0;">: </span>a + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">hello</span> +<span style="color: #0000ff;"> display</span> <span style="color: #C33;">"hello\n"</span> + +<span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">a</span> <span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> b</span> <span style="color: #008b8b;">2</span> +<span style="color: #0000ff;"> format</span> <span style="color: #008b8b;">#t</span> <span style="color: #C33;">"a: ~A, b: ~A"</span> +<span style="color: #a020f0;"> . </span> a b + +<span style="color: #483d8b;">let</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">:</span> a ' : + +<span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> : </span> <span style="color: #898887;">; </span><span style="color: #898887;">foo</span> +<span style="color: #0000ff;"> a</span> + ' + +<span style="color: #a020f0;">:</span> + a + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">\:</span> +<span style="color: #0000ff;"> hello</span> + +<span style="color: #0000ff;">\:</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-12" class="outline-4"> +<h4 id="sec-6-2-12"><span class="section-number-4">6.2.12</span> tests/syntax-colon.scm</h4> +<div class="outline-text-4" id="text-6-2-12"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">let</span> + ( + (a 1) + (b 2)) + (<span style="color: #a020f0;">let</span> + ( + ( + c 3)) + (format #t <span style="color: #C33;">"a: ~A, b: ~A, c: ~A"</span> + a b c))) + +((a)) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">hello</span>) + (display <span style="color: #C33;">"hello\n"</span>)) + +(<span style="color: #a020f0;">let</span> + ((a 1) + (b 2)) + (format #t <span style="color: #C33;">"a: ~A, b: ~A"</span> + a b)) + +(<span style="color: #a020f0;">let</span> ((a '()))) + +(<span style="color: #a020f0;">let</span> + ( <span style="color: #898887;">; </span><span style="color: #898887;">foo</span> + (a + '()))) + +( + (a)) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">:</span>) + (hello)) + +(:) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-13" class="outline-4"> +<h4 id="sec-6-2-13"><span class="section-number-4">6.2.13</span> tests/sublist.w</h4> +<div class="outline-text-4" id="text-6-2-13"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #898887;">; </span><span style="color: #898887;">sublists allow to start single line function calls with a colon ( : ).</span> + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">a</span> b c + <span style="color: #483d8b;">let</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">:</span> e<span style="color: #a020f0;"> . </span>f +<span style="color: #a020f0;"> . </span>g +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-14" class="outline-4"> +<h4 id="sec-6-2-14"><span class="section-number-4">6.2.14</span> tests/sublist.scm</h4> +<div class="outline-text-4" id="text-6-2-14"> +<div class="org-src-container"> + +<pre class="src src-scheme"><span style="color: #898887;">; </span><span style="color: #898887;">sublists allow to start single line function calls with a colon ( : ).</span> + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">a</span> b c) + (<span style="color: #a020f0;">let</span> ((e . f)) + g)) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-15" class="outline-4"> +<h4 id="sec-6-2-15"><span class="section-number-4">6.2.15</span> tests/hashbang.w</h4> +<div class="outline-text-4" id="text-6-2-15"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #898887;">#!/usr/bin/wisp.py # !#</span> +<span style="color: #898887;">; </span><span style="color: #898887;">This tests hashbang lines</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-16" class="outline-4"> +<h4 id="sec-6-2-16"><span class="section-number-4">6.2.16</span> tests/hashbang.scm</h4> +<div class="outline-text-4" id="text-6-2-16"> +<div class="org-src-container"> + +<pre class="src src-scheme">#!/usr/bin/wisp.py # !# +<span style="color: #898887;">; </span><span style="color: #898887;">This tests hashbang lines</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-17" class="outline-4"> +<h4 id="sec-6-2-17"><span class="section-number-4">6.2.17</span> tests/readable-tests.w</h4> +<div class="outline-text-4" id="text-6-2-17"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">fibfast</span> n + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;"><</span> n <span style="color: #008b8b;">2</span> +<span style="color: #a020f0;"> . </span>n +<span style="color: #0000ff;"> fibup</span> n <span style="color: #008b8b;">2</span> <span style="color: #008b8b;">1</span> <span style="color: #008b8b;">0</span> + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">fibup</span> maxnum count n-1 n-2 + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">=</span> maxnum count +<span style="color: #0000ff;"> +</span> n-1 n-2 +<span style="color: #0000ff;"> fibup</span> maxnum +<span style="color: #0000ff;"> +</span> count <span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> +</span> n-1 n-2 +<span style="color: #a020f0;"> . </span>n-1 + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> n + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;"><=</span> n <span style="color: #008b8b;">1</span> +<span style="color: #a020f0;"> . </span><span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> *</span> n +<span style="color: #0000ff;"> factorial</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">-</span> n <span style="color: #008b8b;">1</span> + +<span style="color: #483d8b;">define</span> (<span style="color: #0000ff;">gcd</span> x y) + <span style="color: #483d8b;">if</span> (<span style="color: #0000ff;">=</span> y <span style="color: #008b8b;">0</span>) +<span style="color: #a020f0;"> . </span>x +<span style="color: #0000ff;"> gcd</span> y +<span style="color: #0000ff;"> rem</span> x y + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">add-if-all-numbers</span> lst +<span style="color: #0000ff;"> call/cc</span> +<span style="color: #0000ff;"> lambda</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">exit</span> + <span style="color: #483d8b;">let</span> loop +<span style="color: #a020f0;"> : </span> +<span style="color: #0000ff;"> lst</span> lst +<span style="color: #0000ff;"> sum</span> <span style="color: #008b8b;">0</span> + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">null?</span> lst +<span style="color: #a020f0;"> . </span>sum + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #483d8b;">not</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">number?</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">car</span> lst +<span style="color: #0000ff;"> exit</span> <span style="color: #008b8b;">#f</span> +<span style="color: #0000ff;"> +</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">car</span> lst +<span style="color: #0000ff;"> loop</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">cdr</span> lst +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-18" class="outline-4"> +<h4 id="sec-6-2-18"><span class="section-number-4">6.2.18</span> tests/readable-tests.scm</h4> +<div class="outline-text-4" id="text-6-2-18"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">fibfast</span> n) + (<span style="color: #a020f0;">if</span> (< n 2)) + n + (fibup n 2 1 0 )) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">fibup</span> maxnum count n-1 n-2) + (<span style="color: #a020f0;">if</span> (= maxnum count) + (+ n-1 n-2) + (fibup maxnum + (+ count 1 ) + (+ n-1 n-2 ) + n-1))) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">factorial</span> n) + (<span style="color: #a020f0;">if</span> (<= n 1) + 1 + (* n + (factorial (- n 1))))) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">gcd</span> x y) + (<span style="color: #a020f0;">if</span> (= y 0)) + x + (gcd y + (rem x y))) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">add-if-all-numbers</span> lst) + (<span style="color: #a020f0;">call/cc</span> + (<span style="color: #a020f0;">lambda</span> (exit) + (<span style="color: #a020f0;">let</span> <span style="color: #0000ff;">loop</span> + ( + (lst lst ) + (sum 0)) + (<span style="color: #a020f0;">if</span> (null? lst) + sum + (<span style="color: #a020f0;">if</span> (not (number? (car lst))) + (exit #f) + (+ (car lst) + (loop (cdr lst))))))))) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-19" class="outline-4"> +<h4 id="sec-6-2-19"><span class="section-number-4">6.2.19</span> tests/quotecolon.w</h4> +<div class="outline-text-4" id="text-6-2-19"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #898887;">#!/home/arne/wisp/wisp-multiline.sh </span> +<span style="color: #898887;">; </span><span style="color: #898887;">!#</span> +<span style="color: #483d8b;">define</span> a <span style="color: #008b8b;">1</span> <span style="color: #898887;">; </span><span style="color: #898887;">test whether ' : correctly gets turned into '(</span> +<span style="color: #898887;">; </span><span style="color: #898887;">and whether brackets in commments are treated correctly.</span> + +<span style="color: #483d8b;">define</span> a '<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">1</span> <span style="color: #008b8b;">2</span> <span style="color: #008b8b;">3</span> + +<span style="color: #483d8b;">define</span> +<span style="color: #0000ff;"> a</span> b +<span style="color: #0000ff;"> c</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-20" class="outline-4"> +<h4 id="sec-6-2-20"><span class="section-number-4">6.2.20</span> tests/quotecolon.scm</h4> +<div class="outline-text-4" id="text-6-2-20"> +<div class="org-src-container"> + +<pre class="src src-scheme">#!/home/arne/wisp/wisp-multiline.sh +<span style="color: #898887;">; </span><span style="color: #898887;">!#</span> +(<span style="color: #a020f0;">define</span> <span style="color: #0000ff;">a</span> 1 )<span style="color: #898887;">; </span><span style="color: #898887;">test whether ' : correctly gets turned into '(</span> +<span style="color: #898887;">; </span><span style="color: #898887;">and whether brackets in commments are treated correctly.</span> + +(<span style="color: #a020f0;">define</span> <span style="color: #0000ff;">a</span> '(1 2 3)) + +(<span style="color: #a020f0;">define</span> + (a b) + (c)) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-21" class="outline-4"> +<h4 id="sec-6-2-21"><span class="section-number-4">6.2.21</span> tests/namedlet.w</h4> +<div class="outline-text-4" id="text-6-2-21"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #898887;">#!/home/arne/wisp/wisp-multiline.sh </span> +<span style="color: #898887;">; </span><span style="color: #898887;">!#</span> +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">hello</span> who +<span style="color: #0000ff;"> display</span> who + +<span style="color: #483d8b;">let</span> hello +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">who</span> <span style="color: #008b8b;">0</span> + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">=</span> who <span style="color: #008b8b;">5</span> +<span style="color: #0000ff;"> display</span> who +<span style="color: #0000ff;"> hello</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">+</span> <span style="color: #008b8b;">1</span> who +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-22" class="outline-4"> +<h4 id="sec-6-2-22"><span class="section-number-4">6.2.22</span> tests/namedlet.scm</h4> +<div class="outline-text-4" id="text-6-2-22"> +<div class="org-src-container"> + +<pre class="src src-scheme">#!/home/arne/wisp/wisp-multiline.sh +<span style="color: #898887;">; </span><span style="color: #898887;">!#</span> +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">hello</span> who) + (display who)) + +(<span style="color: #a020f0;">let</span> <span style="color: #0000ff;">hello</span> + ((who 0)) + (<span style="color: #a020f0;">if</span> (= who 5) + (display who) + (hello (+ 1 who)))) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-23" class="outline-4"> +<h4 id="sec-6-2-23"><span class="section-number-4">6.2.23</span> tests/flexible-parameter-list.w</h4> +<div class="outline-text-4" id="text-6-2-23"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #898887;">; </span><span style="color: #898887;">Test using a . as first parameter on a line by prefixing it with a second .</span> +<span style="color: #483d8b;">define</span> +<span style="color: #0000ff;"> a</span> i +<span style="color: #a020f0;"> . . </span>b +<span style="color: #0000ff;"> unless</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">>=</span> i<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">length</span> b +<span style="color: #0000ff;"> display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">number->string</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">length</span> b +<span style="color: #0000ff;"> display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">list-ref</span> b i +<span style="color: #0000ff;"> newline</span> +<span style="color: #0000ff;"> apply</span> a ( <span style="color: #0000ff;">+</span> i <span style="color: #008b8b;">1</span> ) b + + +<span style="color: #0000ff;">a</span> <span style="color: #008b8b;">0</span> <span style="color: #C33;">"123"</span> <span style="color: #C33;">"345"</span> <span style="color: #C33;">"567"</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-24" class="outline-4"> +<h4 id="sec-6-2-24"><span class="section-number-4">6.2.24</span> tests/flexible-parameter-list.scm</h4> +<div class="outline-text-4" id="text-6-2-24"> +<div class="org-src-container"> + +<pre class="src src-scheme"><span style="color: #898887;">; </span><span style="color: #898887;">Test using a . as first parameter on a line by prefixing it with a second .</span> +(<span style="color: #a020f0;">define</span> + (a i + . b) + (unless (>= i (length b)) + (display (number->string (length b ))) + (display (list-ref b i)) + (newline) + (apply a ( + i 1 ) b))) + + +(a 0 <span style="color: #C33;">"123"</span> <span style="color: #C33;">"345"</span> <span style="color: #C33;">"567"</span>) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-25" class="outline-4"> +<h4 id="sec-6-2-25"><span class="section-number-4">6.2.25</span> tests/factorial.w</h4> +<div class="outline-text-4" id="text-6-2-25"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #898887;">;; </span><span style="color: #898887;">short version</span> +<span style="color: #898887;">; </span><span style="color: #898887;">note: once you use one inline colon, all the following forms on that</span> +<span style="color: #898887;">; </span><span style="color: #898887;">line will get closed at the end of the line</span> + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> n + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">zero?</span> n +<span style="color: #a020f0;"> . </span><span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> *</span> n<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">-</span> n <span style="color: #008b8b;">1</span> + +<span style="color: #0000ff;">display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> <span style="color: #008b8b;">5</span> + + +<span style="color: #898887;">;; </span><span style="color: #898887;">more vertical space, less colons</span> +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> n + <span style="color: #483d8b;">if</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">zero?</span> n +<span style="color: #a020f0;"> . </span><span style="color: #008b8b;">1</span> +<span style="color: #0000ff;"> *</span> n +<span style="color: #0000ff;"> factorial</span> +<span style="color: #0000ff;"> -</span> n <span style="color: #008b8b;">1</span> + +<span style="color: #0000ff;">display</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">factorial</span> <span style="color: #008b8b;">5</span> +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-26" class="outline-4"> +<h4 id="sec-6-2-26"><span class="section-number-4">6.2.26</span> tests/factorial.scm</h4> +<div class="outline-text-4" id="text-6-2-26"> +<div class="org-src-container"> + +<pre class="src src-scheme"><span style="color: #898887;">;; </span><span style="color: #898887;">short version</span> +<span style="color: #898887;">; </span><span style="color: #898887;">note: once you use one inline colon, all the following forms on that</span> +<span style="color: #898887;">; </span><span style="color: #898887;">line will get closed at the end of the line</span> + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">factorial</span> n) + (<span style="color: #a020f0;">if</span> (zero? n) + 1 + (* n (factorial (- n 1))))) + +(display (factorial 5 )) + + +<span style="color: #898887;">;; </span><span style="color: #898887;">more vertical space, less colons</span> +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">factorial</span> n) + (<span style="color: #a020f0;">if</span> (zero? n) + 1 + (* n + (factorial + (- n 1))))) + +(display (factorial 5 )) +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-27" class="outline-4"> +<h4 id="sec-6-2-27"><span class="section-number-4">6.2.27</span> tests/example.w</h4> +<div class="outline-text-4" id="text-6-2-27"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #483d8b;">define</span> (<span style="color: #0000ff;">a</span> b c) + <span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> : </span> +<span style="color: #0000ff;"> d</span> <span style="color: #C33;">"i am a string</span> +<span style="color: #C33;">do not break me!"</span> +<span style="color: #a020f0;"> : </span> + <span style="color: #898887;">; </span><span style="color: #898887;">comment: 0</span> + f +<span style="color: #898887;">; </span><span style="color: #898887;">comment : 1</span> +<span style="color: #0000ff;"> `</span> g <span style="color: #898887;">; </span><span style="color: #898887;">comment " : " 2</span> +<span style="color: #a020f0;"> : </span> +<span style="color: #0000ff;"> h</span> (<span style="color: #0000ff;">I</span> am in brackets: +<span style="color: #0000ff;"> do</span> <span style="color: #483d8b;">not</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">change</span> <span style="color: #C33;">"me"</span>) +<span style="color: #a020f0;"> . </span>i +<span style="color: #0000ff;"> ,</span><span style="color: #008b8b;"> 'j</span> k + +<span style="color: #a020f0;"> . </span>l + +<span style="color: #898887;">; </span><span style="color: #898887;">comment</span> + +<span style="color: #0000ff;"> a</span> c + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">b</span> :n o +<span style="color: #a020f0;"> . </span><span style="color: #C33;">"second defun : with a docstring!"</span> +<span style="color: #0000ff;"> message</span> <span style="color: #C33;">"I am here"</span> +<span style="color: #a020f0;"> . </span>t + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">c</span> e f +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">g</span> +<span style="color: #a020f0;"> :</span> +<span style="color: #0000ff;"> h</span> +<span style="color: #0000ff;"> i</span> +<span style="color: #0000ff;"> j</span> +<span style="color: #0000ff;"> '</span> : +<span style="color: #0000ff;"> k</span> +<span style="color: #a020f0;"> . </span>l +<span style="color: #a020f0;"> . </span>: <span style="color: #0000ff;">m</span> + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">_</span> \: +<span style="color: #0000ff;">__</span> +<span style="color: #0000ff;">__</span><span style="color: #a020f0;"> . </span>\: + +<span style="color: #0000ff;">\_</span> b + +<span style="color: #483d8b;">define</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">d</span> + <span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">a</span> b +<span style="color: #0000ff;"> c</span> d + +<span style="color: #0000ff;">a</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">:</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">c</span> + +<span style="color: #483d8b;">let</span> +<span style="color: #a020f0;"> : </span><span style="color: #0000ff;">a</span> b + c + +<span style="color: #483d8b;">let</span><span style="color: #a020f0;"> : </span><span style="color: #0000ff;">:</span> a b + +<span style="color: #a020f0;">. </span>a +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-28" class="outline-4"> +<h4 id="sec-6-2-28"><span class="section-number-4">6.2.28</span> tests/example.scm</h4> +<div class="outline-text-4" id="text-6-2-28"> +<div class="org-src-container"> + +<pre class="src src-scheme">(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">a</span> b c) + (<span style="color: #a020f0;">let</span> + ( + (d <span style="color: #C33;">"i am a string</span> +<span style="color: #C33;">do not break me!"</span>) + ( + <span style="color: #898887;">; </span><span style="color: #898887;">comment: 0</span> + (f) +<span style="color: #898887;">; </span><span style="color: #898887;">comment : 1</span> + `(g ))<span style="color: #898887;">; </span><span style="color: #898887;">comment " : " 2</span> + ( + (h (I am in brackets: + do not : change <span style="color: #C33;">"me"</span>)) + i))) + ,('j k) + + l + +<span style="color: #898887;">; </span><span style="color: #898887;">comment</span> + + (a c)) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">b</span> <span style="color: #483d8b;">:n</span> o) + <span style="color: #C33;">"second defun : with a docstring!"</span> + (message <span style="color: #C33;">"I am here"</span>) + t) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">c</span> e f) + ((g)) + ( + (h + (i)) + (j)) + '(()) + (k) + l + (m)) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">_</span> :) + + :) + +(_ b) + +(<span style="color: #a020f0;">define</span> (<span style="color: #0000ff;">d</span>) + (<span style="color: #a020f0;">let</span> + ((a b) + (c d)))) + +(a (((c)))) + +(<span style="color: #a020f0;">let</span> + ((a b) + (c))) + +(<span style="color: #a020f0;">let</span> ((a b))) + +a +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-29" class="outline-4"> +<h4 id="sec-6-2-29"><span class="section-number-4">6.2.29</span> tests/continuation.w</h4> +<div class="outline-text-4" id="text-6-2-29"> +<div class="org-src-container"> + +<pre class="src src-wisp"><span style="color: #0000ff;">a</span> b c d e +<span style="color: #a020f0;"> . </span>f g h +<span style="color: #a020f0;"> . </span>i j k + +<span style="color: #0000ff;">concat</span> <span style="color: #C33;">"I want "</span> +<span style="color: #0000ff;"> getwish</span> from me +<span style="color: #a020f0;"> . </span><span style="color: #C33;">" - "</span> username +</pre> +</div> +</div> +</div> +<div id="outline-container-sec-6-2-30" class="outline-4"> +<h4 id="sec-6-2-30"><span class="section-number-4">6.2.30</span> tests/continuation.scm</h4> +<div class="outline-text-4" id="text-6-2-30"> +<div class="org-src-container"> + +<pre class="src src-scheme">(a b c d e + f g h + i j k) + +(concat <span style="color: #C33;">"I want "</span> + (getwish from me) + <span style="color: #C33;">" - "</span> username) +</pre> +</div> +</div> +</div> +</div> +</div> +<div id="outline-container-sec-7" class="outline-2"> +<h2 id="sec-7"><span class="section-number-2">7</span> Copyright</h2> +<div class="outline-text-2" id="text-7"> +<p> +Copyright (C) Arne Babenhauserheide (2013–2014). All Rights Reserved. +</p> + +<p> +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +</p> + +<p> +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +</p> + +<p> +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +</p> +</div> +</div> +<div id="footnotes"> +<h2 class="footnotes">Footnotes: </h2> +<div id="text-footnotes"> + +<div class="footdef"><sup><a id="fn.1" name="fn.1" class="footnum" href="#fnr.1">1</a></sup> <p class="footpara"> +The most common non-letter, non-math characters in prose are <code>.,":'_#?!;</code>, in the given order as derived from newspapers and other sources (for the ngram assembling scripts, see the <a href="http://bitbucket.org/ArneBab/evolve-keyboard-layout">evolve keyboard layout project</a>). +</p></div> + +<div class="footdef"><sup><a id="fn.2" name="fn.2" class="footnum" href="#fnr.2">2</a></sup> <p class="footpara"> +Typed Racket uses calls of the form <code>(: x Number)</code> to declare types. These forms can still be used directly in parenthesized form, but in wisp-form the colon has to be replaced with <code>\:</code>. +</p></div> + +<div class="footdef"><sup><a id="fn.3" name="fn.3" class="footnum" href="#fnr.3">3</a></sup> <p class="footpara"> +In most cases type-declarations are not needed in typed racket, since the type can be inferred. See <a href="http://docs.racket-lang.org/ts-guide/more.html?q=typed#(part._when-annotations~3f)">When do you need type annotations?</a> +</p></div> + +<div class="footdef"><sup><a id="fn.4" name="fn.4" class="footnum" href="#fnr.4">4</a></sup> <p class="footpara"> +Conceptually, continuing the argument list with a period uses syntax to mark the rare case of not calling a function as opposed to marking the common case of calling a function. To back the claim, that calling a function is actually the common case in scheme-code, grepping the the modules in the Guile source code shows over 27000 code-lines which start with a paren and only slightly above 10000 code-lines which start with a non-paren, non-comment character. Since wisp-syntax mostly follows the regular scheme indentation guidelines (as realized for example by emacs), the whitespace in front of lines does not need to change. +</p></div> + +<div class="footdef"><sup><a id="fn.5" name="fn.5" class="footnum" href="#fnr.5">5</a></sup> <p class="footpara"> +This special syntax for double parens cannot be replaced by clever whitespace parsing, because it is required for representing two consecutive forms which start with double parentheses. The only pure-whitespace alternative would be fixed-width indentation levels. +</p></div> + +<div class="footdef"><sup><a id="fn.6" name="fn.6" class="footnum" href="#fnr.6">6</a></sup> <p class="footpara"> +The example uses a double let without action as example for the colon-syntax, even though that does nothing, because that makes it impossible to use later indentation to mark an intermediate indentation-level. Another reason why I would not use later indentation to define whether something earlier is a single or double indent is that this would call for subtle and really hard to find errors. +</p></div> + +<div class="footdef"><sup><a id="fn.7" name="fn.7" class="footnum" href="#fnr.7">7</a></sup> <p class="footpara"> +To run the tests in the wisp testsuite with a separately built GNU Guile, you can use any given guile interpreter by adjusting the following command: <code>PATH=~/guile-2.0.11/meta:${PATH} ./runtests.sh</code> +</p></div> + + +</div> +</div></div> +<div id="postamble" class="status"> +<p class="author">Author: Arne Babenhauserheide</p> +<p class="date">Created: 2014-12-23 Di 17:17</p> +<p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.4.1 (<a href="http://orgmode.org">Org</a> mode 8.2.6)</p> +<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p> +</div> +</body> +</html> diff --git a/docs/srfi.org b/docs/srfi.org --- a/docs/srfi.org +++ b/docs/srfi.org @@ -17,12 +17,14 @@ Wisp expressions can include any s-expre define : hello who format #t "~A ~A!\n" . "Hello" who + hello "Wisp" #+END_SRC #+html: </td><td> #+BEGIN_SRC scheme (define (hello who) (format #t "~A ~A!\n" "Hello" who)) + (hello "S-exp") #+END_SRC #+html: </td></tr></table> @@ -91,7 +93,7 @@ Remember, even if a proposal becomes an - SRFI-49 (Indentation-sensitive syntax): superceded by this SRFI, - SRFI-110 (Sweet-expressions (t-expressions)): alternative to this SRFI, -- SRFI-105 (neoteric expressions and curly infix): supported in this SRFI by treating curly braces like brackets and parentheses. Curly infix is required. +- SRFI-105 (neoteric expressions and curly infix): supported in this SRFI by treating curly braces like brackets and parentheses. Curly infix is required by the implementation and the testsuite. - SRFI-30 (Nested Multi-line comments): complex interaction. Should be avoided at the beginning of lines, because it can make the indentation hard to distinguish for humans. SRFI-110 includes them, so there might be value in adding them. The wisp reference implementation does not treat them specially, though, which might create arbitrary complications. * Rationale @@ -102,14 +104,22 @@ But as SRFI-110 explains very thoroughly As a solution to this, SRFI-49 and SRFI-110 provide a way to write whitespace sensitive scheme, but both have their share of issues. -As noted in SRFI-110, there are a number of implementation-problems in SRFI-49, as well as specification shortcomings like choosing the name “group” for the construct which is necessary to represent double parentheses. In addition to the problems named in SRFI-110, SRFI-49 is not able to continue the arguments to a function on one line, if a prior argument was a function call. The example code in the abstract would have to be written in SRFI-49 as follows: +As noted in SRFI-110, there are a number of implementation-problems in SRFI-49, as well as specification shortcomings like choosing the name “group” for the construct which is necessary to represent double parentheses. In addition to the problems named in SRFI-110, SRFI-49 is not able to continue the arguments to a function on one line, if a prior argument was a function call. The following example shows the difference between wisp and SRFI-49 for a very simple code snippet: -#+BEGIN_SRC scheme +#+html: <table><tr><th>wisp</th><th>SRFI-49</th></tr><tr><td> +#+BEGIN_SRC wisp + ,* 5 + + 4 3 + . 2 1 +#+END_SRC +#+html: </td><td> +#+BEGIN_SRC wisp ,* 5 + 4 3 2 1 #+END_SRC +#+html: </td></tr></table> SRFI-110 improves a lot over the implementation of SRFI-49. It resolves the group-naming and reduces the need to continue the argument-list by introducing 3 different grouping syntaxes (=$=, =\\= and =<* *>=). These additional syntax-elements however hurt readability for newcomers (obviously the authors of SRFI-110 disagree with this assertion. Their view is discussed in SRFI-110 in the section about wisp). The additional syntax elements lead to structures like the following (taken from examples from the readable project): #+BEGIN_SRC scheme @@ -131,6 +141,20 @@ This is not only hard to read, but also Like SRFI-49 SRFI-110 also cannot continue the argument-list without resorting to single-element lines, though it reduces this problem by the above grouping syntaxes and advertising the use of neoteric expressions from SRFI-105. +** Wisp example + +Since an example speaks more than a hundred explanations, the following shows wisp exploiting all its features - including curly-infix from SRFI-105: + +#+BEGIN_SRC wisp +define : factorial n +__ if : zero? n +____ . 1 +____ * n : factorial {n - 1} + +display : factorial 5 +newline +#+END_SRC + ** Advantages of Wisp Wisp draws on the strength of SRFI-110 but avoids its complexities. It was conceived and improved in the discussions within the readable-project which preceded SRFI-110 and there is a comparison between readable in wisp in SRFI-110. @@ -139,6 +163,8 @@ Like SRFI-110, wisp is general and homoi But unlike SRFI-110, wisp only uses the minimum of additional syntax-elements which are necessary to support arbitrary code-structures with indentation-sensitive code which is intended to be shared over the internet. To realize these syntax-elements, it generalizes existing syntax and draws on the most common non-letter non-math characters in prose. This allows keeping the actual representation of the code elegant and inviting to newcomers. +Wisp expressions are not as sweet as [[http://readable.sf.net][readable]], but they KISS. + ** Disadvantages of Wisp Using the colon as syntax element keeps the code very close to written prose, but it can interfere with type definitions as for example used in Typed Racket[fn:6]. This can be mitigated in let- and lambda-forms by using the parenthesized form. When doing so, wisp avoids the double-paren for type-declarations and as such makes them easier to catch by eye. For function definitions (the only =define= call where type declarations are needed in typed-racket[fn:7]), a =declare= macro directly before the =define= should work well. @@ -298,7 +324,7 @@ The syntax shown here is the minimal syn *** Empty indentation level -*A line which contains only whitespace and a colon (":") defines an indentation level at the indentation of the colon*. It opens a parenthesis which gets closed by the next less-indented line. If you need to use a colon by itself. you can escape it as "\:". +*A line which contains only whitespace and a colon (":") defines an indentation level at the indentation of the colon*. It opens a parenthesis which gets closed by the next line which has less or equal indentation. If you need to use a colon by itself. you can escape it as "\:". #+BEGIN_SRC wisp let ; (let @@ -317,7 +343,14 @@ The syntax shown here is the minimal syn string-append "Hello " who "!" ; (string-append "Hello " who "!"))) #+END_SRC -If the colon starts a line, it starts a parenthesis which gets closed at the end of the line *and* defines an indentation level at the position of the colon. +If the colon starts a line which also contains other non-whitespace characters, it starts a parenthesis which gets closed at the end of the line *and* defines an indentation level at the position of the colon. + +If the colon is the last non-whitespace character on a line, it represents an empty pair of parentheses: + +#+BEGIN_SRC wisp + let : ; (let () + display "Hello" ; (display "Hello")) +#+END_SRC *** Initial Underscores *You can replace any number of consecutive initial spaces by underscores*, as long as at least one whitespace is left between the underscores and any following character. You can escape initial underscores by prefixing the first one with \ ("\___ a" → "(___ a)"), if you have to use them as function names. @@ -333,15 +366,17 @@ If the colon starts a line, it starts a #+BEGIN_SRC wisp define : stringy s - string-append s "can be varied as follows: - " - string-capitalize s - string-reverse s - . (string-capitalize + string-append s " reversed and capitalized: + " ; linebreaks in strings do not affect wisp parsing + . (string-capitalize ; same for linebreaks in parentheses (string-reverse s)) - . " -" +#+END_SRC +Effectively code in parentheses and strings is interpreted directly as Scheme. This way you can simply copy a thunk of scheme into wisp. The following is valid wisp: + +#+BEGIN_SRC wisp +define foo (+ 1 + (* 2 3)) ; defines foo as 7 #+END_SRC ** Clarifications @@ -358,6 +393,12 @@ define : stringy s - using a quote to escape a symbol separated from it by whitespace is forbidden. This would make the meaning of quoted lines ambigous. +- Curly braces should be treated as curly-infix following SRFI-105. This makes most math look natural to newcomers. + +- Neoteric expressions from SRFI-105 are not required because they create multiple ways to represent the same code. In wisp they add much less advantages than in sweet expressions from SRFI-110, because wisp can continue the arguments to a function after a function call (with the leading period) and the inline colon provides most of the benefits neoteric expressions give to sweet. However implementations providing wisp should give users the option to activate neoteric expressions as by SRFI-105 to allow experimentation and evolution ([[http://sourceforge.net/p/readable/mailman/message/33068104/][discussion]]). + +- It is possible to write code which is at the same time valid wisp and sweet. The readable mailinglist [[http://sourceforge.net/p/readable/mailman/message/33058992/][contains details]]. + * Syntax justification /I do not like adding any unnecessary syntax element to lisp. So I want to show explicitely why the syntax elements are required./ @@ -557,7 +598,7 @@ bar] barz {1 + [* 2 2]} mara { li + -lo (mabba) +lo - (mabba) } #+end_src *** tests/syntax-strings-parens.scm @@ -583,7 +624,7 @@ bar] barz {1 + [* 2 2]}) (mara { li + -lo (mabba) +lo - (mabba) }) #+end_src *** tests/syntax-indent.w @@ -741,7 +782,7 @@ define : \: *** tests/sublist.w #+begin_src wisp ; sublists allow to start single line function calls with a colon ( : ). -; + define : a b c let : : e . f . g @@ -756,15 +797,15 @@ define : a b c #+end_src -*** tests/shebang.w +*** tests/hashbang.w #+begin_src wisp #!/usr/bin/wisp.py # !# -; This tests shebang lines +; This tests hashbang lines #+end_src -*** tests/shebang.scm +*** tests/hashbang.scm #+begin_src scheme #!/usr/bin/wisp.py # !# -; This tests shebang lines +; This tests hashbang lines #+end_src @@ -851,61 +892,6 @@ define : add-if-all-numbers lst (loop (cdr lst))))))))) #+end_src -*** tests/range.w -#+begin_src wisp -import : rnrs - -define range - case-lambda - : n ; one-argument syntax - range 0 n 1 - : n0 n ; two-argument syntax - range n0 n 1 - : n0 n s ; three-argument syntax - assert - and - for-all number? : list n0 n s - not : zero? s - let : : cmp : if (positive? s) >= <= - let loop - : i n0 - acc '() - if - cmp i n - reverse acc - loop (+ i s) (cons i acc) - -display : apply string-append "" : map number->string : range 5 -newline -#+end_src -*** tests/range.scm -#+begin_src scheme -(import (rnrs)) - -(define range - (case-lambda - ((n ); one-argument syntax - (range 0 n 1)) - ((n0 n ); two-argument syntax - (range n0 n 1)) - ((n0 n s ); three-argument syntax - (assert - (and - (for-all number? (list n0 n s)) - (not (zero? s)))) - (let ((cmp (if (positive? s) >= <= ))) - (let loop - ((i n0 ) - (acc '())) - (if - (cmp i n ) - (reverse acc) - (loop (+ i s) (cons i acc)))))))) - -(display (apply string-append "" (map number->string (range 5)))) -(newline) - -#+end_src *** tests/quotecolon.w #+begin_src wisp #!/home/arne/wisp/wisp-multiline.sh @@ -962,20 +948,6 @@ let hello #+end_src -*** tests/mtest.w -#+begin_src wisp -#!/home/arne/wisp/wisp-multiline.sh !# - -display 1 -#+end_src -*** tests/mtest.scm -#+begin_src scheme -#!/home/arne/wisp/wisp-multiline.sh !# - -(display 1) - - -#+end_src *** tests/flexible-parameter-list.w #+begin_src wisp ; Test using a . as first parameter on a line by prefixing it with a second . @@ -1210,17 +1182,6 @@ concat "I want " #+end_src -*** tests/btest.w -#+begin_src wisp -display "b" -newline -#+end_src -*** tests/btest.scm -#+begin_src scheme -(display "b") -(newline) -#+end_src - * Copyright Copyright (C) Arne Babenhauserheide (2013--2014). All Rights Reserved. @@ -1239,7 +1200,7 @@ newline [fn:3] This special syntax for double parens cannot be replaced by clever whitespace parsing, because it is required for representing two consecutive forms which start with double parentheses. The only pure-whitespace alternative would be fixed-width indentation levels. -[fn:4] I used a double let without action as example for the colon-syntax, even though that does nothing, because that makes it impossible to use later indentation to mark an intermediate indentation-level. Another reason why I would not use later indentation to define whether something earlier is a single or double indent is that this would call for subtle and really hard to find errors: +[fn:4] The example uses a double let without action as example for the colon-syntax, even though that does nothing, because that makes it impossible to use later indentation to mark an intermediate indentation-level. Another reason why I would not use later indentation to define whether something earlier is a single or double indent is that this would call for subtle and really hard to find errors. [fn:5] To run the tests in the wisp testsuite with a separately built GNU Guile, you can use any given guile interpreter by adjusting the following command: =PATH=~/guile-2.0.11/meta:${PATH} ./runtests.sh= diff --git a/examples/ensemble-estimation.w b/examples/ensemble-estimation.w new file mode 100755 --- /dev/null +++ b/examples/ensemble-estimation.w @@ -0,0 +1,237 @@ +#!/usr/bin/env sh +exec guile -L $(dirname $(dirname $(realpath "$0"))) --language=wisp -e '(@@ (examples ensemble-estimation) main)' -s "$0" "$@" +; !# + +;; Simple Ensemble Square Root Filter to estimate function parameters +;; based on measurements. + +;; Provide first guess parameters x^b and measurements y⁰ to get +;; optimized parameters x^a. + +;; Method +;; x^b = '(…) ; first guess of the parameters +;; P = '((…) (…) …) ; parameter covariance +;; y⁰ = '(…) ; observations +;; R = '((…) (…) …) ; observation covariance +;; H: H(x) → y ; provide modelled observations for the given parameters. Just run the function. +;; with N ensemble members (i=1, … N) drawn from the state x^b: +;; For each measurement y⁰_j: +;; x'^b: X = 1/√(N-1)(x'b_1, …, x'b_N)^T +;; with P = XX^T ; in the simplest case x'^b are gaussian +;; distributed with standard distribution from +;; square root of the diagonals. +;; x_i = x^b + x'^b_i +;; H(x^b_i) = H(x^b + x'^b_i) +;; H(x^b) = (1/N)·Σ H(x^b + x'^b_i) +;; H(x'^b_i) = H(x^b + x'_i) - H(x^b) +;; HPHt = 1/(N-1)(H(x'_1), …, H(x'_N))(H(x'1), …, H(x'N))T +;; PHt = 1/(N-1)(x'_1, …, x'_N)(H(x'1), …, H(x'N))T +;; K = PHt*(HPHt + R)⁻¹ +;; x^a = x^b + K(y⁰_j - H(x^b)) +;; α = (1 + √(R/(HPHt+R)))⁻¹ +;; x'^a = x'^b - αK·H(x'^b) + +define-module : examples ensemble-estimation +use-modules : srfi srfi-42 ; list-ec +use-modules + : ice-9 popen + . #:select : open-output-pipe close-pipe + +; seed the random number generator +set! *random-state* : random-state-from-platform + +define : make-diagonal-matrix-with-trace trace + let : : dim : length trace + list-ec (: i dim) + list-ec (: j dim) + if : = i j + list-ref trace i + . 0.0 + +define : make-covariance-matrix-from-standard-deviations stds + make-diagonal-matrix-with-trace : map (lambda (x) (expt x 2)) stds + +define : mean l + . "Calculate the average value of l (numbers)." + / : apply + l + length l + + +define : standard-deviation l + . "Calculate the standard deviation of list l (numbers)." + let : : l_mean : mean l + sqrt + / : sum-ec (: i l) : expt {i - l_mean} 2 + . {(length l) - 1} + +define : standard-deviation-from-deviations . l + . "Calculate the standard deviation from a list of deviations (x - x_mean)." + sqrt + / : sum-ec (: i l) : expt i 2 + . {(length l) - 1} + +define* : write-multiple . x + . "Helper to avoid suffering from write-newline-typing." + map : lambda (x) (write x) (newline) + . x + +;; Start with the simple case: One variable and independent observations (R diagonal) +;; First define a truth +define x^seed '(0.5 0.6 7 0.1 0.7 0.9 0.8 0.4) +define x^true : append-ec (: i (length x^seed)) : list-ec (: j x^seed) : * j : list-ref x^seed i +;; And add an initial guess of the parameters +define x^b : append-ec (: i (length x^seed)) '(1 1 1 1 1 1 1 1) ; initial guess +define P : make-covariance-matrix-from-standard-deviations : append-ec (: i (length x^seed)) '(0.5 0.1 0.3 0.1 0.2 0.2 0.2 0.2) + +;; Then generate observations +define y⁰-num 3000 +define y⁰-pos-max 100 +;; At the positions where they are measured. Drawn randomly to avoid +;; giving an undue weight to later values. +define y⁰-pos : list-ec (: i y⁰-num) : * (random:uniform) y⁰-pos-max + +;; We need an observation operator to generate observations from true values +define : H x pos + . "Observation operator. It generates modelled observations from the input. + +x are parameters to be optimized, pos is another input which is not optimized. For plain functions it could be the position of the measurement on the x-axis. We currently assume absolute knowledge about the position. +" + let* + : len : length x + ystretch y⁰-pos-max + x-pos : list-ec (: i len) : * ystretch {{i + 0.5} / {len + 1}} + apply + + list-ec (: i len) + * : list-ref x i + . pos + exp + - + expt + / {pos - (list-ref x-pos i)} {ystretch / 20} + . 2 + + +;; We start with true observations which we will disturb later to get +;; the equivalent of measured observations +define y^true : list-ec (: i y⁰-pos) : H x^true i +;; now we disturb the observations with a fixed standard deviation. This assumes uncorrelated observations. +define y⁰-std 50 +define y⁰ : list-ec (: i y^true) : + i : * y⁰-std : random:normal +;; and define the covariance matrix. This assumes uncorrelated observations. +define R : make-covariance-matrix-from-standard-deviations : list-ec (: i y⁰-num) y⁰-std + +;; Alternative: define observations +;; define y⁰-mean 0.8 +;; The actual observations +;; define y⁰ : list-ec (: i y⁰-num) : + y⁰-mean : * y⁰-std : random:normal + + +define : EnSRT H x P y R y-pos N + . "Observation function H, parameters x, +parameter-covariance P, observations y, observation covariance R +and number of ensemble members N. + +Limitations: y is a single value. R and P are diagonal. +" + let step + : observations-to-process y + observation-variances : list-ec (: i (length y)) : list-ref (list-ref R i) i + observation-positions y-pos + x^b x + x-deviations + list-ec (: i N) + list-ec (: j (length x)) + * : random:normal + sqrt : list-ref (list-ref P j) j ; only for diagonal P! + cond + : null? observations-to-process + list x^b x-deviations + else + ; write : list x^b '± : sqrt : * {1 / {(length x-deviations) - 1}} : sum-ec (: i x-deviations) : expt i 2 + ; newline + let* + : y_cur : car observations-to-process + R_cur : car observation-variances + y-pos_cur : car observation-positions + Hx^b_i + list-ec (: i x-deviations) + H + list-ec (: j (length i)) + + (list-ref x^b j) (list-ref i j) + . y-pos_cur + Hx^b + / : sum-ec (: i Hx^b_i) i + . N + Hx^b-prime + list-ec (: i N) + - : list-ref Hx^b_i i + . Hx^b + HPHt + / : sum-ec (: i Hx^b-prime) {i * i} + . {N - 1} + PHt + list-ec (: j (length x^b)) ; for each x^b_i multiply the state-element and model-deviation for all ensemble members. + * {1 / {N - 1}} + sum-ec (: i N) + * : list-ref (list-ref x-deviations i) j ; FIXME: this currently does not use j because I only do length 1 x + list-ref Hx^b-prime i + K : list-ec (: i PHt) {i / {HPHt + R_cur}} + x^a + list-ec (: j (length x^b)) + + : list-ref x^b j + * : list-ref K j + . {y_cur - Hx^b} + α-weight-sqrt : sqrt {R_cur / {HPHt + R_cur}} + α {1 / {1 + α-weight-sqrt}} + x^a-deviations + list-ec (: i N) ; for each ensemble member + list-ec (: j (length x^b)) ; and each state variable + - : list-ref (list-ref x-deviations i) j + * α + list-ref K j + list-ref Hx^b-prime i + step + cdr observations-to-process + cdr observation-variances + cdr observation-positions + . x^a + . x^a-deviations + + +define : main args + let* + : optimized : EnSRT H x^b P y⁰ R y⁰-pos 30 + x-opt : list-ref optimized 0 + x-deviations : list-ref optimized 1 + ; std : sqrt : * {1 / {(length x-deviations) - 1}} : sum-ec (: i x-deviations) : expt i 2 + format #t "x⁰: ~A ± ~A\nx: ~A ± ~A\nx^t:~A\ny: ~A ± \ny⁰: ~A ± ~A\nnoise: ~A\n" + . x^b + list-ec (: i (length x^b)) : list-ref (list-ref P i) i + . x-opt + list-ec (: i (length x-opt)) + apply standard-deviation-from-deviations : list-ec (: j x-deviations) : list-ref j i + . x^true + * {1 / (length y⁰)} : apply + : map (lambda (x) (H x-opt x)) y⁰-pos + ; apply standard-deviation-from-deviations : map H x-deviations ; FIXME: This only works for trivial H. + mean y⁰ + standard-deviation y⁰ + . y⁰-std + ; now plot the result + let : : port : open-output-pipe "python" + format port "import pylab as pl\n" + format port "y0 = [float(i) for i in '~A'[1:-1].split(' ')]\n" y⁰ + format port "ypos = [float(i) for i in '~A'[1:-1].split(' ')]\n" y⁰-pos + format port "yinit = [float(i) for i in '~A'[1:-1].split(' ')]\n" : list-ec (: i y⁰-pos) : H x^b i + format port "ytrue = [float(i) for i in '~A'[1:-1].split(' ')]\n" : list-ec (: i y⁰-pos) : H x^true i + format port "yopt = [float(i) for i in '~A'[1:-1].split(' ')]\n" : list-ec (: i y⁰-pos) : H x-opt i + format port "pl.plot(*zip(*sorted(zip(ypos, yinit))), label='prior')\n" + format port "pl.plot(*zip(*sorted(zip(ypos, ytrue))), label='true')\n" + format port "pl.plot(*zip(*sorted(zip(ypos, yopt))), label='optimized')\n" + format port "pl.plot(*zip(*sorted(zip(ypos, y0))), marker='+', linewidth=0, label='measurements')\n" + format port "pl.legend()\n" + format port "pl.xlabel('position [arbitrary units]')\n" + format port "pl.ylabel('value [arbitrary units]')\n" + format port "pl.title('ensemble optimization results')\n" + format port "pl.show()\n" + format port "exit()\n" + close-pipe port diff --git a/examples/factorial.w b/examples/factorial.w new file mode 100755 --- /dev/null +++ b/examples/factorial.w @@ -0,0 +1,16 @@ +#!/usr/bin/env sh +exec guile -L $(dirname $(dirname $(realpath "$0"))) --language=wisp -e '(@@ (examples factorial) main)' -s "$0" "$@" +; !# + +define-module : examples factorial + . #:export : factorial + +define : factorial n ; (define (factorial n) + if : zero? n ; (if (zero? n) + . n ; => n + * n : factorial {n - 1} ; (* n (factorial {n - 1})))) + +define : main args + display : factorial 5 + newline + diff --git a/examples/map-product-sums.w b/examples/map-product-sums.w new file mode 100644 --- /dev/null +++ b/examples/map-product-sums.w @@ -0,0 +1,23 @@ +#!/usr/bin/env sh +exec guile -L $(dirname $(dirname $(realpath "$0"))) --language=wisp -e '(@@ (examples map-product-sums) main)' -s "$0" "$@" +; !# + +use-modules : (srfi srfi-42) + +define-module : examples map-product-sums + +define : list-product-sums list-of-numbers + . "return a list with the sum of the products of each number with all other numbers. + + >>> map-product-sums '(2 4 6) + (list (+ (* 2 4) (* 2 6)) (+ (* 4 2) (* 4 6)) (+ (* 6 2) (* 6 4))) + " + map (lambda (x) (apply + x)) + list-ec (: i list-of-numbers) + map (lambda (x) (* i x)) + cons (- i) list-of-numbers + + +define : main . args + write : list-product-sums '(2 4 6) + diff --git a/tests/runtests-scheme-reader.sh b/tests/runtests-scheme-reader.sh --- a/tests/runtests-scheme-reader.sh +++ b/tests/runtests-scheme-reader.sh @@ -17,13 +17,11 @@ fi failed=0 cd ${builddir} for i in ${srcdir}/tests/*.w; do - d=$(guile -L . --language=wisp ${srcdir}/testrunner.w "${i}" "${srcdir}/tests/$(basename "${i}" .w).scm") - if test $? -eq 0; then + if guile -L . --language=wisp ${srcdir}/testrunner.w "${i}" "${srcdir}/tests/$(basename "${i}" .w).scm" | grep -q "have equivalent content"; then continue - else - echo test "$i" failed. Diff: "$d" - failed=$((failed + 1)) fi + echo test "$i" failed. Diff: $(guile -L . --language=wisp ${srcdir}/testrunner.w "${i}" "${srcdir}/tests/$(basename "${i}" .w).scm") + failed=$((failed + 1)) done cd - >/dev/null # undo dir change # if test $failed -eq 0; then echo "Tests succeeded"; diff --git a/tests/self-referencial.scm b/tests/self-referencial.scm new file mode 100644 --- /dev/null +++ b/tests/self-referencial.scm @@ -0,0 +1,21 @@ +; http://stackoverflow.com/questions/23167464/scheme-self-reference-lambda-macro +; because this is as cool as things get +(define-syntax slambda + (lambda (x) + (syntax-case x () + ((slambda formals body0 body1 ...) + (with-syntax + ((self (datum->syntax #'slambda 'self))) + #'(letrec ((self (lambda formals body0 body1 ...))) + self)))))) + + + +( + (slambda (x) (+ x 1)) + 10) + +((slambda () self)) + + + diff --git a/tests/self-referencial.w b/tests/self-referencial.w new file mode 100644 --- /dev/null +++ b/tests/self-referencial.w @@ -0,0 +1,19 @@ +; http://stackoverflow.com/questions/23167464/scheme-self-reference-lambda-macro +; because this is as cool as things get +define-syntax slambda + lambda : x + syntax-case x : + : slambda formals body0 body1 ... + with-syntax + : self : datum->syntax #'slambda 'self + #' letrec : : self : lambda formals body0 body1 ... + . self + + + +: + slambda (x) : + x 1 + . 10 + +: slambda () self + diff --git a/tests/sxml.scm b/tests/sxml.scm new file mode 100644 --- /dev/null +++ b/tests/sxml.scm @@ -0,0 +1,34 @@ +(use-modules (sxml simple)) +(use-modules (ice-9 match)) + +; define a template +(define template + (quote + (html + (head (title "test")) + (body + (h1 "test") + (message "the header") + (p "it " (em "works!") + (br) + (" it actually works!")))))) + +; transform it +(define template2 + (let loop + ((l template)) + (match l + (('message a ...) + `(p (@ (style "margin-left: 2em")) + (strong ,(map loop a)))) + ((a ...) + (map loop a )) + (a + a)))) + +; write xml to the output port +(sxml->xml template2) + +(newline) + + diff --git a/tests/sxml.w b/tests/sxml.w new file mode 100644 --- /dev/null +++ b/tests/sxml.w @@ -0,0 +1,32 @@ +use-modules : sxml simple +use-modules : ice-9 match + +; define a template +define template + quote + html + head : title "test" + body + h1 "test" + message "the header" + p "it " : em "works!" + br + " it actually works!" + +; transform it +define template2 + let loop + : l template + match l + : 'message a ... + ` p : @ : style "margin-left: 2em" + strong ,(map loop a) + : a ... + map loop a + a + . a + +; write xml to the output port +sxml->xml template2 + +newline diff --git a/tests/syntax-strings-parens.scm b/tests/syntax-strings-parens.scm --- a/tests/syntax-strings-parens.scm +++ b/tests/syntax-strings-parens.scm @@ -19,5 +19,5 @@ bar] barz {1 + [* 2 2]}) (mara { li + -lo (mabba) +lo - (mabba) }) diff --git a/tests/syntax-strings-parens.w b/tests/syntax-strings-parens.w --- a/tests/syntax-strings-parens.w +++ b/tests/syntax-strings-parens.w @@ -19,5 +19,5 @@ bar] barz {1 + [* 2 2]} mara { li + -lo (mabba) +lo - (mabba) } diff --git a/tests/websafe-indent.scm b/tests/websafe-indent.scm deleted file mode 100644 --- a/tests/websafe-indent.scm +++ /dev/null @@ -1,7 +0,0 @@ -(defun a (b c) - (d e - (f) - (g h) - i)) - - diff --git a/wisp-reader.w b/wisp-reader.w --- a/wisp-reader.w +++ b/wisp-reader.w @@ -51,22 +51,26 @@ define wisp-pending-port : make-object-p ; try-pending -define wisp-pending-sexps '() +define wisp-pending-sexps : list define : read-one-wisp-sexp port env define : wisp-scheme-read-chunk-env - if : eof-object? : peek-char port + cond + : eof-object? : peek-char port read-char port ; return eof: we’re done - begin - set! wisp-pending-sexps - append wisp-pending-sexps : wisp-scheme-read-chunk port - try-pending + else + set! wisp-pending-sexps + append wisp-pending-sexps : wisp-scheme-read-chunk port + try-pending define : try-pending if : null? wisp-pending-sexps wisp-scheme-read-chunk-env - let : : sexp : car wisp-pending-sexps - set! wisp-pending-sexps : cdr wisp-pending-sexps - . sexp + let + : sexp : car wisp-pending-sexps + pending wisp-pending-sexps + set! wisp-pending-sexps : list ; : cdr wisp-pending-sexps + ; write : cons 'begin pending + cons 'begin pending try-pending define-language wisp @@ -76,7 +80,7 @@ define-language wisp . #:compilers `((scheme . ,compile-scheme)) . #:decompilers `((scheme . ,decompile-scheme)) . #:evaluator : lambda (x module) : primitive-eval x - . #:printer write + . #:printer write ; TODO: backtransform to wisp? Use source-properties? . #:make-default-environment lambda : ;; Ideally we'd duplicate the whole module hierarchy so that `set!', diff --git a/wisp-scheme.w b/wisp-scheme.w --- a/wisp-scheme.w +++ b/wisp-scheme.w @@ -3,7 +3,7 @@ exec guile -L . --language=wisp -s "$0" ; !# ;; Scheme-only implementation of a wisp-preprocessor which output a -;; scheme Tree IL to feed to a scheme interpreter instead of a +;; scheme code tree to feed to a scheme interpreter instead of a ;; preprocessed file. ;; Plan: