Am 18.09.2016 um 21:04 schrieb Allin Cottrell:
OK, maybe this just me, but personally I hate, despise and deplore
the
various supposedly "user-friendly" alternatives to C-style printf as
found in Ox, R and some other languages. I find it terribly confusing to
have to mix quoted string-literal chunks and variable names, all comma
separated, in a single statement.
(Side remark: What _is_ confusing about string literals in hansl is the
way how literals are given without quotes in a foreach loop --as in
"loop foreach i peach pear plum"--, and probably in a few more places;
but I've said that before.)
It's a matter of taste of course, but Jack's experience regarding user
feedback would seem to support my intuition about what people find
user-friendly.
Anyway, one could probably get pretty close to what I have in mind with
the following example (working code!):
<hansl>
function string str(scalar n)
if isnan(n)
return "NaN"
elif missing(n)
return "NA"
elif (n - 1e-5) <= int(n) && int(n) <= (n + 1e-5) # is integer
return sprintf("%d", n)
else
return sprintf("%g", n)
endif
end function
eval "hey" ~ str(0.5) ~ "hu"
eval "zoom" ~ str(1/0) ~ " zap"
</hansl>
In some sense I'm just using the str() function as a short form for the
sprintf() function with an implicit format default.
Now I've read your latest email about eval and print, but personally I
still think it's a bit of a pity that I cannot use print here, as it
would sound/read more natural IMHO. (Does the eval output actually also
get diverted if an "outfile" command is active?)
With printf, you have a clear separation of just one string literal,
the
format, and whatever variables or expressions you want to print.
I don't really see how the string literal can be called separated from
the format when the format spec comes right in the middle of the literal!?
cheers,
sven