Switch branches/tags
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


D²NA Language

D²NA is a special language to generate code by genetic algorithm. It is something like a mixture of state engine and DNA.

D²NA code has input and output signals to communicate with other world and states to store data. Input and output signals has name, which must start from upper case letter. State has name and integer value. When value is more than zero, state is active.

There is build-in input signal :Init, which is something like constructor. On first usage it will be send to initialize fisrt states.

D²NA code consists of rules. Each rule contains conditions (input signal and active states) and a set of commands, which will be run on all of this conditions. Command may be up :state, down :state or send :Output_signal to increment/decrement some state or to send some output signal.


You can define rules in Ruby code by D2NA::Code class:

code = D2NA::Code.new do
  on :Input do
    up :memory
    send :Output

code.listen do |code, signal|
  puts "Receive #{signal}. Memory: #{code.states[:memory]}."

code << :Input # Print "Receive Output. Memory 1."

Or you can use d2na-vm script to print signals to standard output and read it from standard input.

To use it by human and print and read signals by console (option -c will be make output more human readable):

d2na-vm -c script.d2na

To use it from another program and write/read to standard input/output:

d2na-vm script.d2na


Comment start by number sign # and end by end of line.

State and signals names must start from : symbol (as a Symbol). Signal names must start from upper case latter. For example: :Input_signal, :state, :Output_signal.

You can define input/output signals and states by input :Input_signal, state :state, output :Output_signal at the beginning of the file. It is optionally, because using signals and states will be detecting automatically by code.

Rule is start from on word. After it you should write input signal and states names separated by commas. When this input signal will be send to code and all states will be active, this rule will be run.

Command must be surrounded by do and end words. Each command must be on a separate line or separated by a semicolon.


# Send alternately :Ping or :Pong

input  :Print # Command to write next word
output :Ping, :Pong

# Initialize first state
on :Init do
  up :ping

# Send ping and change state
on :Print, :ping do
  send :Ping
  down :ping
  up :pong

# Send pong and change state
on :Print, :pong do
  send :Pong
  down :pong
  up :ping