lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Am 23.08.2015 um 12:50 schröbte John Hind:
Date: Sat, 22 Aug 2015 17:08:14 -0400
From: Sean Conner <>

I'll give "complex" a pass (given the the modifiers you can add), but
where do you get "arbitrary" from?

	%d - decimal output of a number
	%o - octal output of a number
	%x - hexidecimal output of a number
	%s - string
	%f - float
	%q - quoted string

I'll give you a reciprocal pass on "arbitrary" then (though why 'x'
for hexadecimal rather than 'h'?). My point is: why does this syntax
not aspire to the same degree of readability as the rest of Lua? I do
not think a proposal to shorten ALL of Lua's keywords to one letter
prefixed by a randomly selected punctuation symbol (what have
percentages got to do with string formatting?) would be considered
sensible! (OK, I've just taken back my pass on "arbitrary"!)

Using a template language for string formatting instead of general purpose programming language constructs has the obvious benefit that the result strings look much more like the source strings. Short but eye-catching formatting instructions reinforce that benefit but also allow you to see at a glance where the result string will be different from the source string. When introducing a template language, it makes perfect sense to reuse (as far as possible) something preexisting and familiar instead of inventing yet another new language.

The situation is similar for string matching: Many patterns contain parts that should match verbatim, so a template language makes sense. Also, there is *one* widely used syntax for this, and it is regular expressions.

Regarding string (un)packing: I don't know whether there are preexisting and familiar languages for this (other than Roberto's struct library). However, I think that a "preview" with a strong resemblance to the final result makes sense there as well. I haven't used Lua's string (un)packing yet, so I can't say how good the resemblance really is.