digitalmars.D - std.metastrings
- Bill Baxter (15/15) Nov 13 2009 Std.metastrings could use some work.
- bearophile (4/7) Nov 13 2009 I suggest you to ask to downs too, he has done lot of such things. Using...
- Andrei Alexandrescu (3/23) Nov 13 2009 Please have at it.
- Vladimir Panteleev (11/17) Nov 14 2009 Why don't we have version(CTFE) or something like that yet? Then we can ...
- Don (5/20) Nov 14 2009 Yes, I think it's something we need. I've worked out how to do it, but
- downs (17/17) Nov 14 2009 Slightly modified from what you so amusingly called "my CoolTools.ctfe":
- Bill Baxter (15/32) Nov 14 2009 ces" a string in two at a marker, returning the text before the marker a...
- downs (3/41) Nov 14 2009 Feel free. :D
Std.metastrings could use some work. So I'm thinking to take it upon myself to make it more useful. After asking some questions here about it previously, I got a bunch of comments like "oh yeh I have that in my CoolTools.ctfe module". Well, that's kinda silly that everyone is re-inventing such things. I'm just mentioning this here in case someone wants to stop me, or offer their versions of CoolTools.ctfe, or argue that it should be std.ctfe rather than std.metastrings, or whatever. My plan is to try to do things with an API that reflects std.string as closely as possible, and then as CTFE gets better, just replace those functions with aliases to the ones in std.string. So eventually std.metastrings should contain little more than a bunch of aliases. But in the mean time there'll be a one-stop shop for basic compile-time string manipulation functions. --bb
Nov 13 2009
Bill Baxter:I'm just mentioning this here in case someone wants to stop me, or offer their versions of CoolTools.ctfe, or argue that it should be std.ctfe rather than std.metastrings, or whatever.I suggest you to ask to downs too, he has done lot of such things. Using a cleaned up part of his 'tools' (in scraps) for Phobos can be positive. Even if some things will need to be adapted to D2 (downs has written them for D1, I think) their purpose, name (and code) can give you a good starting point. Bye, bearophile
Nov 13 2009
Bill Baxter wrote:Std.metastrings could use some work. So I'm thinking to take it upon myself to make it more useful. After asking some questions here about it previously, I got a bunch of comments like "oh yeh I have that in my CoolTools.ctfe module". Well, that's kinda silly that everyone is re-inventing such things. I'm just mentioning this here in case someone wants to stop me, or offer their versions of CoolTools.ctfe, or argue that it should be std.ctfe rather than std.metastrings, or whatever. My plan is to try to do things with an API that reflects std.string as closely as possible, and then as CTFE gets better, just replace those functions with aliases to the ones in std.string. So eventually std.metastrings should contain little more than a bunch of aliases. But in the mean time there'll be a one-stop shop for basic compile-time string manipulation functions. --bbPlease have at it. Andrei
Nov 13 2009
On Fri, 13 Nov 2009 22:17:21 +0200, Bill Baxter <wbaxter gmail.com> wrote:My plan is to try to do things with an API that reflects std.string as closely as possible, and then as CTFE gets better, just replace those functions with aliases to the ones in std.string. So eventually std.metastrings should contain little more than a bunch of aliases. But in the mean time there'll be a one-stop shop for basic compile-time string manipulation functions.Why don't we have version(CTFE) or something like that yet? Then we can just have two versions of code for most of std.string - one optimized for runtime execution, and one adhering to CTFE restrictions. That would remove the need to write two versions of a function which would be called both during compile-time and runtime (one using std.metastrings and one using std.string). Also, nitpick: std.metastrings is plural but std.string is singular. -- Best regards, Vladimir mailto:thecybershadow gmail.com
Nov 14 2009
Vladimir Panteleev wrote:On Fri, 13 Nov 2009 22:17:21 +0200, Bill Baxter <wbaxter gmail.com> wrote:Yes, I think it's something we need. I've worked out how to do it, but haven't implemented it yet. There's way too much to do... It would fit very nicely into the 'meta' proposal. EG if (meta.ctfe) { ... } else { ... }My plan is to try to do things with an API that reflects std.string as closely as possible, and then as CTFE gets better, just replace those functions with aliases to the ones in std.string. So eventually std.metastrings should contain little more than a bunch of aliases. But in the mean time there'll be a one-stop shop for basic compile-time string manipulation functions.Why don't we have version(CTFE) or something like that yet? Then we can just have two versions of code for most of std.string - one optimized for runtime execution, and one adhering to CTFE restrictions. That would remove the need to write two versions of a function which would be called both during compile-time and runtime (one using std.metastrings and one using std.string).
Nov 14 2009
Slightly modified from what you so amusingly called "my CoolTools.ctfe": ctSlice (not to be confused with the [] array slicing functionality) "slices" a string in two at a marker, returning the text before the marker and removing it (and the marker) from the input text. The ct prefix is handy for differentiating between std.metastrings and std.string functions - one may often want to import both .. string ctSlice(ref string what, string where) { auto loc = what.ctFind(where); if (loc == -1) { auto res = what; what = null; return res; } auto res = what[0 .. loc]; what = what[loc+where.length .. $]; return res; } When is this useful? For instance, when writing a compile-time enum, you may want to use a syntax of the form "EnumName: Entries" In that case, you could write `string name = input.ctSlice(":"); '
Nov 14 2009
On Sat, Nov 14, 2009 at 10:16 AM, downs <default_357-line yahoo.de> wrote:Slightly modified from what you so amusingly called "my CoolTools.ctfe": ctSlice (not to be confused with the [] array slicing functionality) "sli=ces" a string in two at a marker, returning the text before the marker and = removing it (and the marker) from the input text.The ct prefix is handy for differentiating between std.metastrings and st=d.string functions - one may often want to import both .. Yeh, I agree some diffentiator is good. std.metastrings started off with a capital letter convention to differentiate. I'm not sure which is better.string ctSlice(ref string what, string where) { =A0auto loc =3D what.ctFind(where); =A0if (loc =3D=3D -1) { =A0 =A0auto res =3D what; =A0 =A0what =3D null; =A0 =A0return res; =A0} =A0auto res =3D what[0 .. loc]; =A0what =3D what[loc+where.length .. $]; =A0return res; } When is this useful? For instance, when writing a compile-time enum, you may want to use a syn=tax of the form "EnumName: Entries"In that case, you could write `string name =3D input.ctSlice(":"); 'That's nice. I would probably call that something like "ctZapToChar", in honor of the same function in Emacs. :-) Slice is a very confusing name for it. So is your code free game for stealing from for std.metastring? (meaning whatever I borrowed would be re-licensed under Boost) --bb
Nov 14 2009
Bill Baxter wrote:On Sat, Nov 14, 2009 at 10:16 AM, downs <default_357-line yahoo.de> wrote:Feel free. :D (yes this constitutes a full license to redistribute)Slightly modified from what you so amusingly called "my CoolTools.ctfe": ctSlice (not to be confused with the [] array slicing functionality) "slices" a string in two at a marker, returning the text before the marker and removing it (and the marker) from the input text. The ct prefix is handy for differentiating between std.metastrings and std.string functions - one may often want to import both ..Yeh, I agree some diffentiator is good. std.metastrings started off with a capital letter convention to differentiate. I'm not sure which is better.string ctSlice(ref string what, string where) { auto loc = what.ctFind(where); if (loc == -1) { auto res = what; what = null; return res; } auto res = what[0 .. loc]; what = what[loc+where.length .. $]; return res; } When is this useful? For instance, when writing a compile-time enum, you may want to use a syntax of the form "EnumName: Entries" In that case, you could write `string name = input.ctSlice(":"); 'That's nice. I would probably call that something like "ctZapToChar", in honor of the same function in Emacs. :-) Slice is a very confusing name for it. So is your code free game for stealing from for std.metastring? (meaning whatever I borrowed would be re-licensed under Boost) --bb
Nov 14 2009