Jump to content

AnyLang Programming Language Comparison/Variables and data structures

From Wikibooks, open books for an open world

Variables as composite data structures

[edit | edit source]

Variables can be combined into composite data structures. Data structures are useful and common in mainstream programming languages, and they follow commonly recognized patterns which can be documented and re-used.[1][2]

SimpleTable (AoH , AoD)

[edit | edit source]

(aka simpletable_aoh [array of hash])

(aka simpletable_aod [array of dictionary])

This composite data structure is suitable for representing a series of rows and columns in most programming languages.[3] AoH stands for "Array of Hashes"[4]

JavaScript

[edit | edit source]
var mytable_aoh = [
   { "fname":"fred"    ,   "lname":"flintstone"  ,   "age":"33"  ,   "sex":"male"    ,  "motto":"yabbadabbadoo"           }
   ,{ "fname":"wilma"   ,   "lname":"flintstone"  ,   "age":"28"  ,   "sex":"female"  ,  "motto":""                        }
   ,{ "fname":"barney"  ,   "lname":"rubble"      ,   "age":"32"  ,   "sex":"male"    ,  "motto":"hiya fred!"              }
   ,{ "fname":"Fred"    ,   "lname":"Astaire"     ,   "age":"76"  ,   "sex":"male"    ,  "motto":"Dancing is a sweat job"  }
];
$mytable_aoh = Array(
    Array( 'lname' => 'Simpson'      ,'fname'  => 'Homer' ,'age' => '35' ,'motto' => '_blank_' )
    ,Array( 'lname' => 'Simpson'     ,'fname'  => 'Marge' ,'age' => '34' ,'motto' => '_blank_' )
    ,Array( 'lname' => 'Flintstone'  ,'fname'  => 'Fred' ,'age' => '33' ,'motto' => '_blank_' ) 
    ,Array( 'lname' => 'John'        ,'fname'  => 'Doe' ,'age' => '0' ,'motto' => '_blank_' )   
    ,Array( 'lname' => 'Flintstone'  ,'fname'  => 'Wilma' ,'age' => '29' ,'motto' => '_blank_' )
);

Rows are represented using an unordered sequence of name-value pairs (aka Dictionary, Hash, Object).

SimpleTable (AoA)

[edit | edit source]

(aka simpletable_aos [array of sequence])

This is a table structure suitable for representing a series of rows and columns in most programming languages.[5]

JavaScript

[edit | edit source]
var mytable_aoa = [
   [ "fname"   ,   "lname"       ,   "age" ,   "sex"     ,  "motto"                   ]
   ,[ "fred"    ,   "flintstone"  ,   "33"  ,   "male"    ,  "yabbadabbadoo"           ]
   ,[ "wilma"   ,   "flintstone"  ,   "28"  ,   "female"  ,  ""                        ]
   ,[ "barney"  ,   "rubble"      ,   "32"  ,   "male"    ,  "hiya fred!"              ]
   ,[ "Fred"    ,   "Astaire"     ,   "76"  ,   "male"    ,  "Dancing is a sweat job"  ]
];

Rows are represented using an ordered sequence of values (aka Array, List).

Notes and references

[edit | edit source]
  1. See e.g., "Perl Data Structures Cookbook". Retrieved 2010-01-15 09:34:53. {{cite web}}: Check date values in: |accessdate= (help) Perl Data Structures Cookbook
  2. Christiansen, Tom (2003). Perl Cookbook. Boston: Twayne Publishers. ISBN 0596003137.
  3. The search fingerprint for this structure is gem_hypo_kinds_yuzovka_aoh.
  4. This term is used in Perl, where a "Hash" is another term for a "Dictionary" array.
  5. The search fingerprint for this structure is gem_hypo_kinds_yuzovka_aoa.