Need to convert Camel string into Snake using Macro + Jinja in For Loop

The problem I’m having

I want to convert “CamelStringX” into “camel_string_x”

The context of why I’m trying to do this

I need to do that inside of for loop to convert all function names into variables with better format

Some example code or error messages

## What I've already tried 
I tried this macro
{% macro to_snake_case(column_name) %}
    {%- set result = "" %}
    {%- set length = column_name|length %}
    {%- for i in range(length) %}
        {%- set char = column_name[i] %}
        {%- if i > 0 and char.isupper() %}
            {%- set result = result + '_' %}
        {%- endif %}
        {%- set result = result + char|lower %}
    {%- endfor %}
    {{ result }}
{% endmacro %}
but it return empty string inside of for loop

-- Create Arrays for Each Variable Type
{% set addresses = [
    'CamelCaseVariable',
    'AnotherCamelCase'
] %}

SELECT 
    {% for var in addresses -%}
        varbinary_substring(data, varbinary_position(data, to_utf8('{{ var }}')) - 52, 20) AS {{ to_snake_case(var) }}
        {%- if not loop.last -%},{%- endif %}        
    {% endfor %}
FROM
    {{ source('arbitrum', 'logs') }}
WHERE
    contract_address = "example"
    AND topic1 = keccak(to_utf8('{{ event_name }}'))