(Arne Babenhauserheide)
2014-04-24: merge wisp merge wisp
diff --git a/.bugs/bugs b/.bugs/bugs --- a/.bugs/bugs +++ b/.bugs/bugs @@ -1,4 +1,5 @@ fails when I add stuff at the end of end of example.w | owner:, open:False, id:08c68e1ce0c9798184c01806d2661a3220bff3cd, time:1363789693.79 +wisp-mode in quoted lists only the first item is colorized as data, but all words up to the last paren should be colorized. | owner:, open:True, id:1675ca3f894ed8470fa292149a476a2fa0d17140, time:1397196957.45 add a testsuite for wisp parsers. | owner:, open:False, id:1c05d27ac916e1a823b8985a094947907c3c19af, time:1379064922.74 wisp-mode: export wisp to html fails in org-mode: font-lock-fontify-keywords-region: Invalid regexp | owner:, open:False, id:1e46d8c05580c961c37a32d36c987a5dd1d34943, time:1389371020.39 an empty line with : should start with double parens | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:2e188ddf44d36e4605030d3c58607ebfa97d189e, time:1390328674.43 diff --git a/docs/srfi.org b/docs/srfi.org --- a/docs/srfi.org +++ b/docs/srfi.org @@ -1,13 +1,34 @@ #+title: SRFI: wisp: whitespace-to-lisp preprocessing +#+options: toc:nil #+BEGIN_ABSTRACT -This SRFI describes a simple syntax which allows making scheme easier to read for newcomers while keeping the simplicity and elegance of s-expressions. Similar to SRFI-110, SRFI-49 and Python it uses indentation to group expressions. As SRFI-110 wisp is general and homoiconic. Different from its precedessors, wisp only uses the absolute minimum of additional syntax-elements which are required for writing and exchanging arbitrary code-structures. +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. -The expressiveness of +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 as first code-character on the line and underscores at the beginning of the line. -Wisp expressions can include any s-expressions +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. + +Wisp expressions can include any s-expressions and as such provide backwards compatibility. + +#+html: <table><tr><th>wisp</th><th>s-exp</th></tr><tr><td> +#+BEGIN_SRC wisp + + 5 + ,* 4 3 + . 2 1 +#+END_SRC +#+html: </td><td> +#+BEGIN_SRC scheme + (+ 5 + (* 4 3) + 2 1) + +#+END_SRC +#+html: </td></tr></table> + #+END_ABSTRACT +#+toc: headlines 2 + * SRFI process :noexport: 1. Authors submit a proposal by using the http://srfi.schemers.org/ web page, or sending email to srfi minus editors at srfi dot schemers dot org. @@ -60,5 +81,69 @@ Remember, even if a proposal becomes an * Related SRFIs -SRFI-49 (Indentation-sensitive syntax) (superceded by this SRFI), SRFI-110 (Sweet-expressions (t-expressions)) (superceded by this SRFI), … (neoteric expressions) (compatible), … (curly infix) (supported) and SRFI-30 (Nested Multi-line comments) (interacts with this SRFI). +- SRFI-49 (Indentation-sensitive syntax): superceded by this SRFI, +- SRFI-110 (Sweet-expressions (t-expressions)): superceded by this SRFI, +- SRFI-105 (neoteric expressions and curly infix): supported, and +- 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 + +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 and the parens for the syntax, they are very close to natural language. Along with the minimal list-structure of the code, this gives these languages a timeless elegance. + +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. + +Using indentation to mark the structure of the code follows the natural way how programmers understand code and avoids errors due to mismatches between indentation and actual structure. + +SRFI-49 and SRFI-110 provide a structure to write whitespace sensitive scheme, but both have their share of problems. + +As noted in SRFI-110, there are a number of implementation-problems in SRFI-49 as well as choosing the name “group” for the construct which is necessary to represent double parentheses. Additionally to the problems named in SRFI-110, it 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: + +#+BEGIN_SRC scheme + ,* 5 + + 4 3 + 2 + 1 +#+END_SRC + +SRFI-110 improves a lot over the implementation of SRFI-49 and resolves the group-naming by introducing 3 different grouping-syntaxes (=$=, =\\= and =<* *>=). These additional syntax-elements however hurt readability by newcomers a lot. They make some code written in SRFI-110 look quite similar as perl-code: +#+BEGIN_SRC scheme +myfunction + x: \\ original-x + y: \\ calculate-y original-y +#+END_SRC + +#+BEGIN_SRC scheme + a b $ c d e $ f g +#+END_SRC + +#+BEGIN_SRC scheme + let <* x getx() \\ y gety() *> + ! {{x * x} + {y * y}} +#+END_SRC + +This is not only hard to read, but also makes it harder to work with the code, because the programmer needs to take these additional syntax elements into account before being able to understand the code. + +SRFI-110 also keeps the limitation from SRFI-49 and is not able to continue the argument-list. + +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. + +But unlike SRFI-110, wisp only uses the minimum of additional syntax-elements which are necessary to support arbitrary code-structures in indentation-sensitive code which is intended to be shared over the internet. + +* Specification + +** Clarifications + +- 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. + +* Test Suite + + +* Copyright + + Copyright (C) Arne Babenhauserheide (2014). All Rights Reserved. + + 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: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + 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. diff --git a/docs/why-wisp.org b/docs/why-wisp.org --- a/docs/why-wisp.org +++ b/docs/why-wisp.org @@ -26,7 +26,6 @@ /The most common paired characters/ (From letter distributions in newspapers) - * On Words #+BEGIN_SRC elisp :exports results :results results raw @@ -70,9 +69,7 @@ - /Do you see how much harder it got?/ - /€ and ¥ escape your existing filters/ - -* Summary: Current Lisp - +* On Lisp 1. Lisp syntax uses the *most common* non-letter, non-math characters. 2. The *first and last characters* are important for text-recognition. @@ -82,6 +79,12 @@ Any fix for elegance 2 should preserve e Elegance 0: generality and homoiconicity: *code is data* +* Summary: Current Lisp Syntax + +- √ *Code is data*. +- √ Uses the *most common* characters. +- *×* The *first and last characters* are always *the same*. + * On Wisp #+html: <br /> #+BEGIN_SRC scheme @@ -218,7 +221,7 @@ becomes ((x 1) (y 2) (z 3)) - body) + (body)) #+END_SRC * Wisp syntax 4/4: Resilient Indentation @@ -240,7 +243,7 @@ becomes ((x 1) (y 2) (z 3)) - body) + (body)) #+END_SRC diff --git a/examples/fizzbuzz.w b/examples/fizzbuzz.w new file mode 100755 --- /dev/null +++ b/examples/fizzbuzz.w @@ -0,0 +1,24 @@ +#!./wisp-multiline.sh +; !# + +;; this example needs foof-loop installed via guildhall! +use-modules : guildhall ext foof-loop +;; Pseudocode adapted from +;; http://en.wikipedia.org/wiki/Pseudocode#Syntax +define : divisible? number divisor + = 0 : remainder number divisor + +define : fizzbuzz + let : : print_number #f + loop : : for i : up-from 1 : to 100 + set! print_number #t + when : divisible? i 3 + display "Fizz" + set! print_number #f + when : divisible? i 5 + display "Buzz" + set! print_number #f; + when print_number : display i + newline + +fizzbuzz diff --git a/examples/kit-encode.w b/examples/kit-encode.w --- a/examples/kit-encode.w +++ b/examples/kit-encode.w @@ -93,12 +93,11 @@ Karlsruher Institut fuer Technologie " -define : kittify numbers - . "Display a list of numbers as Text in a KIT Logo." +define : kittifytologo numbers logo + . "Display a list of numbers as Text in the given text logo." let* : base60numbers : map base60encode numbers requiredletters : + (length base60numbers) : apply + : map string-length base60numbers - logo kitlogosmall charsinlogo : string-count logo #\. requiredlogos : ceiling-quotient requiredletters charsinlogo text : xsubstring logo 0 : * requiredlogos : string-length logo @@ -146,6 +145,14 @@ define : kittify numbers +define : kittify numbers + . "Display a list of numbers as Text in a KIT Logo." + kittifytologo numbers kitlogosmall + + +define : kittifylarge numbers + . "Display a list of numbers as Text in a KIT Logo." + kittifytologo numbers kitlogo ; unkittify: first take out "Karlsruher Institut fuer Technologie" and all spaces and linebreaks, then split by . and base60decode the result. @@ -224,7 +231,7 @@ If TEXT is #t, transform the numbers to bv : get-bytevector-all file numbers : bytevector->u8-list bv numbers : if text (map shiftbytedownfortext numbers) numbers - kittify numbers + kittifylarge numbers define : kittytextfile filepath . "Kittify the contents of the file at FILEPATH, with a transformation to optimize for text files." @@ -284,5 +291,21 @@ 1o.1 r.1i . 1k.1 g.Y. f.1F Karlsruher Institut fuer Technologie " + +displaywithnewline " + + === KIT, IMK, RemoteC ===" + +displaywithnewline : kittify : map shiftbytedownfortext : bytevector->u8-list : string->utf8 "Karlsruhe Institut für Technologie (KIT), IMK-ASF, RemoteC" + + +displaywithnewline " + + === kittifyscript ===" + +displaywithnewline : kittytextfile "examples/kit-encode.w" + + + ; TODO: Final step: Add commandline handling which allows to write into files and set the text flag and so on. ; ./kit-encode [-e|--encode|-d|--decode] [--text] [--template file] [--killstring "stringtoremove" (mutliple times)] [-o|--output file] [file|-] diff --git a/wisp-mode.el b/wisp-mode.el --- a/wisp-mode.el +++ b/wisp-mode.el @@ -94,6 +94,8 @@ ("\\_<[+-]?[0-9]+\\_>\\|\\_<[+-][0-9]*\\.[0-9]*\\(e[+-]?[0-9]+\\)?\\_>" . font-lock-constant-face) ; numbers ("'()" . font-lock-constant-face) ; empty list ("[ ]'[^ ]+" . font-lock-constant-face) ; 'name + ; FIXME: This is too general (it will capture a . 'b, making it + ; impossible to have 'b highlighted) (" : \\| \\. " . font-lock-keyword-face) ; leading : or . )) "Default highlighting expressions for wisp mode.")