This Emacs module enables support for the Racket programming language in Emacs’ Org-mode Babel. This allows executing Racket code blocks directly from Org mode, embedding the results of those code blocks in your Org files, and even chaining the result from one code block into another code block. See the Babel intro for more details on what’s possible.
This example shows how to add a code block implementing the classic recursive
factorial. With point inside the code block, press C-c C-c
to execute the
block. The result will be inserted immediately beneath it.
#+BEGIN_SRC racket :var input=10
(define (factorial n)
(if (= n 1)
1
(* n (factorial (sub1 n)))))
(factorial input)
#+END_SRC
#+RESULTS:
: 3628800
- :results
- Can be set to either
value
oroutput
. If set tovalue
, the code block will be wrapped in a (let …) form, and only the result of the form will recorded. If set tooutput
, the code block will be run as a script, and all standard output will be recorded. Defaults tovalue
. - :lang
- Specifies the language used in the
#lang
directive at the beginning of the script. Defaults to “racket”. - :var
- Allows defining a variable for use in the block. If using the
value
output type, the variable will be passed to the wrapping function as an argument. Otherwise, it will be defined at the top level of the script using a(define ...)
form.
- Install
ob-racket.el
in your Emacs load path - Add the following to your
.emacs.d
file:
;; Enable Racket in Org-mode Babel
(org-babel-do-load-languages
'org-babel-load-languages
'((racket . t)))
- If your Racket interpreter is installed in a non-standard location (anywhere
other than
/usr/bin/racket
), also add the following to your.emacs.d
file:
;; Set path to racket interpreter
(setq org-babel-command:racket "/path/goes/here")
Chris Vig (chris@invictus.so)