<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body dir="auto">
<div>Thomas et al,</div>
<div id="AppleMailSignature"><br>
</div>
<div id="AppleMailSignature">You have identified two separate items with your previous good introduction.</div>
<div id="AppleMailSignature"><br>
</div>
<div id="AppleMailSignature">In my opinion, I agree that the need to create an intermediate string is at the level of "nuisance." I really wish I didn't have to do it and I think my code would look a little bit tighter if I didn't have to do it yet it's not
 keeping me from doing anything important. I would welcome a syntax that eliminates the need for creating the intermediate string.</div>
<div id="AppleMailSignature"><br>
</div>
<div id="AppleMailSignature">On your second point I am much less troubled. I find myself unencumbered by the sprintf syntax either in general or as implemented in the IP. Perhaps I've subconsciously (unconsciously?) trained myself to work within the existing
 constraints. This one is not on my wish list.<br>
<br>
Thank you for raising issues and for raising them here. This is a great form for doing it.</div>
<div id="AppleMailSignature"><br>
<span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); background-color: rgba(255, 255, 255, 0); ">Best regards,</span>
<div style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">
<span style="background-color: rgba(255, 255, 255, 0); ">Joseph</span></div>
<div style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">
<span style="background-color: rgba(255, 255, 255, 0); ">--</span></div>
<div style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;">
<span style="font-size: 12pt;">Joseph A. DiVerdi, Ph.D., M.B.A.</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;">
<span style="font-size: 12pt;">Associate Professor of Chemistry</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;">
<span style="font-size: 12pt;">Colorado State University, Fort Collins, CO, USA</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica;">
<span style="font-size: 12pt;"><a href="tel:+1.970.980.5868">+1.970.980.5868</a> -
<a href="http://sites.chem.colostate.edu/diverdi">http://sites.chem.colostate.edu/diverdi</a></span></p>
</div>
</div>
<div><br>
On Feb 24, 2019, at 11:17 AM, Thomas Braun <<a href="mailto:thomas.braun@virtuell-zuhause.de">thomas.braun@virtuell-zuhause.de</a>> wrote:<br>
<br>
</div>
<blockquote type="cite">
<div><span>Hi Igorians,</span><br>
<span></span><br>
<span>since quite some time I'm starting to dislike the sprintf function.</span><br>
<span></span><br>
<span>Main reason is that I need to create a temporary string to be able to work with it and</span><br>
<span>also that it can not be used in arbitrary code as e.g. %s is limited to x number of characters.</span><br>
<span></span><br>
<span>Since quite some time I've been using fmtlib [1] in my C++ projects.</span><br>
<span>In short it allows you to write something like</span><br>
<span></span><br>
<span>fmt::format("The answer is {}.", 42);</span><br>
<span></span><br>
<span>and that returns a string with the contents “The answer is 42.”.</span><br>
<span></span><br>
<span>Now there is no use in trying to get that exact syntax working in Igor Pro.</span><br>
<span></span><br>
<span>But one could get quite close. Here is a hacky hack example:</span><br>
<span></span><br>
<span>Function Examples()</span><br>
<span></span><br>
<span>   print f("Hi {s_a}!", s_a = "HAL")</span><br>
<span>   print f("Are you up to counting from 0 to {v_a}?", v_a = 10)</span><br>
<span>   print f("Sure ;) Wanna see {w_a}?", w_a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10})</span><br>
<span>   print f("In this case have fun with {s_a} and {v_a}s.", v_a=0, s_a="ones")</span><br>
<span>   </span><br>
<span>End</span><br>
<span></span><br>
<span>Function/S f(format, [v_a, s_a, w_a])</span><br>
<span>   string format</span><br>
<span>   variable v_a</span><br>
<span>   string s_a</span><br>
<span>   WAVE w_a</span><br>
<span></span><br>
<span>   variable numDefaultParams, i</span><br>
<span>   string str, buf, w_buf</span><br>
<span></span><br>
<span>   if(ParamIsDefault(v_a))</span><br>
<span>       numDefaultParams += 1</span><br>
<span>   endif</span><br>
<span></span><br>
<span>   if(ParamIsDefault(s_a))</span><br>
<span>       numDefaultParams += 1</span><br>
<span>   endif</span><br>
<span></span><br>
<span>   if(ParamIsDefault(w_a))</span><br>
<span>       numDefaultParams += 1</span><br>
<span>   endif</span><br>
<span></span><br>
<span>   str = format</span><br>
<span></span><br>
<span>   if(numDefaultParams == 0)</span><br>
<span>       // TODO check that str does not contain {}</span><br>
<span>       return str</span><br>
<span>   endif</span><br>
<span></span><br>
<span>   if(!ParamIsDefault(v_a))</span><br>
<span>       // TODO make %g configurable from {}</span><br>
<span>       sprintf buf, "%g", v_a</span><br>
<span>       str = ReplaceString("{v_a}", str, buf)</span><br>
<span>   endif</span><br>
<span></span><br>
<span>   if(!ParamIsDefault(s_a))</span><br>
<span>       // TODO make configurable</span><br>
<span>       str = ReplaceString("{s_a}", str, s_a)</span><br>
<span>   endif</span><br>
<span></span><br>
<span>   if(!ParamIsDefault(w_a))</span><br>
<span>       // TODO make configurable and support dimensions larger than 1D</span><br>
<span>       // and also other wave types</span><br>
<span>       w_buf = "["</span><br>
<span>       for(i = 0; i < DimSize(w_a, 0); i += 1)</span><br>
<span>           sprintf buf, "%g", w_a[i]</span><br>
<span>           w_buf += buf</span><br>
<span>           </span><br>
<span>           if(i != DimSize(w_a, 0) - 1)</span><br>
<span>               w_buf += ", "</span><br>
<span>           endif</span><br>
<span>       endfor</span><br>
<span>       w_buf += "]"</span><br>
<span></span><br>
<span>       str = ReplaceString("{w_a}", str, w_buf)</span><br>
<span>   endif</span><br>
<span>   </span><br>
<span>   return str</span><br>
<span>End</span><br>
<span></span><br>
<span>which gives</span><br>
<span></span><br>
<span>•examples()</span><br>
<span> Hi HAL!</span><br>
<span> Are you up to counting from 0 to 10?</span><br>
<span> Sure ;) Wanna see? -> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]</span><br>
<span> In this case have fun with ones and 0s.</span><br>
<span></span><br>
<span>and this is already quite nice (I think) because it avoids both my main problems with sprintf.</span><br>
<span></span><br>
<span>My main problem at the moment is that it does not scale with the number of characters per type. If we would support up to 8 characters after the "_" we have already
</span><br>
<span></span><br>
<span>•print/D 26^8*3</span><br>
<span> 626481193728</span><br>
<span></span><br>
<span>combinations and thus a dump approach would need that many optional parameters. And to be usable we would need a way to iterate over them in a way with has sub-linear complexity.</span><br>
<span></span><br>
<span>And we would probably also hit a hard-coded limit of the number of optional parameters or maximum line length or ....</span><br>
<span></span><br>
<span>Thoughts?</span><br>
<span></span><br>
<span>Thomas</span><br>
<span></span><br>
<span>[1]: <a href="https://github.com/fmtlib/fmt">https://github.com/fmtlib/fmt</a></span><br>
<span>_______________________________________________</span><br>
<span>Info-igor mailing list</span><br>
<span><a href="mailto:Info-igor@lists.info-igor.org">Info-igor@lists.info-igor.org</a></span><br>
<span><a href="http://lists.info-igor.org/listinfo.cgi/info-igor-info-igor.org">http://lists.info-igor.org/listinfo.cgi/info-igor-info-igor.org</a></span><br>
</div>
</blockquote>
</body>
</html>