It's the other way around; I want to turn a string literal into an identifier.

The 
[program](https://hg.sr.ht/~sschwarzer/todoreport/browse/default/src/todoreport.nim)
 parses a [todo.txt](https://github.com/todotxt/todo.txt#todotxt-format-rules) 
file and displays the information grouped and sorted (grouping isn't 
implemented yet). The user can specify the sort criteria on the command line, 
for example, 
    
    
    $ todoreport --sort-by=prio,crd todo.txt
    
    
    Run

would print the tasks from the todo.txt file sorted by priority, then by 
creation date. So the user doesn't specify the field names for the `Task` 
object directly, but the user input is "translated" to the corresponding field 
name with a [hash 
table](https://hg.sr.ht/~sschwarzer/todoreport/browse/default/src/todoreport.nim#L15).

What I'm looking for is something like Python's `getattr`. For example, 
`getattr(someObject, "fieldName")` would return the value of 
`someObject.fieldName`. Since Nim uses the term "field" instead of "attribute", 
a Nim version of this could be called `getField`.

Reply via email to