Mew is a library targetting R5RS/R7RS scheme, which provides some conveniences inspired from Goo, Clojure, T and Arc to allow writing more compact code. == Design goals Mew, in its current iteration, is designed as a Scheme library. Even though a program written in Mew will look quite different to a plain Scheme program, code is compatible, and Scheme code can generally live inside a Mew program, and Mew can load Scheme libraries. Extra care has been taken to not reuse identifiers found in important SRFIs. Mew code is tight code, commonly used Mew identifiers are short. Mew uses a few features provided by R7RS internally, but does not require using R7RS. Mew targets Chicken Scheme currently but should be easy to port to other Scheme implementations. Mew is multi-paradigm: it simplifies both writing imperative and functional code. Mew uses SRFI-158 (Generators and Accumulators) for generic functions on enumerable structures. Mew generally uses {{equal?}} as equality predicate. Mew never mutates lists. Except for few shortcut macros ({{op}} and {{op*}), Mew endorses macro hygiene. == Re-Exports Mew re-exports SRFI-1 (List library), SRFI-13 (String Libraries) (from {{utf8-srfi-13}}), SRFI-69 (Basic hash tables), SRFI-158 (Generators and Accumulators), {{(chicken io)}}, {{(chicken irregex)}}, {{(chicken pretty-print)}}}, {{(chicken sort)}}}, and {{matchable}}. == Definitions, bindings and assignments (def ) (def ( ) ) Alias for {{define}}. (fun ...) Alias for {{lambda}}. (fun* ...) Lambda which pattern matches all its arguments (ala the {{match}} macro). (loc ( ... ) ) Binds local variables in pattern (ala the {{match}} macro) {{pat1}} to the result of evaluating {{val1}}, then {{pat2}} to {{val2}}, etc., then evaluates {{body}}. Assignments can refer to previously assigned values of the {{loc}}. (andloc ( ... ) ) Like {{loc}} (without pattern matching), but return false when one of the {{>}} evaluates to false. If a {{}} is {{_}}, only performs the check without binding a value. (rec ) (rec ( ) ) See Module%20(chicken%20base)#rec or SRFI-31. Often, using {{def}} in an inner scope is preferable to using {{rec}}. (set ) Like {{set!}}, but also return the value of {{}}. == Control flow (esc ) Bind {{}} to the current continuation, then run {{}}. Code should not pass {{}} outside the lexical scope and only call it once---use {{call/cc}} else. (fin . ) Evaluate {{}}, then evaluate {{}}, even if {{}} used a non-local exit (as from {{esc}}). Returns value of {{}}, so can also be used as a replacment for Common Lisp PROG1. (rep ( ... ) ...) Explicit form of named {{let}}, using {{loc}} binding syntax. Assignments cannot refer to previously assigned values of the {{rep}}. (seq . ) Like {{begin}}, but allows {{}} to be empty and returns a value which is {{void?}} then. (unless ...) (when ...) As in R7RS-small. (while ...) (until ...) Evaluate {{}} while {{}} is true/false. (xcond ...) Like {{cond}}, but raise error if no case matched. (fail ? ...) Create and signal a condition of {{}} (default: {{(exn)}}) with a {{'message}} of {{}} passed through {{format}} with {{}}. == Numeric helpers (inc ) (dec ) Increment or decrement the argument by 1. (div ) Alias for {{floor-quotient}}. (mod ) Alias for {{floor-remainder}}. == General helpers (app . ) Alias for {{apply}}. (op
) Returns a procedure that evaluates {{}} with {{_}} bound to its only argument. If {{>} is empty, behaves as {{values}}, i.e. the identity function. {{(op 5)}} is the function that always returns 5. {{(op + 2 _)}} is the function that adds 2 to its argument. (op* ) Returns a procedure that evaluates {{}} with {{...}} expanded to all its arguments. {{...}} must only appear once and must not be nested further. If {{...} does not appear in {{}}, it's added implicitly at the end. {{(op* + 5)}} is the function that adds 5 and then all its arguments. {{(op* - 0 ... 2)}} is the function that subtracts all its arguments from 0 and finally 2. (proj ) Expands to a function that returns its {{}}th argument. (boolean ) Return false if {{}} is {{#f}}, and true else. (negate ) Alias for {{complement}}. (comp ...) Alias for {{compose}}. (per ...) Reverse function composition. (act ...) Reverse function compose all {{}}, then apply to {{}}. (=> ...) Alias for {{act}}. (set=> ...) Shortcut for {{(set (=> ...))}}. (and=> ...) Apply the first function in {{}} to {{}}, then the second to the result, etc. Stop if any value is false. (juxt ...) Returns a function that applies each {{}} to its arguments and returns the results as multiple values. (unlist ) Returns the list {{}} as multiple values. (str . ) Returns a new string composed by concatenating the strings given by applying {{display}} to all {{}}. (one-of ...) Expands to a lambda expression that is true if its argument is {{equal?}} to any of the {{}} passed. (sing? ) Return true iff {{}} is a proper list of length 1. (void ...) Ignores all arguments and returns a value where {{void?}} is true. (void? ) Returns true if {{}} is an unspecified value, else false. == I/O helpers (prn . ) {{write}} all {{args}} separated by spaces and terminated by a newline to the current output stream. Returns the value of the last argument. (puts . ) {{display}} all {{args}} terminated by a newline to the current output stream. (eof) Return an object for which {{eof-object?}} is true. (slurp ) If {{}} is an input-port, read all data into a string. If {{}} is a string, read all data from the file named {{<>}. If {{}} is false, read all data from {{*current-input-port*}}. == Equality (=? ...) Return true if all values are {{equal?}} or hash-tables with same set of keys and {{equal?}} values. (<>? ...) Return true if all values are pairwise different. == Data types (get ) (at ) (set (at ) ) Generalized accessor, supports indexing into lists, vectors, hash-tables, strings. (set-at ...) Mutate the hash-table/vector/string {{}} by setting the key/index {{}} to {{}} etc. Returns {{}}. (del-at ...) Delete {{}} from the hash-table, and return the hash-table. (tbl ... ) Construct a hash-table; using {{equal?}}. (keys ) Alias for {{hash-table-keys}}. (vals ) Alias for {{hash-table-values}}. (empty? ) Test if {{}} is an empty list/string/vector/hash-table. (len ) Return the length of the list/vector/string/hash-table/generator {{}}. (for ( ) ...) (for (( . ) ) ...) If {{}} is a list or a vector, iterate over its elements. If {{}} is a procedure, consider it a SRFI-158 generator and iterate over its values. If {{}} is a hash-table, iterate over its keys and values. (search ?) Returns the offset of the sequence (string/list/vector) {{}} in the sequence {{}}, starting no earlier than {{>}} (default: 0). Returns false if the sequence cannot be found. == Generators and Accumulators (gen ) Generic generator for list/vector/string/hash-table/generator. (cycle ...) Alias for {{circular-generator}}. (range ? ? ?) A variant of {{make-range-generator}} that also allows negative {{}}. {{}} defaults to zero. {{}} defaults to infinity. {{}} defaults to 1. (giterate ) Generator returning {{}}, {{( )}}, {{( ()))}}... (gconcatenate ) Generator yielding all values of the all generators yielded by {{}}. (gpick ) Like {{gmap}}, apply {{}} to all values yielded by the generator {{}}, but skip values when {{}} returns an eof object. (gwindow ) Generator yielding a sliding window of length {{}} (as a list) over the values yielded by the generator {{}}. Yields never if the generator yielded fewer than {{}} elements. (gslice-when ) Partition the elements yielded by the generator {{}} into lists: starts a new list when the predicate {{}} called with the previous and the current element of the generator returns true. (genumerate ) Takes the values yielded by the generator {{}} and yields them as a {{cons}} where the first cell is an index incremented on every yield. (gfix ) Returns a generator that runs the generator {{}} until it yields a value {{equal?}} to the preceding one, then stops. (final ) Run the generator {{}} until it stops and return its final value. (into ...) Feed all elements of the generators {{}} into the accumulator {{}}. Uses {{gen}} to convert {{}} into a generator. If {{}} is a list/vector/hash-table/string, accumulate into a corresponding accumulator initialized to {{}}. (accumulate ( ) body ...) Bind {{}} to the accumulator {{}} and run {{body}}. Finally, return the result of accumulation. If {{}} is a list/vector/hash-table/string, accumulate into a corresponding accumulator initialized to {{}}. (tally-accumulator) Returns an accumulator that counts how often each element was accumulated. The accumulator results in a hash-table of objects to numbers. (group-by-accumulator ) Returns an accumulator that stores all elements in lists in a hash-table, applying {{}} to the element to compute the key. (uniq-accumulator ?) Returns an accumulator that returns a list of unique elements. Two elements are considered equal if their image under {{}} is {{equal?}}. {{}} defaults to the identity function. (inject ?) Returns a procedure that takes an generator (or something convertible by {{gen}}) and folds the function {{}} over its values. If given, folding starts with {{}}, else with the first element yielded by the generator. If the generator is empty, return {{()}}. == Regular expressions (?~ ) Matches the string {{}} against the irregex (string or sexp) {{}} without anchoring. Returns false on no match, else a list of all match data strings. (gmatch ) Returns a generator that for each match of the irregex {{}} in the string {{}} either yields the match, or a list of all match data strings (if there are any). (gsplit ?) Returns a generator that yields the strings between matches of the irregex {{}} in the string {{}}, at most {{>} times (by default, unlimited). When the pattern {{}} uses match data, the result is unspecified. == Special syntax (-> a -> b c -> d e f) (-> a ->> b c ->> d e f) Nesting macros: {{->}} inserts the previous part as the second argument: {{(-> a -> b c -> d e f)}} expands to {{(d (b a c) e f)}}. {{->>}} inserts the previous part as the last argument: {{(-> a ->> b c ->> d e f)}} expands to {{(d e f (b c a))}}. You can mix {{->}} and {{->>}} macros: {{(-> a -> b c ->> d e f)}} expands to {{(d e f (b a c))}}. Nesting macros must start off with a {{->}}. (fun-> b c -> d e f) (fun->> b c ->> d e f) Nesting lambdas: like {{->}} but the nesting starts with the argument of the lambda. {{(fun-> b c -> d e f)}} expands to {{(lambda (x) (-> x -> b c -> d e f))}}. {{(fun->> b c ->> d e f)}} expands to {{(lambda (x) (-> x ->> b c ->> d e f))}}. (set-> loc ...) Mutation with nesting macros: shortcut for {{(set loc (-> loc ...))}}. (-> ... if-> ?) Evaluate {{}}. Then, when {{}} is not false, behaves like {{(-> -> }}, otherwise like {{(-> -> )}} (or just {{}} if no {{}} was passed). (-> ... and-> ...) (-> ... and->> ...) Like {{->}}/{{->>}} but skips nesting the code if the nested expression is false.