In simplest form, python string formatting replaces {} with the next `stringified' argument.  It's a good idea!  This simple form has met almost all my requirements.  I've never needed the optional positional specifiers, and sometimes used the specific formatting instructions that can fit within the braces.  Here's a version:

   NB. an implementation
   format=: ''&$: :([: ; (a: , [: ":&.> [) ,. '{}' ([ (E. <@}.;._1 ]) ,) ])

   NB. examples
   1 2 3 format 'A {} and a {} set go {}'
A 1 and a 2 set go 3

   (;:'Marcia John') format 0 :0
Dear {},
   I miss your kiss.
fondly,
{}
)
Dear Marcia,
   I miss your kiss.
fondly,
John

The first of these references uses pre-formatted numbers, the latter task provided reason to create it.

http://rosettacode.org/wiki/Exponentiation_with_infix_operators_in_(or_operating_on)_the_base#J
http://rosettacode.org/wiki/Cistercian_numerals#J

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to