The goal of this FAQ is to provide a humorous response to the inevitable question that comes up whenever people discuss a project that is written in Vala. Hopefully, it will save some time in the long run.
That was called Mono, and nobody liked it.
| def gen_primes(): | |
| """Generate an infinite sequence of prime numbers.""" | |
| D = {} | |
| q = 2 | |
| S = 4 | |
| r = 2 | |
| while True: | |
| if q not in D: | |
| if q == S: | |
| S = S + r |
| (defn echo [x] (do (prn x) x)) | |
| (defn readmap [fn fl] | |
| (with-open [r (clojure.java.io/reader fl)] (doall (map fn (line-seq r))))) | |
| (defn zip-county-frac [s] (let [l (clojure.string/split s #",")] (list (second l) (first l) (nth l 4)))) | |
| (defn cbsa-county [s] (list (first (clojure.string/split s #"," 2)) (clojure.string/replace (or (re-find #",\d\d,\d\d\d," s) "") #"," ""))) |
| -- This script attempts to automatically sort the \bibitem{}s in the bibliography of a .tex file according to occurrences of \cite{}. | |
| -- Pretty much everyone wants this, but LaTeX you to use extra files or sort by hand. This is annoying for small projects which only | |
| -- need to use a single .tex file. | |
| -- Assumptions: all \cite{} and \bibitem{} occurrences are in one file; only one \bibitem{} on each line; string.lower() works with | |
| -- your citation handles. | |
| tfile = [==[ PASTE .tex FILE HERE ]==] -- or use file i/o and io:lines() instead of the first call to gmatch() | |
| local orders, count, lines = {}, 1, {} |
| -- A simple array-manipulation library for Lua. | |
| -- The natural question is: why bother writing this? | |
| -- After all, it's very short, and anyone reasonably familiar with | |
| -- normal array-manipulation libraries could replicate it in a few | |
| -- hours. | |
| -- But despite this, such a library does not exist in the wild, and | |
| -- the existing counterparts are bad. For instance, penlight.List | |
| -- lacks foldr(), and includes a bunch of things that it shouldn't, | |
| -- like t:put(x), which is equivalent to t:insert(1, x), but also | |
| -- prevents anyone reading your code from knowing what it does. |
| /* example implementation -- not recommended for actual use, but it would work! | |
| * (SIMD-friendly in principle; not shown) | |
| * (probably not ideal for memory-bound workloads; uses 50% more space) | |
| * based on two insights: | |
| * - complex multiplication (a+bi)(c+di) with i^2 = -1 is equivalent to | |
| * split-complex multiplication (a+bk)(c+dk) - 2*b*d with k^2 = +1 | |
| * - the split-complex numbers are isomorphic to the direct product R*R with the | |
| * basis (1+k)/sqrt(2), (1-k)/sqrt(2), both idempotents, thus split-complex | |
| * multiplication (a+bk)(c+dk) can be done by (a+b)(c+d) and (a-b)(c-d) | |
| */ |
| f = {[0] = 1} | |
| m = {[0] = 0} | |
| len = 100000000 | |
| for i = 1, len do | |
| m[i] = i - f[m[i-1]] | |
| f[i] = i - m[f[i-1]] | |
| end |
| /* STR_VA_ARG(...) -- convert variadic arglist to strings | |
| * Usage: STR_VA_ARG(phnglui, mglwnafh, cthulhu, rlyeh, wgahnagl, fhtagn) | |
| * >> "phnglui", "mglwnafh", "cthulhu", "rlyeh", "wgahnagl", "fhtagn" | |
| */ | |
| #ifndef __VA_STRINGIFY_H | |
| #define __VA_STRINGIFY_H | |
| #define PP_NARG(...) \ | |
| PP_NARG_(__VA_ARGS__,PP_RSEQ_N()) |
| --Rich Hickey's infamous transducers, demonstrating reversed function composition. | |
| --Look closely. | |
| function transduce(tf, rf, init, iter) | |
| for i in iter do | |
| init = tf(rf)(init, i) | |
| end | |
| return init | |
| end |
| re = require "re" | |
| local function condense(keyvals) | |
| local obj = {} | |
| for i = 1, #keyvals do | |
| obj[keyvals[i][1]] = keyvals[i][2] | |
| end | |
| return obj | |
| end |