How to resolve the algorithm Associative array/Creation step by step in the APL programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Associative array/Creation step by step in the APL programming language

Table of Contents

Problem Statement

The goal is to create an associative array (also known as a dictionary, map, or hash).

Related tasks:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Associative array/Creation step by step in the APL programming language

Source code in the apl programming language

⍝  Create a namespace ("hash")
      X⎕NS 
      
      ⍝ Assign some names
      X.this'that'
      X.foo88
      
      ⍝  Access the names
      X.this
that
      
      ⍝  Or do it the array way
      X.(foo this)
88  that 
      
      ⍝  Namespaces are first class objects
      sales  ⎕NS 
      sales.(prices quantities)  (100 98.4 103.4 110.16) (10  12 8  10)
      sales.(revenue  prices +.× quantities)
      sales.revenue
4109.6


      ⍝ Assign some names
      X.this'that'
      X.foo88
      
      ⍝  Access the names
      X.this
that

      ⍝  ..or access via 'array index' syntax
      X['this']
that
      
      ⍝  Or do it the array way
      X.(foo)
88

      ⍝ GNU APL does not support multiple assoc. array indices however
      X.(foo this)
VALUE ERROR
      X.(foo this)
             ^

      (sales.prices sales.quantities)  (100 98.4 103.4 110.16) (10 12 8 10)
      sales.revenue  sales.prices +.× sales.quantities
      sales.revenue
4109.6


  

You may also check:How to resolve the algorithm Keyboard input/Keypress check step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Power set step by step in the Erlang programming language
You may also check:How to resolve the algorithm Video display modes step by step in the Phix programming language
You may also check:How to resolve the algorithm Sudan function step by step in the Ruby programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the Python programming language