Author Topic: Sanger  (Read 12191 times)

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« on: November 16, 2007, 05:15:38 PM »
Please check it out.

http://ersatz.org/sanger-1.0.zip

Feedback and bug reports are equally welcome. If you notice a bad turn of speech in documentation, please report me as well, since English is not my native language and I can hardly check myself.

Code: [Select]
NAME
    sanger.pl - Darwinbots DNA macro language interpreter

SYNOPSIS
        sanger.pl [file]
        sanger.pl -e [code]
        sanger.pl --help

DESCRIPTION
    Sanger is a macro language designed to make conditionless DNA
    construction easier. Sanger is named after Frederick Sanger, inventor
    of DNA sequencing.

    "sanger.pl" is Sanger interpreter which gives classic low-level DNA code
    on output. Sanger code may contain macro definitions and file
    inclusions. Everything else is interpreted as instructions, I. e. macro
    calls and plain DNA code.

MACROS
    Macro definition starts with DEFINE and lasts till a semicolon. Macro
    names are case-insensitive.

        DEFINE NEZ     $1 sgn abs;
        DEFINE NE      NEZ( $1 $2 sub );

    Definition of a macro may contain argument references: $1, $2 and so on.
    When macro is called, argument references are replaced with arguments.
    For instance,

        NE( *.myeye, *.refeye )

    is interpreted as

        *.myeye *.refeye sub sgn abs
    
FILE INCLUSIONS
    File inclusions start with INCLUDE and last till a semicolon, similar to
    macros.

        INCLUDE filename;

STANDARD LIBRARY
    These macros are found within 'stdlib.dna' file going in distribution.

    NOT( boolean )
    AND( boolean, boolean )
    OR( boolean, boolean )
    XOR( boolean, boolean )
        Boolean operators.

    EQZ( integer )
    NEZ( integer )
    GTZ( integer )
    LTZ( integer )
    GEZ( integer )
    LEZ( integer )
        Compare the top value on the stack with zero.

    EQ( integer, integer )
    NE( integer, integer )
    GT( integer, integer )
    LT( integer, integer )
    GE( integer, integer )
    LE( integer, integer )
        Compare two integers on the top of the stack.

    TEST( boolean, integer )
        If the first argument is true, pushes the second argument on the
        stack, otherwise pushes zero.

    IF( boolean, integer, integer )
        If the first argument is true, pushes the second argument on the
        stack, otherwise pushes the third.

EXAMPLES
        Lionfish's genes are taken for demonstration.

            INCLUDE stdlib.dna;

            ' Venom blinding and strvenom killer exploit
            IF( 1 rnd, IF( 1 rnd, .eye5width, .eye5dir ), .strvenom ) .vloc store

            ' Selective shooting
            DEFINE ENEMY NE( *.in1, *.refage );
            IF( GT( *.eye5, 60 ),
                IF( NEZ( *.refeye ),
                    TEST( ENEMY(), -3 ),
                    -6 ),
                TEST( GT( *.nrg, 1000 ), -3 ) ) .shoot store

SEE ALSO
    Frederick Sanger
        <http://en.wikipedia.org/wiki/Frederick_Sanger>

    Lionfish's genes explained
        <http://www.darwinbots.com/Forum/index.php?showtopic=2169>

AUTHOR
    Ivan Fomichev <ifomichev@gmail.com>

COPYRIGHT
        Copyright (C) 2007  Ivan Fomichev

        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
« Last Edit: November 16, 2007, 05:43:20 PM by Gobo »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7714
    • View Profile
Sanger
« Reply #1 on: November 16, 2007, 09:00:33 PM »
Neat, but you might want to consider changing the names for the "standard library" to be clearer.  For instance, EQZ is awefully cryptic if you've never used assembly.  And the macro language is supposed to be higher level than the original DNA.  Maybe something like EqualsZero or similar.

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #2 on: November 17, 2007, 02:33:10 AM »
Quote from: Numsgil
Neat, but you might want to consider changing the names for the "standard library" to be clearer.  For instance, EQZ is awefully cryptic if you've never used assembly.  And the macro language is supposed to be higher level than the original DNA.  Maybe something like EqualsZero or similar.
I thought about that, but preferred clarity to brevity. Actually these names are based rather on Perl operators than assembly. By the way, high level language may have nothing with clarity, e. g. see APL

Nevertheless thank you for your notice, I'm likely to add verbose names as aliases in the next revision.
« Last Edit: November 17, 2007, 02:34:44 AM by Gobo »

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #3 on: November 17, 2007, 02:58:24 AM »
I noticed, that IF is not as effective as it might be, when arguments themselves are complex expressions, since $3 is calculated twice. This will be fixed in the next revision.

Originial definition:
Code: [Select]
DEFINE IF       $2 $3 sub $1 mult $3 add;Revised definition:
Code: [Select]
DEFINE IF       $3 dup $2 sub $1 mult sub;
« Last Edit: November 17, 2007, 03:09:24 AM by Gobo »

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Sanger
« Reply #4 on: November 17, 2007, 04:37:03 AM »
Okay, maybe I am acting like a stupid-head. Well just maybe.  

What can I do with this sanger-program???

Give some explanation, becouse I just don't get the full point.

I Just read the first line again.
It says.
Darwinbots DNA macro language interpreter

Does it means it converts DB dna to a higher languege. If so, I don't understand the languege at all.
But you want to make a program or something that codes what you make in DB-dna and can recode back to higher languege. That could be pretty good. Maybe something for a better understandment of evolved bots or something.(their dna is mostly harder to read)

And just to know, what does EQZ exactly mean??(along with the others)
« Last Edit: November 17, 2007, 04:50:04 AM by Peter »
Oh my god, who the hell cares.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7714
    • View Profile
Sanger
« Reply #5 on: November 17, 2007, 06:47:19 AM »
Quote from: Peter
What can I do with this sanger-program???

You can write a high level version of DNA that gets compiled into Darwinbots DNA code.  I believe one of the more recent bots in the arena, the one that was crazy long, Guardian I think, was written in a macro language like this, and "compiled" into usable code.

As the complexity of a bot increases, it becomes more and more necessary to write in a higher level and compile it into DNA.  I doubt, for instance, a person could write DNA that's thousands of bps long.  The complexity is just overwhelming.

Quote
And just to know, what does EQZ exactly mean??(along with the others)

You need to actually read posts before declaring that they don't make sense.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7714
    • View Profile
Sanger
« Reply #6 on: November 17, 2007, 07:01:14 AM »
Quote from: Gobo
I thought about that, but preferred clarity to brevity. Actually these names are based rather on Perl operators than assembly. By the way, high level language may have nothing with clarity, e. g. see APL  

Nevertheless thank you for your notice, I'm likely to add verbose names as aliases in the next revision.

Well, it depends on how high level you want to get.  Something like Ruby is what I consider the "perfect" language.  Making programming easy for the programmer is emphasized over implementation difficulty.  The result is that it's very intuitive and fun to program in.

By contrast, something like assembly is designed only to be easy for the computer to interpret.  Programming ease is not the priority at all.  The current DNA language is comparable to assembly, so I'm thinking you should aim for something like ruby.  Something totally natural for a coder to work in.  You could even go the full nine yards and implement classes, too.  Just depends on your goals.

You might want to give this a look.  About the 4th or 5th post down Trafalgar shows the code he used for Guardian for his interpreter.
« Last Edit: November 17, 2007, 07:10:04 AM by Numsgil »

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #7 on: November 17, 2007, 07:10:27 AM »
Quote from: Numsgil
You might want to give this a look.  About the 4th or 5th post down Trafalgar shows the code he used for Guardian for his interpreter.
Hmmm... It seems I have reinvented a bike
Is Guardian's interpreter's code available?
« Last Edit: November 17, 2007, 07:11:52 AM by Gobo »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7714
    • View Profile
Sanger
« Reply #8 on: November 17, 2007, 07:12:10 AM »
I don't think he ever released it, but he'd probably share if you could reach him.

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #9 on: November 17, 2007, 07:43:54 AM »
Quote from: Numsgil
I don't think he ever released it, but he'd probably share if you could reach him.
I think I dropped him a personal message, but it didn't show up in "Sent Items". Is it ok?

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Sanger
« Reply #10 on: November 17, 2007, 08:15:33 AM »
Quote from: Numsgil
Quote from: Peter

And just to know, what does EQZ exactly mean??(along with the others)

You need to actually read posts before declaring that they don't make sense.
When did I declare they don't make sense?
What made you think I didn't red any posts?

Quote
EQZ( integer )
    NEZ( integer )
    GTZ( integer )
    LTZ( integer )
    GEZ( integer )
    LEZ( integer )
        Compare the top value on the stack with zero.
I see compare the top value on the stack with zero. Everyone?, I don't think they all do desame so what do they do.



Quote from: Gobo
Quote from: Numsgil
I don't think he ever released it, but he'd probably share if you could reach him.
I think I dropped him a personal message, but it didn't show up in "Sent Items". Is it ok?
Yes, it is.
Oh my god, who the hell cares.

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #11 on: November 17, 2007, 08:22:33 AM »
Quote from: Peter
Quote
   EQZ( integer )
    NEZ( integer )
    GTZ( integer )
    LTZ( integer )
    GEZ( integer )
    LEZ( integer )
        Compare the top value on the stack with zero.
I see compare the top value on the stack with zero. Everyone?, I don't think they all do desame so what do they do.
EQZ - equal to zero
NEZ - not equal to zero
GTZ - greater than zero
LTZ - less than zero
GEZ - greater or equal to zero
LEZ - less or equal to zero

If you glanced in 'stdlib.dna', you could easily figure that by yourself.

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #12 on: November 17, 2007, 08:47:39 AM »
Quote from: Numsgil
You might want to give this a look.  About the 4th or 5th post down Trafalgar shows the code he used for Guardian for his interpreter.
I looked into it more thoroughly. Trafalgar's interpreter has a prettier syntax, but it seems it lacks at least two prominent features Sanger has.

First, there are no macros with arguments. So Trafalgar's interpreter's language seems to me less extensible, than Sanger.

Second, there is no branching with "else" case (compare to IF macro in Sanger). As the result, I expect DNA code produced with Trafalgar's interpreter's language be much more verbose than Sanger's, since the same conditions repeat in compiled code excessively.

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #13 on: November 21, 2007, 12:21:10 AM »
Quote from: Numsgil
By contrast, something like assembly is designed only to be easy for the computer to interpret.  Programming ease is not the priority at all.  The current DNA language is comparable to assembly, so I'm thinking you should aim for something like ruby.  Something totally natural for a coder to work in.
I have trifled Parse::Eyapp and I think I can manage a prettier syntax. Sample code for the same Lionfish's genes follows.

Code: [Select]
include "stdlib.dna";

.vloc = rnd(1) ? .strvenom : rnd(1) ? .eye5width : .eye5dir;

function isEnemy() { *.in1 != *.refage }

if ( *.eye5 > 60 ) {
    if ( *.refeye != 0 ) {
        if ( isEnemy() ) .shoot = -3;
    }
    else .shoot = -6;
}
else if ( *.nrg > 1000 ) .shoot = -3;
I suppose to embed plain DNA with backticks and have named arguments for "functions". The following example is contrived, since notEquals is built-in "!=", and notEqualsZero is thought to be used within as an optimization of "a != 0".

Code: [Select]
function notEqualsZero(a) { a, `abs sgn`; }
function notEquals(a, b) { notEqualsZero( a - b ); }
Please make your notices before I begin developing, because it is much easier to change code before it has been written
« Last Edit: November 21, 2007, 02:06:14 AM by Gobo »

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #14 on: November 25, 2007, 11:52:21 AM »
I have written pre-alpha Sanger with new syntax. This is not yet documented, though is quite intuitive.
You can download it from http://ersatz.org/sanger-1.999.tar.gz or try it online at http://ersatz.org/sanger.html. By default the form contains the source of Animal Minimalis in Sanger.

Just few notices.
  • There is a ternary conditional assignment operator: EXPR1 ?? EXPR2 = EXPR3. It means: assign EXPR3 to EXPR1 if EXPR2 is true. EXPR2 may contain a special word this (but just once), which refers to EXPR3. E. g.
    Code: [Select]
    .aimsx ?? this = ( *.eye9 && -40 ) + ( *.eye8 && -30 ) + ( *.eye7 && -20 ) +
            ( *.eye6 && -10 ) + ( *.eye4 && 10 ) + ( *.eye3 && 20 ) +
            ( *.eye2 && 30 ) + ( *.eye1 && 40 );

    .eye5width ?? ( this != *.eye5width ) = ( rnd(4) == 0 ? 900 : 0 );
  • You can define macros with -> operator. For now, they cannot be inside genes. They may have arguments, separated with comma.
    Code: [Select]
    friendly() -> *.refeye == *.myeye;
    chance( n ) -> rnd( n ) == 0;
  • Custom variables are defined with similar syntax.
    Code: [Select]
    kinfactor -> 971;
  • For now, there is only syntax for conditionless genes.
    Code: [Select]
    always {
        ...
    }
  • You may have expressions on the left side, too.
    Code: [Select]
    *.eye5 > 50 && !friendly() && .shoot = -1;
  • Logical operators || and && have the same return value as in Perl. It means that
        5 || 3 == 5
        0 || 2 == 2
        3 && 5 == 5
        0 && 2 == 0
« Last Edit: November 25, 2007, 03:22:20 PM by Gobo »