LFE Cowboy Examples

LFE ports of the Cowboy examples.

Example Description
chunked-hello-world demonstrate chunked data transfer with two one-second delays
compress-response send a response body compressed if the client supports it
cookie set cookies from server and client side
echo-get parse and echo a GET query string
echo-post parse and echo a POST parameter
error-hook provide custom error pages
eventsource eventsource emitter and consumer
hello-world simplest example application
markdown-middleware static file handler with markdown preprocessor
rest-hello-world return the data type that matches the request type (html, json or text)
rest-basic-auth basic HTTP authorization with REST
rest-pastebin create text objects and return the data type that matches the request type (html, text)
rest-stream-response stream results from a data store
ssl-hello-world simplest SSL application
static-world static file handler
web-server serve files and list directory entries
websocket websocket example
upload multipart/form-data upload


How to implement a programming language in JavaScript

This is a tutorial on how to implement a programming language. If you ever wrote an interpreter or a compiler, then there is probably nothing new for you here. But, if you’re using regexps to “parse” anything that looks like a programming language, then please read at least the section on parsing. Let’s write less buggy code!

The ToC on the right is in “simple-to-advanced” order. I’d recommend you not to skip forward, unless you know the subject well. You can always refer back if you don’t understand something. Also, questions and feedback are very much appreciated!

The target audience is the average JavaScript / NodeJS programmer.

What are we going to learn

  • What is a parser, and how to write one.
  • How to write an interpreter.
  • Continuations, and why are they important.
  • Writing a compiler.
  • How to transform code to continuation-passing style.
  • A few basic optimization techniques.
  • Examples of what our λanguage brings new over plain JavaScript.

In between, I’m going to argue why Lisp is a great programming language. However, the language we will work on is not a Lisp. It has a richer syntax (classical infix notation that everybody knows) and will be about as powerful as Scheme, except for macros. Sadly or not, macros are the ultimate bastion of Lisp, something that other languages just can’t conquer (unless they are called Lisp dialects). [Yes, I know about SweetJS… close but no cigar.]

But first, let’s dream up a programming language.


“Lispsy” Lisp(ish) to C Converter (designed for CLISP)

LISP/c is a powerful macrolanguage for C. It basically turns this:

(header stdio)
(@printf (str “Hello, world!”))
(return 0))
into (after it being cleaned up (more on this later)) this:


int main(int argc,char **argv)
printf(“Hello, world!”);
return 0;

But why?

First, you might check out this video. Because LISP is expressive and C is fast and I wanted the best of both worlds is the short answer. The longer answer has something to do with macros. But instead of immediately boring you with that, I’ll answer what you really want to know:

Why Should I Care?

First let’s discuss if you can use it. Not to be elitist (I wish everyone would use this tool), but you must know both C and LISP fairly well to be able to use LISP/c.

Suppose, however, that you do already know both LISP and C pretty well. You might want to use LISP/c because it features access to LISP to write C code both implicitly and explicity. You might also want to use it if you like writing CUDA code, because it has built-in support for CUDA as well.

But really, to see why you might like to use LISP/c, check out a few examples, and feel free to skip around a little.


Full Stack Lisp

Lisp aliens have infected the terrestrial memetosphere with the meme complex of Common Lisp. The mindless human hosts find themselves helpless spreaders of the glory and joy of Lisp Development. Join us and become a great Lisp Programmer! Learn how to build and deploy modern Lisp applications in the booming ecosystem of modern software inhabited by lesser technologies!


SICP in Python 3

Welcome to Composing Programs, a free online introduction to programming and computer science.

In the tradition of SICP, this text focuses on methods for abstraction, programming paradigms, and techniques for managing the complexity of large programs. These concepts are illustrated primarily using the Python 3 programming language.

In addition to reading the chapters below, you can apply your knowledge to the programming projectsthat accompany the text and visualize program execution using the Online Python Tutor.

Instructors: If you are interested in adapting any of these materials for your courses, please fill out this short survey so that we can support your efforts.

http://web.archive.org/web/20160402152716/http://www.composingprograms.com/ (mirror)
http://cs61a.org/ (course material)