Tobin Fricke's Lab Notebook (nibot_lab) wrote,
Tobin Fricke's Lab Notebook
nibot_lab

icfp: 2d language

We log into ohmega's account and we find a specification, an interpreter, and a couple of problem statements for a perverse programming language called 2d, in which programs are drawn out as "ASCII art" flowcharts. Hilariously the specification explains, "This language frees the programmer from the shackles of linear programming by allowing programs to occupy two dimensions. However, unlike 3- and 4- dimensional languages like CUBOL and Hypercard, it does not distract the programmer's attention with needless dimensional abandon." The flowchart describes not just the data flow, but also the control flow of a program, because boxes aren't evaluated until all of their inputs have values.

The specification for 2d is available on Wikipedia.

I found it useful to first write my programs in Scheme, and then translate them into 2d. For example, here's a function that concatenates two lists, written first in Scheme and then in 2d:

(define (append listA listB)
  (if (empty? listA)
      listB
      (cons (car listA)
            (append (cdr listA) listB))))

The same program, implemented in 2d:

       ,..........................|........................................,
       :append                    |                                        :
       :                          v                                        :
       :                     *==================*                          :
       :                     !send [(N,S),(N,E)]!-----+                    :
       :                     *==================*     |                    :
       :                          |                   v                    :
       :   *=============*        |            *============*              :
       --->!case W of S,E!--------#----------->!send [(N,E)]!---------------
       :   *=============*        |            *============*              :
       :      |                   |                                        :
       :      v                   v                                        :        
       :   *=======*         *==========*                                  :
       :   !split N!-------->!use append!------------+                     :
       :   *=======*         *==========*            |                     :
       :      |                                      v                     :
       :      |                                *====================*      :
       :      +------------------------------->!send [(Inl (W,N),E)]!-------
       :                                       *====================*      :
       ,...................................................................,  
Tags: icfp
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded 

  • 7 comments