|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
|
|
|
Re: Re: [sc-users] String.formatI'd say, let's have a readable method name for the base implementation, then % as a shortcut. + String fformat /* for lack of a better name now */ { |... items| ... } % { |array| this.fformat(*array) } } hjh On Jul 8, 2008, at 7:45 AM, Dan Stowell wrote:
: H. James Harkins : http://www.dewdrop-world.net .::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..: "Come said the Muse, Sing me a song no poet has yet chanted, Sing me the universal." -- Whitman |
|
|
Re: [sc-users] String.format>Looks a bit obscure to me. Bit worried about Perl-like obfuscated
>piles of symbols. But if python does it, who am I to argue? Go for it. yes, % seems a bit obscure. Although the association with modulo kind of makes the right knot in my mind. >Dan > > >2008/7/8 Julian Rohrhuber <rohrhuber@...>: >> this seems like a good solution to me. >> >>> so back to this, it would be really nice to have python style % operator >>> for string that would call fformat >>> >>> "zook:%s ball:%s " % [z,b] >>> >>> I suggest we just use the dict solution in Post >>> >>> %c - compile string, which I like >>> >>> and then add a common subset of python format codes: >>> %i - int >>> %f - float >>> %s - string >>> >>> >>> >>> and for various fancy formatting just add the methods to SimpleNumber >>> >>> SimpleNumber:leftPad >>> Float:rightPad >>> >>> z = 3; >>> b = 0.27398838 >>> "zook:%s ball:%s" % [ z.leftPad(2), b.asStringPrec(4) ] >>> >>> we have already: >>> SimpleNumber:asStringPrec >>> SimpleNumber:asTimeString >>> >>> >>> then its much easier to understand what formatting you are specifying. >>> >>> >>> personally I have to go look up the formatting codes any time I want to >>> use them in either python, c, javascript or php. so having a "standard" >>> formatter in sc isn't important. >>> >>> simplicity is better >>> >>> >>> On Fri, May 30, 2008 at 2:26 PM, Julian Rohrhuber >>> <<mailto:rohrhuber@...>rohrhuber@...> wrote: >>> >>> >James Harkins wrote: >>>>> >>>>> Anyway, according to >>>>> >>>>> >>>>> >>>>><http://www.cplusplus.com/reference/clibrary/cstdio/printf.html>http://www.cplusplus.com/reference/clibrary/cstdio/printf.html >>>>> the >>>>> "specifier" (last character of formatting token) is always alphabetic >>>>> (allowing also %% for an escape sequence == % in the output). >>>>> >>>>> So the parsing rule is really simple, given i = position of % in the >>>>> string, >>>>> >>>>> var string = "hello %0.000f xyz", i = string.indexOf($%), token; >>>>> token = String.new; >>>>> while { >>>>> i = i + 1; >>>>> string[i] !? { token = token.add(string[i]) }; >>>>> i < string.size and: { string[i].isAlpha.not and: { string[i] != $% >>>>> } } >>>>> }; >>>>> token >>>>> --> 0.000f >>>>> >>>>> hjh >>>>> >>>> >>>> wikipedia (which has several interesting considerations) writes: >>>> >>>> The syntax for a format placeholder is >>>> "%[parameter][flags][width][.precision][length]type". >>> >>> So should we take away fformat again (I only committed it so that >>> those who need the functionality may test and extend it) ? >>> >>> the sc-typical oop-formating is not possible in the standard printf >>> version, so I'm not sure if it is the best solution. We could add a >>> class called StringFormats that the strings could be passed to. >>> -- >>> >>> >>> >>> >>> >>> >>> . >>> _______________________________________________ >>> sc-users mailing list >>> <mailto:sc-users@...>sc-users@... >>> >>> >>><http://lists.create.ucsb.edu/mailman/listinfo/sc-users>http://lists.create.ucsb.edu/mailman/listinfo/sc-users >> >> >> -- >> >> >> >> >> >> . >> >> _______________________________________________ >> sc-users mailing list >> >> >> info (subscribe and unsubscribe): >> http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880 >> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/ >> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/ >> > > > >-- >http://www.mcld.co.uk > >_______________________________________________ >sc-dev mailing list > > >info (subscribe and unsubscribe): >http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880 >archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/ >search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/ -- . _______________________________________________ sc-dev mailing list info (subscribe and unsubscribe): http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880 archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/ search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/ |
|
|
|
| Free Forum Powered by Nabble | Forum Help |