# lisp

## Surface Area of regions on an ellipsoid Earth

PDF (to print)

Org (source)

Data (netCDF4)

Calculating the area of arbitrary regions on the Earth approximated as an ellipsoid. I needed this for conversion between the output of different models.

It’s calculated in Emacs Lisp, which showed me that for somewhat complex mathematical tasks Lisp syntax isn’t only unproblematic, but actually helps avoiding mistakes. And full unicode support is great for implementing algorithms with ω, λ and φ.

## wisp: Whitespace to Lisp

» I love the syntax of Python, but crave the simplicity and power of Lisp.«

```display "Hello World!" ↦ (display "Hello World!")
```
```define : factorial n     (define (factorial n)
if : zero? n       ↦     (if (zero? n)
. 1                      1
* n : factorial {n - 1}  (* n (factorial {n - 1}))))
```

## Wisp basics

• Wisp turns indentation into lisp expressions.
• Why Wisp?
• Get it
• from its Mercurial repository:
`hg clone http://bitbucket.org/ArneBab/wisp`
• Or via GNU Guix:
`guix package -i guile guile-wisp`
• Or via the package guile-wisp-hg for Arch Linux.
• Or via `./configure; make install` from the releases:
`bitbucket.org/ArneBab/wisp/downloads/`
• See more examples and tests.
»ArneBab's alternate sexp syntax is best I've seen; pythonesque, hides parens but keeps power« — Christopher Webber in twitter, in identi.ca and in his blog: Wisp: Lisp, minus the parentheses
☺ Yay! ☺
```with (open-file "with.w" "r") as port
format #t "~a\n" : read port```
Familiar with-statement in 25 lines.
Update (2017-11-10): wisp v0.9.8 released with installation fixes (thanks to benq!). To start your own wisp-project, see the tutorial Starting a wisp project. For more info, see the NEWS file. To test wisp v0.9.8, install Guile 2.0.11 or later and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.9.8.tar.gz; tar xf wisp-0.9.8.tar.gz ; cd wisp-0.9.8/; ./configure; make check; examples/newbase60.w 123`
If it prints 23 (123 in NewBase60), your wisp is fully operational.
That’s it - have fun with wisp syntax!
Update (2017-10-17): wisp v0.9.7 released with bugfixes. To start your own wisp-project, see the tutorial Starting a wisp project. For more info, see the NEWS file. To test wisp v0.9.7, install Guile 2.0.11 or later and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.9.7.tar.gz; tar xf wisp-0.9.7.tar.gz ; cd wisp-0.9.7/; ./configure; make check; examples/newbase60.w 123`
If it prints 23 (123 in NewBase60), your wisp is fully operational.
That’s it - have fun with wisp syntax!
Update (2017-10-08): wisp v0.9.6 released with compatibility for tests on OSX and old autotools, installation to `guile/site/(guile version)/language/wisp` for cleaner installation, debugging and warning when using not yet defined lower indentation levels, and with `wisp-scheme.scm` moved to `language/wisp.scm`. This allows creating a wisp project by simply copying `language/`. A short tutorial for creating a wisp project is available at Starting a wisp project as part of With Guise and Guile. For more info, see the NEWS file. To test wisp v0.9.6, install Guile 2.0.11 or later and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.9.6.tar.gz; tar xf wisp-0.9.6.tar.gz ; cd wisp-0.9.6/; ./configure; make check; examples/newbase60.w 123`
If it prints 23 (123 in NewBase60), your wisp is fully operational.
That’s it - have fun with wisp syntax!
Update (2017-08-19): Thanks to tantalum, wisp is now available as package for Arch Linux: from the Arch User Repository (AUR) as guile-wisp-hg! Instructions for installing the package are provided on the AUR page in the Arch Linux wiki. Thank you, tantalum!
Update (2017-08-20): wisp v0.9.2 released with many additional examples including the proof-of-concept for a minimum ceremony dialog-based game duel.w and the datatype benchmarks in benchmark.w. For more info, see the NEWS file. To test it, install Guile 2.0.11 or later and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.9.2.tar.gz; tar xf wisp-0.9.2.tar.gz ; cd wisp-0.9.2/; ./configure; make check; examples/newbase60.w 123`
If it prints 23 (123 in NewBase60), your wisp is fully operational.
That’s it - have fun with wisp syntax!
Update (2017-03-18): I removed the link to Gozala’s wisp, because it was put in maintenance mode. Quite the opposite of Guile which is taking up speed and just released Guile version 2.2.0, fully compatible with wisp (though wisp helped to find and fix one compiler bug, which is something I’m really happy about ☺).
Update (2017-02-05): Allan C. Webber presented my talk Natural script writing with Guile in the Guile devroom at FOSDEM. The talk was awesome — and recorded! Enjoy Natural script writing with Guile by "pretend Arne" ☺

presentation (pdf, 16 slides) and its source (org).
Have fun with wisp syntax!
Update (2016-07-12): wisp v0.9.1 released with a fix for multiline strings and many additional examples. For more info, see the NEWS file. To test it, install Guile 2.0.11 or later and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.9.1.tar.gz; tar xf wisp-0.9.1.tar.gz ; cd wisp-0.9.1/; ./configure; make check; examples/newbase60.w 123`
If it prints 23 (123 in NewBase60), your wisp is fully operational.
That’s it - have fun with wisp syntax!
Update (2016-01-30): I presented Wisp in the Guile devroom at FOSDEM. The reception was unexpectedly positive — given some of the backlash the readable project got I expected an exceptionally sceptical audience, but people rather asked about ways to put Wisp to good use, for example in templates, whether it works in the REPL (yes, it does) and whether it could help people start into Scheme. The atmosphere in the Guile devroom was very constructive and friendly during all talks, and I’m happy I could meet the Hackers there in person. I’m definitely taking good memories with me. Sadly the video did not make it, but the schedule-page includes the presentation (pdf, 10 slides) and its source (org).
Have fun with wisp syntax!
Update (2016-01-04): Wisp is available in GNU Guix! Thanks to the package from Christopher Webber you can try Wisp easily on top of any distribution:
`guix package -i guile guile-wispguile --language=wisp`
This already gives you Wisp at the REPL (take care to follow all instructions for installing Guix on top of another distro, especially the locales).
Have fun with wisp syntax!
Update (2015-10-01): wisp v0.9.0 released which no longer depends on Python for bootstrapping releases (but ./configure still asks for it — a fix for another day). And thanks to Christopher Webber there is now a patch to install wisp within GNU Guix. For more info, see the NEWS file. To test it, install Guile 2.0.11 or later and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.9.0.tar.gz; tar xf wisp-0.9.0.tar.gz ; cd wisp-0.9.0/; ./configure; make check; examples/newbase60.w 123`
If it prints 23 (123 in NewBase60), your wisp is fully operational.
That’s it - have fun with wisp syntax!
Update (2015-09-12): wisp v0.8.6 released with fixed macros in interpreted code, chunking by top-level forms, `: .` parsed as nothing, ending chunks with a trailing period, updated example evolve and added examples newbase60, cli, cholesky decomposition, closure and hoist in loop. For more info, see the NEWS file.To test it, install Guile 2.0.x or 2.2.x and Python 3 and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.8.6.tar.gz; tar xf wisp-0.8.6.tar.gz ; cd wisp-0.8.6/; ./configure; make check; examples/newbase60.w 123`
If it prints 23 (123 in NewBase60), your wisp is fully operational.
That’s it - have fun with wisp syntax! And a happy time together for the ones who merge their paths today ☺
Update (2015-04-10): wisp v0.8.3 released with line information in backtraces. For more info, see the NEWS file.To test it, install Guile 2.0.x or 2.2.x and Python 3 and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.8.3.tar.gz; tar xf wisp-0.8.3.tar.gz ; cd wisp-0.8.3/; ./configure; make check; guile -L . --language=wisp tests/factorial.w; echo`
If it prints 120120 (two times 120, the factorial of 5), your wisp is fully operational.
That’s it - have fun with wisp syntax!
Update (2015-03-18): wisp v0.8.2 released with reader bugfixes, new examples and an updated draft for SRFI 119 (wisp). For more info, see the NEWS file.To test it, install Guile 2.0.x or 2.2.x and Python 3 and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.8.2.tar.gz; tar xf wisp-0.8.2.tar.gz ; cd wisp-0.8.2/; ./configure; make check; guile -L . --language=wisp tests/factorial.w; echo`
If it prints 120120 (two times 120, the factorial of 5), your wisp is fully operational.
That’s it - have fun with wisp syntax!
Update (2015-02-03): The wisp SRFI just got into draft state: SRFI-119 — on its way to an official Scheme Request For Implementation!
Update (2014-11-19): wisp v0.8.1 released with reader bugfixes. To test it, install Guile 2.0.x and Python 3 and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.8.1.tar.gz; tar xf wisp-0.8.1.tar.gz ; cd wisp-0.8.1/; ./configure; make check; guile -L . --language=wisp tests/factorial.w; echo`
If it prints 120120 (two times 120, the factorial of 5), your wisp is fully operational.
That’s it - have fun with wisp syntax!
Update (2014-11-06): wisp v0.8.0 released! The new parser now passes the testsuite and wisp files can be executed directly. For more details, see the NEWS file. To test it, install Guile 2.0.x and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.8.0.tar.gz; tar xf wisp-0.8.0.tar.gz ; cd wisp-0.8.0/; ./configure; make check; guile -L . --language=wisp tests/factorial.w; echo`
If it prints 120120 (two times 120, the factorial of 5), your wisp is fully operational.
That’s it - have fun with wisp syntax!
On a personal note: It’s mindboggling that I could get this far! This is actually a fully bootstrapped indentation sensitive programming language with all the power of Scheme underneath, and it’s a one-person when-my-wife-and-children-sleep sideproject. The extensibility of Guile is awesome!
Update (2014-10-17): wisp v0.6.6 has a new implementation of the parser which now uses the scheme read function. `wisp-scheme.w` parses directly to a scheme syntax-tree instead of a scheme file to be more suitable to an SRFI. For more details, see the NEWS file. To test it, install Guile 2.0.x and bootstrap wisp:
`wget https://bitbucket.org/ArneBab/wisp/downloads/wisp-0.6.6.tar.gz; tar xf wisp-0.6.6.tar.gz; cd wisp-0.6.6; ./configure; make; guile -L . --language=wisp`
That’s it - have fun with wisp syntax at the REPL!
Caveat: It does not support the ' prefix yet (syntax point 4).
Update (2014-01-04): Resolved the name-clash together with Steve Purcell und Kris Jenkins: the javascript wisp-mode was renamed to wispjs-mode and wisp.el is called wisp-mode 0.1.5 again. It provides syntax highlighting for Emacs and minimal indentation support via tab. You can install it with `M-x package-install wisp-mode`
Update (2014-01-03): wisp-mode.el was renamed to wisp 0.1.4 to avoid a name clash with wisp-mode for the javascript-based wisp.
Update (2013-09-13): Wisp now has a REPL! Thanks go to GNU Guile and especially Mark Weaver, who guided me through the process (along with nalaginrut who answered my first clueless questions…).
To test the REPL, get the current code snapshot, unpack it, run `./bootstrap.sh`, start guile with `\$ guile -L .` (requires guile 2.x) and enter `,language wisp`.
Example usage:
`display "Hello World!\n"`
then hit enter thrice.
Voilà, you have wisp at the REPL!
Caveeat: the wisp-parser is still experimental and contains known bugs. Use it for testing, but please do not rely on it for important stuff, yet.
Update (2013-09-10): wisp-guile.w can now parse itself! Bootstrapping: The magical feeling of seeing a language (dialect) grow up to live by itself: `python3 wisp.py wisp-guile.w > 1 && guile 1 wisp-guile.w > 2 && guile 2 wisp-guile.w > 3 && diff 2 3`. Starting today, wisp is implemented in wisp.
Update (2013-08-08): Wisp 0.3.1 released (Changelog).

## Namespaces in Emacs Lisp - ohne den Interpreter zu ändern

» Adding namespace support to emacs lisp in a macro with just 15 lines of code - it’s things like this which make lisp feel like the mother of all languages.«1

```(defmacro namespace (prefix &rest sexps)
(let* ((naive-dfs-map
(lambda (fun tree)
(mapcar (lambda (n) (if (listp n) (funcall naive-dfs-map fun n)
(funcall fun n))) tree)))
(to-rewrite (loop for sexp in sexps
when (member (car sexp)
'(defvar defmacro defun))
(fixed-sexps (funcall naive-dfs-map
(lambda (n) (if (member n to-rewrite)
(intern
(format "%s-%s" prefix n)) n))
sexps)))
`(progn ,@fixed-sexps)))
(provide 'namespace)
```
```(require 'namespace)
(namespace foo
(defun bar ()
"bar")
(defun foo (s)
"foo"))
(foo-foo (foo-bar))
```

Disclaimer: This code is not perfect. It will likely fail in unpredictable ways, and the number of not supported corner-cases is probably huge - and unknown. But (and that’s the relevant result) you can do this right. Rainer Joswig gives pointers for that on Stackoverflow: “What you actually need is a so-called code-walker”. Also he shows examples where the code breaks.

(Der Hauptteil dieses Codes stammt von vpit3833 und konr und ich darf ihn verwenden. Er funktioniert dank einer Korrektur von Stefan. Er ist nicht perfekt, aber da er mir v.a. dazu dienen soll, meine eigenen Codeschnipsel besser zu organisieren, sollte ich das verschmerzen können)

Der Code mag schwer lesbar sein, hat aber riesige Implikationen: Du als einfacher Endnutzer des Lisp-Interpreters kannst Namespace-Support hinzufügen, ohne dass die Hauptentwickler dafür irgendetwas machen müssen.

1. Der Code stammt größtenteils aus einer Diskussion auf Stackoverflow

## Custom link completion for org-mode in 25 lines (emacs)

Update (2013-01-23): The new org-mode removed (org-make-link), so I replaced it with (concat) and uploaded a new example-file: org-custom-link-completion.el.
Happy Hacking!