λ-2D: An exploration of drawing as programming language

λ-2D: An exploration of drawing as programming language

How will we code through drawing?

The self-discipline of non-verbal programming languages has no longer been unexplored. There are ASCII-basically basically based languages similar to Befunge and asciidots, besides image-basically basically based ones similar to Piet, true to title just a few. Every inspired and challenged by these work, I self-discipline the next goals for my new language:

  • To catch advantage of the reality that this technique is drawn, to embody system that is in any other case unfeasible with textual train-basically basically based programming languages.
  • To enjoy neither too few instructions, nor too many: For the passe it becomes laborious to assign even the ideal programs, and for the latter it becomes non-minimalistic and no longer easy to total computer vision on.
  • To enjoy the flexibility to procedure programs that witness visually provocative themselves, such that somebody would are seeking to position a frame round them and hold them on the wall.

Though I’m in overall an crucial and low-stage particular person, I became compelled to make exercise of lambda calculus, or functional programming in its most outdated make, as the premise for the language, for it regarded as if it may well possibly well perchance possibly me that the tips accept as true with a fashion of resemblance to a standard drawing. It has no idea of “execution” however simplest that of “evaluate”, powerful love how the viewers’ eyes can linger on any section of a drawing in no particular utter, and by following many dots they witness the road, and contours the make, and forms the composition.

Conceptual blabber aside, I began with a grid-basically basically based system. Whereas the particular person can procedure actual lines across many grids, every grid discontinuance up as one of a finite self-discipline of symbols. It seems love a merely compromise between the ease of drawing for the human and that of parsing for the computer.

Lambda calculus is this form of concise language that it simplest has two instructions: that of feature application and that of feature definition. I fleet came up with working symbols for every: a “cup” form for the passe (for the silly intuition that making exercise of the feature is love placing the argument into the “cup”), and the eponymous greek letter for the latter (which is a puny expressionless and arguably overused, however at the least it is obvious). Honest appropriate love vanilla lambda calculus, capabilities continually catch one argument and kind one output; to win more, you may well perchance possibly possibly also chain multiple capabilities together, is known as “currying”.

Then came the wires to effect the symbols and in which records can waft. Technically the language is Turing total at this level, however will doubtless be excruciatingly laborious to make exercise of, violating my originate rule #2. Therefore, I added loads more more than just a few symbols you may well perchance possibly possibly request from your favourite programming languages, issues love numbers and math operators. Discover into story them mere syntactic sugars: you may well perchance possibly possibly also amassed stick to Church numerals (they’re shiny cool) and assorted “pure” lambda calculus constructs if you need.

I frail to skills how easy it is miles in Scratch, to procedure some sprites in the an identical editor and straight exercise it for this technique. Since my new language is entirely drawn, it will doubtless be even more natural to incorporate such more or much less feature. Furthermore, I wished with the procedure to sketch the form of a mathematical feature and exercise it (e.g. for animating stuff), without the extra step of figuring out the equation (manually or in any other case). So I introduced the premise of “frames”: fence any self-discipline of the canvas with wires, and assign an indicating symbol at better left; anything doodled in the self-discipline will also be frail as records. In an identical spirit, I wished with the procedure to procedure sliders (and maybe more than just a few GUI system in some unspecified time in the future), which will also be dragged at escape-time to parametrically adjust this technique.

At first I sketched my tips on a dotted notebook, seeking to assign some example programs in my (then imaginary) language. (I chanced on this reach helpful in my outdated programming-language-originate experiences). Then I figured it became time to code a parser for it, to perceive if it if truth be told “works”. Since the computer vision section to scan this technique from the paper became no longer titillating but, I made up my mind to first assign a easy editor utility to let the particular person digitally procedure programs.

Every symbol is made to 5×5 pixels, with ease stamp-ready on the gridded canvas, while the particular person can additionally procedure “free hand” with a “pencil”-love tool. What in the foundation began as a brief measure grew to an nearly full-fledged editor with many system. 

One provocative mutter that I did no longer attach up for while imagining the language became that it turned out so purely functional and entirely utter-much less, that it becomes impossible to place into effect a “print” assertion, for to print is to commerce utter, to request some issues to be printed in some particular utter is to know that some expressions will doubtless be evaluated in some utter. The solution became a functional re-thinking of the definition of “printing” as passing a bit of empty canvas to a pair feature and receiving a brand new canvas with altered pixels comparable to textual train (or without reference to scribble desired) on it. (Change “canvas” with “string” and “pixels” with “characters”, if you need, however you doubtless figured having read to this level that right here is an anti-strings and pro-pixels language).

The baseline parser works by transpiling (translating) a total λ-2d program to a javascript equivalence. The consequent javascript one-liner is a single horrendously inscrutable mega-expression that contains adequate parentheses to assign a lisper shudder. However the coolest section about it is miles that it if truth be told works (albeit inefficiently)!

I work to toughen the language by developing more example programs, and as I discontinuance I explore originate flaws to be corrected. It became a fashion of fun, for I am myself unfamiliar with my possess creation: I simplest know the detestable tips, and that in theory it is miles going to work, however as to how to if truth be told program in it I am as clueless as any more than just a few new learner of programming languages. Step by step I start to remove its temperaments, of what it is miles love to program on this very irregular, drawing-basically basically based language. Within the starting I became using the syntax clumsily, seeking to bend issues to my will; later I change into more suave and expressive in it. Coding in λ-2D is a puny love taking half in Minecraft or Factorio, however it absolutely’s even better because I will have the ability to call it evaluate.

Below you may well perchance possibly possibly also the comparison of two fractal tree programs, one in notebook doodles, and the assorted in subtle digital make. (Please forgive the copious bugs and logical inconsistencies in the passe, for I know folk that can program on a bit of paper and win it merely in one shot, sadly I’m no longer one of them and discovered programming the “rogue” manner: by running stuff as soon as more and as soon as more and witness if I will have the ability to win any errors to pop up).

I idea it will doubtless be cool and puzzled what it may well possibly well perchance possibly witness love, to visualize the execution of a program written on this queer language. Essentially the most up-to-date parser spits out javascript and your browser’s immense-optimized javascript engine takes it over from there, so it is miles never any longer easy to visualize the particular execution. Nonetheless I will have the ability to without concerns visualize the parsing, which would possibly enjoy to witness similar to the route taken by a tree-stroll interpreter executing this technique.

And the animation did turn out quite fun to explore. However what if it makes sounds when going over more than just a few symbols? We can then “listen” to a program as it is miles being escape, as if it were a song! I’m no musician myself however theoretically it will doubtless be doubtless to construct something musical with this more or much less system.

It ended up sounding love a whacky computer sport from 8-bit generation. It is doubtless you’ll well perchance attempt it out in the online demo (Menu> Program> Interesting Traipse).

λ-2D began as a section of the next evaluate to originate a system the build the particular person procedure programs with pen and paper, and receive interactive feedback through augmented reality. Nonetheless, it grew an increasing number of provocative that it turned a full project by itself.  Though I’m quite overjoyed with this easy puny language, it is miles but to entirely meet just some of the initial goals. As an illustration, the programs witness too powerful love circuit diagrams and no longer adequate love, smartly, drawings. Also, I’m no longer too optimistic about how easy it is miles for a human (besides myself) to be taught it, and for a computer vision system to scan it without error.

Therefore, after I refine λ-2D, I idea to originate more doable programming languages that can also be integrated into the drawing-as-computation system I am rising, using records and skills I’ve since gained.

It is doubtless you’ll well perchance attempt out a beta model of λ-2D online right here. The availability code for the parser and editor will rapidly be on hand on GitHub.

Read More
Part this on knowasiak.com to talk over with folk on this subjectRegister on Knowasiak.com now if you is doubtless to be no longer registered but.

Related Articles

What’s recent in Emacs 28.1?

By Mickey Petersen It’s that time again: there’s a new major version of Emacs and, with it, a treasure trove of new features and changes.Notable features include the formal inclusion of native compilation, a technique that will greatly speed up your Emacs experience.A critical issue surrounding the use of ligatures also fixed; without it, you…

Vim Galore: the entirety you accept as true with to know about Vim

Intro What is Vim? The Vim Philosophy First steps Minimal vimrc What kind of Vim am I running? Cheatsheets Basics Buffers, windows, tabs Active, loaded, listed, named buffers Argument list Mappings Mapleader Registers Ranges Marks Completion Motions, operators, text objects Autocmds Changelist, jumplist Undo tree Quickfix and location lists Macros Colorschemes Folding Sessions Locality Usage…

Used CSS, Original CSS

I first got into web design/development in the late 90s, and only as I type this sentence do I realize how long ago that was. And boy, it was horrendous. I mean, being able to make stuff and put it online where other people could see it was pretty slick, but we did not have very…

Lambda Calculus in 400 Bytes

February 27th, 2022 @ justine’s web page The Lambda Calculus is a programming language with a single keyword. It’s the Turing tarpit discovered by Turing’s doctoral advisor. This blog post introduces a brand new 400 byte implementation of binary lambda calculus as an x86-64 Linux ELF executable. Friendly portable C code and prebuilt APE binaries…