Syntax: Lists, Routines, Pointers

Here are the first few notable syntax changes I'm planning for this next iteration of Bard.

  1. Back to {Curly,Braces,For,Lists}

    Originally I wanted Bard to directly support JSON-style notation of literals (and it has until now). Practically speaking however I never use the feature (in terms of ever copying and pasting JSON into my Bard source) and I've got better things to do with the square brackets (see Pointers, below).

    So lists are going back to using curly braces. However, literal tables (maps/dictionaries) can still be declared using curly braces as well - tables have colons, lists don't.

    Type-inferred literal list: {4,5,6}

    Explicitly typed literal list: Integer[]{4,5,6}

    Type-inferred literal table: {first:"Abe",last:"Pralle"}

    Explicitly typed literal table: [String:String]{first:"Abe",last:"Pralle"}

  2. Globals and Routines

    Bard now supports global variables with the keyword 'global', with syntax variations the same as 'local' variables. For example:

    global configured : Logical
    global program_start_time = Time.current
    

    Bard also supports non-object-oriented 'routines' AKA functions. Like Bard
    methods they begin with the keyword 'routine' and don't require an 'endRoutine' statement.

    routine add( a:Real, b:Real )->Real
      return a + b
    
  3. Pointers

    Bard uses bounding square brackets to denote a pointer type or to dereference an existing pointer. The built-in command addressOf() will fetch the address of a variable. Pointer-based code will only translate to languages that directly support pointers.

    // C Code
    double r, angle, x, y;
    ...
    polar_to_xy( r, angle, &x, &y )
    
    void polar_to_xy( double r, double radians, 
        double* x_ptr, double *y_ptr )
    {
      *x_ptr = r * cos( radians );
      *y_ptr = r * cos( radians );
    }
    
    # Bard Code
    local r, angle, x, y : Real
    ...
    polar_to_xy( r, angle,
        addressOf(x), addressOf(y) )
    
    routine polar_to_xy( r:Real, radians:Real,
        x_ptr:[Real], y_ptr:[Real] )
      [x_ptr] = r * Math.cos( radians )
      [y_ptr] = r * Math.sin( radians )
    

As in C, array notation can also be used with Bard pointers.