[Jprogramming] literal format
David Lambert
b49p23tivg at gmail.com
Thu Mar 18 23:34:16 UTC 2021
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
More information about the Programming
mailing list