• voxel
    link
    fedilink
    arrow-up
    6
    arrow-down
    2
    ·
    edit-2
    1 year ago

    not unique to python.

    function pointers and hashmaps exist in basically all languages

    like in lua:

    local table = {
      add = function(a, b) return a + b end
    }
    table["add"](4, 5)
    

    JavaScript:

    {
      add: (a, b) => a + b
    }
    

    Rust (using hashmaps with string keys is extremely inefficient tho, there are much better options here but whatever)

    let map = HashMap::from([
       ("add", |a, b| a + b),
    ]);
    
    //...
    
    map["add"](1, 3);