© 2018 Strange Loop
How do you control communicating actors? How do you implement an SSH server in a truly functional style? How do you teach middle school students event-driven programming? How are these questions related?
This talk will present a tour through Racket's world of thinking in a purely functional manner. It will start with the Universe library, which we use for reaching middle school students, and it will end with a sketch of the Network Calculus dialect, a natural research outgrowth of the Universe.
Racket's Universe library is the foundation of the long-running Bootstrap and ProgramByDesign K-12 outreach projects. The library's exports make algebra come alive. With big-bang, a middle-school student's "hello world" program simulates a rocket lift-off:
(define (lift-off t) (place-image rocket middle (- height t) background)) (define rocket .. some image ..) (define background .. some image ..) (define height (image-height background)) (define middle (/ (image-width background) 2)) ;; run program run (animate lift-off)
More generally, middle school students can formulate interactive, graphical programs---animations, video games, or simple editors---with algebra. Even evaluating these programs uses nothing but algebraic calculations.
The key to this approach is big-bang, which turns algebraic functions on numbers, booleans, images, and strings into event handlers and rendering functions:
(big-bang height [to-draw lift-off] [on-tick sub1] [stop-when zero?])
A big-bang expression describes a world with functions. Precisely put, it associates functions with certain events. Each function consumes the state of the world and possibly some additional information; it returns the next state of the world or computes a property of the world.
Naturally a world is not enough. Therefore Universe also exports a universe form, with which students can create a network of worlds. For example, they can turn the above animation into a remote-controlled one with just three lines of code added to the above:
[register LOCALHOST] [on-key (lambda (w key) (make-package w 'reset))] [on-receive (lambda (s m) height)]
A beginning student formulates the "universe" server as a top-level function instead of a lambda, but it still doesn't take more than 10 lines.
Even though worlds connected in a universe still consist of algebraic descriptions of state, state transformation, and communication, network connectivity turns the resulting systems into a non-deterministic one. Our college freshmen routinely study and use this material to construct distributed programs at the end of their first semester.
Finally, over the past couple of years, Universe programming has given rise to the idea of folding the network into the programming language. Here a network consists of communicating actors---each of which may be a network itself---and a coordinating messaging board on which actors publish messages and subscribe to them.
The Network Calculus language (NC) is a dialect of Racket that supports programming with these trees of actors. As such, programming in NC resembles programming with actors in Akka or Erlang/OMP, but it also integrates well-known patterns as a language construct.
[[ Attendees are encouraged to install Racket before the presentation and to participate in a small interactive demo midway through the presentation (via pre-packaged code). ]]
I launched the PLT research group at Rice University that created Racket and has maintained it for the past 20 years.