> still be Greek for me.

Well, the when statement is really easy to understand and well explained in the 
manual, so maybe you should read it again. It is good to understand it.

What you may be looking for is a converter, see manual. A converter allows 
automatic conversion of proc parameter types. So you may define a converter 
which converts cstrings to cwidestrings, and then whenever there is a proc that 
needs a cwidestring and you pass it a cstring, then that converter is called 
automatically and does the needed conversion. Note, that use of very many 
converters may make compilation slower, as the compiler has much effort to 
select all the right converters.

For your code example
    
    
    proc s(val: string|Widecstring): Widecstring =
        when not type(val) is Widecstring:
            return newWideCString(convert(val, "utf8", "gb2312"))
        else:
            return val
    

I am not sure if that shape make much sense. As Nim is statically typed, a proc 
signature like "proc s(val: string|Widecstring): Widecstring =" generates two 
procs, one with string, the other with Widecstring argument. Due to the when 
statement, the later really does nothing. What you may want here is just a proc 
or converter that converts from string to WideCString or whatever. 

Reply via email to