[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Named parameters to format?
From: |
Christopher Allan Webber |
Subject: |
Re: Named parameters to format? |
Date: |
Tue, 15 Dec 2015 09:43:15 -0600 |
Mark H Weaver writes:
> Christopher Allan Webber <address@hidden> writes:
>
>> I've been thinking about what I'm going to do once I hit the need for
>> gettext support. I'm not really sure for things that have multiple
>> variables in their string. In python land, I'd do something like:
>>
>> gettext("foo %(bar) %(baz)") % {"bar": "bleh",
>> "baz": "wonk"}
>>
>> This would give translators an opportunity to move the right parameters
>> to the right place in the string. However, this appears to not be
>> possible in our current format system, because there's no place to put
>> keyword based substitutable arguments. Syntactic word ordering varies
>> from natural language to natural language, so...
>
> It's true that (ice-9 format) doesn't provide a way to specify
> substitutable arguments by keyword, but it _does_ provide a way to
> specify arguments by index. Search for "Argument jumping" in section
> 7.10 (Formatted Output) of the Guile manual. In particular, "address@hidden"
> sets
> the argument "pointer" to the first argument (index 0), and more
> generally "address@hidden" jumps to argument N. So, for example:
>
> scheme@(guile-user)> (format #f "address@hidden and address@hidden" 1 2)
> $1 = "1 and 2"
> scheme@(guile-user)> (format #f "address@hidden and address@hidden" 1 2)
> $2 = "2 and 1"
>
> I agree that this is not very nice, and that we should find a better
> solution.
>
> Mark
Aha, it's very helpful though! That does solve my need.