
  function(query_select __lst input_callback)
    set(args ${ARGN})
    list_extract_flag(args --index)
    ans(index)
    set(i 0)
    list(LENGTH ${__lst} len)

    message_indent_push(+2)
    foreach(item ${${__lst}})
      message("${i}: ${item}") 
      math(EXPR i "${i} + 1")
    endforeach()
    message_indent_pop()
    while(true)
      echo_append("> ")
      call("${input_callback}"())
      ans(selected_index)
    
      string_isnumeric("${selected_index}")
      ans(isnumeric)
      if(isnumeric)
        if("${selected_index}" GREATER 0 AND ${selected_index} LESS ${len})
          break()
        else()
          message_indent("please enter a positive number < ${len}")
        endif()
      else()
        list(FIND ${__lst} "${selected_index}" selected_index)
        if(NOT "${selected_index}_" STREQUAL "_")
          break()
        endif()
        message_indent("please enter a number")
      endif()
    endwhile()
    if(index)
      return(${selected_index})
    endif()
    list(GET ${__lst} ${selected_index} selected_value)
    return_ref(selected_value)
  endfunction()