​

DRAKON-Erlang: Visual Functional Programming

Home|Download

By Stepan Mitkin

Part 10 of 10

Previous|Contents

Appendix: Implementation of DRAKON-Erlang in DRAKON Editor 1.22

Generating Erlang source code

How to create a DRAKON-Erlang file:

  1. Create a new .drn file with DRAKON Editor.
  2. Choose Erlang as the language of the file.

    Main menu / File / File Properties...

    Choosing Erlang

How to generate Erlang source code from the .drn file:

Main menu / DRAKON / Generate code

Or Ctrl+B (Command+B on Mac).

An Erlang source file will be created near the .drn file.

There is also a command line tool for generating code from .drn files (drakon_gen.tcl). Using this tool, you can specify the output directory for the generated files.

drakon_gen.tcl is not available in the Mac version of DRAKON Editor. But you can download the cross-platform package and run the tool.

The module name

DRAKON Editor puts a module statement at the beginning of the source file. The module name is taken from the file name.

Here is the autogenerated module statement for the file called demo.drn:

-module(erldemo).

Function arguments

The function arguments should be placed in the "Formal parameters" icons. It's just an "Action" icon placed to the right from the diagram header.

Each argument occupies one line.

Arguments

Exported functions

In order to make a function exported, put the public keyword on the first line inside the "Formal parameters" icon.

Exported function

DRAKON Editor will add this function to the export statement at the beginning of the file.

-export([exported_function/2]).

Commas, dots and semicolons

The standard Erlang has quite complex punctuation rules. Statements must end with a different symbol depending on the context:

  • comma;
  • dot;
  • semicolon;
  • nothing.

DRAKON-Erlang removes this complexity.

The rule is:

  • Put no punctuation to icons that have only one statement.

    No comma

  • Put a comma at the end of the statement when there are many of those in the icon.

    Use comma

Exceptions

Exceptions introduce hidden paths into the algorithm. DRAKON as a language aims to expose hidden paths. This is why DRAKON does not have a visual construct to support exceptions.

Yet exceptions are implemented very well in Erlang. They are also relatively harmless in this language. At least when the code that throws them does not have any side effects.

In order to catch exceptions in DRAKON-Erlang, put try and catch statements inside "Action" icons.

Arbitrary source code

You can instruct DRAKON Editor to insert some free text into the generated source file. This is done by adding special sections to the file description:

  • header. The text that goes before the functions generated by the editor.
  • footer. The text that follows the functions.

Here is a typical file description (main menu / File / File description...):

The text that goes before the section
is ignored.
It is the DESCRIPTION of the file.

=== header ===
some_hand_made_function() -> true.  

=== footer ===
another_hand_made_function() -> false.

State machines

DRAKON Editor can generate Erlang source code from DRAKON state machine diagrams.

Both OTP-based gen_fsm and standalone state machines are supported.

Previous|Contents


Contact: drakon.editor@gmail.com