perl live coding

Hello, Everyone!

Since I think that live coding gives more flexibility and visual feedback than conventional REPL, here is approach to simple Perl live coding environment using Emacs, AnyEvent, PadWalker, Package::Stash and eval.

Live coding basically consists in performing evaluation of code when it comes from the text editor to a running script, but I also wanted persistent lexicals between eval's. One of ways is to predefine lexicals (or make simple context hash) and/or use $::somevar / $'somevar syntax to create/modify main package vars and/or define global lexicals with use vars qw($one @two %three). Live environment should have asynchronous capability, and AnyEvent was the first option that came to my mind.

Hence, I created perl script which represents running interpreter with optional (but default) PadWalker/Package::Stash processing in order to move my's declarations to global context. And some elisp stuff to communicate with running interpreter from emacs.

That's it - load perl-live.el in emacs, create scratch cperl-mode buffer, start interpreter (C-c C-l), open "*perl live*" buffer in other window to check output and have fun - evaluate line/region (C-c C-c) or something between braces (C-M-x). + *perl live* buffer behaves like REPL (in comint-mode)

Here is short screencast (frame dropped) of a live session with random stuff featuring PDL::Graphics::Simple, OpenGL w/ shaders, sub-processes, live http server modification (AnyEvent::HTTPD, Twiggy), interconnection with SuperCollider via OSC protocol using Net::LibLO and running Gtk2 / Prima / Tk / Wx / SDL - all at the same time, just to test whether it was possible )


p.s. i hope someone will implement similar front-end in other perl-friendly text editors in order to spread perl live coding




A bit of voiceover might have helped as I was squinting to keep up, but that was inspirational.

Is the video running at real time speed? You sure are fast!

This is so cool!

Leave a comment

About vividsnow

user-pic perl blog