digitalmars.D - idea: Templates + AJAX = breakthrough application
- BCS (35/35) Nov 17 2007 I have thought up a really cool template programming idea. I'm so swampe...
- Robert Fraser (2/50) Nov 17 2007 I had this idea a while back, except I used a compile-time function not ...
- BCS (9/12) Nov 17 2007 how could you do it with a function? How would you get to the argument l...
- Robert Fraser (8/24) Nov 18 2007 Mixins.
- BCS (14/44) Nov 18 2007 The only clean way to do it still requiter that ctfeFunc be templated or...
- Robert Fraser (10/25) Nov 19 2007 Sure you can. __traits, typeof(), is expressions... You can't pass
- BCS (11/46) Nov 19 2007 that's what I was thinking of, you end up with template at some point. I...
- Ary Borenszweig (5/40) Nov 19 2007 We already can do that: we've ported all of DMD's semantic, so
I have thought up a really cool template programming idea. I'm so swamped now that I don't have time to work on it so I'm throwing it out here to see if anyone wants to give it a go. Anyway, her its. In a nutshell: Auto AJAX from template magic. it would consist of a template that specializes on a class, interface, struct or free function. The template would implement a function that would take something of the given type. this function would be the server side of an AJAX setup that would exercise the given variable's public interface. The template would also generate a const string that is the JavaScript that is needed for the client side. I see it being used something like this: // given the users partial input, // return a list of auto compleat choices char[][] GetChoices(char[] text){...} const int AJAXport = 0xF00D; const char[] AJAXaddress = "somwhere.not"; char[] BuildWebPageBody() { char[] ret; ret ~= stuff ret ~= "<script type='text/javascript'>\n"; ret ~= AJAX!(GetChoices).JavaScript!(AJAXaddress, AJAXport); ret ~= "</script>\n"; ret ~= moreStuff; return ret; } AJAXthread AJAXserver; static this() { AJAXserver = AJAX!(GetChoices).StartServerThread(AJAXport); } static ~this() { AJAXserver.kill(); }
Nov 17 2007
BCS Wrote:I have thought up a really cool template programming idea. I'm so swamped now that I don't have time to work on it so I'm throwing it out here to see if anyone wants to give it a go. Anyway, her its. In a nutshell: Auto AJAX from template magic. it would consist of a template that specializes on a class, interface, struct or free function. The template would implement a function that would take something of the given type. this function would be the server side of an AJAX setup that would exercise the given variable's public interface. The template would also generate a const string that is the JavaScript that is needed for the client side. I see it being used something like this: // given the users partial input, // return a list of auto compleat choices char[][] GetChoices(char[] text){...} const int AJAXport = 0xF00D; const char[] AJAXaddress = "somwhere.not"; char[] BuildWebPageBody() { char[] ret; ret ~= stuff ret ~= "<script type='text/javascript'>\n"; ret ~= AJAX!(GetChoices).JavaScript!(AJAXaddress, AJAXport); ret ~= "</script>\n"; ret ~= moreStuff; return ret; } AJAXthread AJAXserver; static this() { AJAXserver = AJAX!(GetChoices).StartServerThread(AJAXport); } static ~this() { AJAXserver.kill(); }I had this idea a while back, except I used a compile-time function not a template.
Nov 17 2007
Reply to Robert,I had this idea a while back, except I used a compile-time function not a template.how could you do it with a function? How would you get to the argument list of the function or the list of methods for an aggregate type? You have a good point though, it would almost certainly need to use CTFE for much of the work, the JavaScript if nothing else. Other parts (argument and return value marshaling) would be better in pure template code. For instance, I have a set of template functions somewhere that pack and unpack up a unlimited depth of dynamic arrays into a byte array. It's only about 30 lines of code and will suite for any type of dynamic array.
Nov 17 2007
BCS wrote:Reply to Robert,Mixins. Having never actually used C++ templates, I feel a lot more comfortable writing mixin(ctfeFunc(args)) than writing templ!(args) .I had this idea a while back, except I used a compile-time function not a template.how could you do it with a function? How would you get to the argument list of the function or the list of methods for an aggregate type? You have a good point though, it would almost certainly need to use CTFE for much of the work, the JavaScript if nothing else. Other parts (argument and return value marshaling) would be better in pure template code. For instance, I have a set of template functions somewhere that pack and unpack up a unlimited depth of dynamic arrays into a byte array. It's only about 30 lines of code and will suite for any type of dynamic array.
Nov 18 2007
Reply to Robert,BCS wrote:The only clean way to do it still requiter that ctfeFunc be templated or you cant get to any of the semantic info. Personably I'd rather not use mixins (my parser generator only uses them in two place to generate numbered labels and a goto) My feeling is that it's sort of going backwards in the abstraction domain. Also I'd rather get a lex/syntax error that points to hard text rather than mixin text. I find that a little CTFE, a little template functional programming and a pile of tuple foreaches can get a LOT done. I would actually recommend playing around with template functional programming a little (try some scheme or lisp first though). They are remarkably not that nasty in D. OTOH that's me saying this and and I'm a bit off in what I think of as nasty (my current project involves using lisp to do code-gen for some nasty template Foo, but I get ahead of my self ;-)Reply to Robert,Mixins. Having never actually used C++ templates, I feel a lot more comfortable writing mixin(ctfeFunc(args)) than writing templ!(args) .I had this idea a while back, except I used a compile-time function not a template.how could you do it with a function? How would you get to the argument list of the function or the list of methods for an aggregate type? You have a good point though, it would almost certainly need to use CTFE for much of the work, the JavaScript if nothing else. Other parts (argument and return value marshaling) would be better in pure template code. For instance, I have a set of template functions somewhere that pack and unpack up a unlimited depth of dynamic arrays into a byte array. It's only about 30 lines of code and will suite for any type of dynamic array.
Nov 18 2007
BCS wrote:The only clean way to do it still requiter that ctfeFunc be templated or you cant get to any of the semantic info.Sure you can. __traits, typeof(), is expressions... You can't pass around the types, though.Personably I'd rather not use mixins (my parser generator only uses them in two place to generate numbered labels and a goto) My feeling is that it's sort of going backwards in the abstraction domain. Also I'd rather get a lex/syntax error that points to hard text rather than mixin text. I find that a little CTFE, a little template functional programming and a pile of tuple foreaches can get a LOT done.Descent will soon (in Kramer time...) have the ability to mark errors at a location in a mixin... you still have to figure out where the problem is being created, but at least you can see exactly what the problem is.I would actually recommend playing around with template functional programming a little (try some scheme or lisp first though).I'll be learning that in school next quarter... Never done any functional programming, which may be why I'm so hesitant to adopt template-based programming fully.They are remarkably not that nasty in D. OTOH that's me saying this and and I'm a bit off in what I think of as nasty (my current project involves using lisp to do code-gen for some nasty template Foo, but I get ahead of my self ;-)Heh; looking forward to it!
Nov 19 2007
Reply to Robert,BCS wrote:that's what I was thinking of, you end up with template at some point. If nothing else you get: char[] CTFEfunc(T)(T t){...}The only clean way to do it still requiter that ctfeFunc be templated or you cant get to any of the semantic info.Sure you can. __traits, typeof(), is expressions... You can't pass around the types, though.sweet, will it also do mixin unfolding? this would be where you can expand a mixin in the editor to the text it expands to. This would however require the ability to pin template parameters and unfold/evaluate that as well. Whatever happens, it will be fun to see.Personably I'd rather not use mixins (my parser generator only uses them in two place to generate numbered labels and a goto) My feeling is that it's sort of going backwards in the abstraction domain. Also I'd rather get a lex/syntax error that points to hard text rather than mixin text. I find that a little CTFE, a little template functional programming and a pile of tuple foreaches can get a LOT done.Descent will soon (in Kramer time...) have the ability to mark errors at a location in a mixin... you still have to figure out where the problem is being created, but at least you can see exactly what the problem is.My experience is that template stuff was Greek to me, then after taking programming languages, it was a lot clearer. I wish you luck.I would actually recommend playing around with template functional programming a little (try some scheme or lisp first though).I'll be learning that in school next quarter... Never done any functional programming, which may be why I'm so hesitant to adopt template-based programming fully.:-þ <G>They are remarkably not that nasty in D. OTOH that's me saying this and and I'm a bit off in what I think of as nasty (my current project involves using lisp to do code-gen for some nasty template Foo, but I get ahead of my self ;-)Heh; looking forward to it!
Nov 19 2007
BCS escribió:Reply to Robert,We already can do that: we've ported all of DMD's semantic, so everything DMD ('s frontend) knows, we also. :-) We just need a nice and clean way to show it in the UI... plus all the other, more important features, first.BCS wrote:that's what I was thinking of, you end up with template at some point. If nothing else you get: char[] CTFEfunc(T)(T t){...}The only clean way to do it still requiter that ctfeFunc be templated or you cant get to any of the semantic info.Sure you can. __traits, typeof(), is expressions... You can't pass around the types, though.sweet, will it also do mixin unfolding? this would be where you can expand a mixin in the editor to the text it expands to. This would however require the ability to pin template parameters and unfold/evaluate that as well. Whatever happens, it will be fun to see.Personably I'd rather not use mixins (my parser generator only uses them in two place to generate numbered labels and a goto) My feeling is that it's sort of going backwards in the abstraction domain. Also I'd rather get a lex/syntax error that points to hard text rather than mixin text. I find that a little CTFE, a little template functional programming and a pile of tuple foreaches can get a LOT done.Descent will soon (in Kramer time...) have the ability to mark errors at a location in a mixin... you still have to figure out where the problem is being created, but at least you can see exactly what the problem is.
Nov 19 2007