D - [HOWTO](MN002, part 3) Coding typesafe multi parameter functions, optional parameters and the like
- Manfred Nowak (109/109) Apr 02 2004 Part 3 of how to code multi parameter functions, optional parameters,
- C (24/137) Apr 02 2004 MW, can you post these somewhere ? I'm usually a fan of the NG , but =
- C (18/165) Apr 02 2004 the
- Ilya Minkov (13/36) Apr 02 2004 "That's very important," the King said, turning to the jury. They were
- C (19/56) Apr 02 2004 :).
- Ilya Minkov (8/15) Apr 02 2004 Then i think someone can simply add them to the Wiki4D. I think this
- John Reimer (6/17) Apr 02 2004 You mean you weren't quoting from memory?! Ah man, you've just destroyed...
- John Reimer (7/22) Apr 02 2004 He he.
- Ilya Minkov (11/19) Apr 02 2004 Whoops! I missed quotation marks!
- Manfred Nowak (9/10) Apr 02 2004 Readers of this newsgroup have requested examples for my suggested synta...
- John Reimer (5/20) Apr 02 2004 Manfred, I think he just thought the posting of these essays on the Wiki
- C (13/36) Apr 02 2004 Yes I like the HOW-TO's , its not off topic. I just thinking it would b...
- Ben Hinkle (11/20) Apr 02 2004 I've been reading your posts about this and I have a quick question:
- Manfred Nowak (12/19) Apr 02 2004 I do not understand completely what the current compiler does, because t...
- Manfred Nowak (8/11) Apr 05 2004 To have a more clear picture I added a "= 0" to the right of such a call
Part 3 of how to code multi parameter functions, optional parameters, positional parameters, default valued parameters and the like, using the the syntax extension I just suggested. With working example using the currently available syntax. In part 2 I introduced the general way to code a finite state machine (FSM) for accepting a regular expression (RE) over a signature alphabet. Now to the working examples. 3) Let us start with a simple FSM that does nothing but analyze the actual call whether it conforms to the regular expression as implemented by the FSM. Such FSM is called acceptor. Because I promised a working example with the current syntax and currently there is no opMultArg it must be faked. 3.a) The following code implements an acceptor for the signature S=int and the regular expression r=S*: <code> class List{ static: State0 opCall(int elem){ // fake opMultArg return state0( elem); } void opCall(){ // fake opMultArg } struct State0{ State0 opCall(int elem){ State0 next; return next; } void opCall(){ } } State0 state0; } /* Because I promised a working example with the current syntax and there is no semicolon allowed to separate signatures the semicolon must be faked with `)(', i.e. a right followed by a left parenthesis. */ void main(){ List list= new List; list(); list( 1); list( 1)( 2); list( 1)( 2)( 3); } </code> Play around with this. Replace the numbers with double, real, char etc. and watch the compiler rejecting your plays. From the code you may have noticed, that you are able to extend it, so that it does some preprocessing, by introducing for example some printf's into the bodies of the faked opMultArg's. You can also introduce printf's into the opCall's of state0, to print out the values of the actual parameters provided. But there is no way to post process the data received because there is no opEOM. The opEOM must be faked also, by appending a signature, that is not part of the signatures that are accepted regularly. Because the coder of the call might forget this appending, it must be checked for. Naturally this checking must be delayed until the next call of the multi parameter function and the appending of the faked opEOM to the very last call can be checked by the destructor of the class. For the empty list of actual parameters there is no need to append a fake opEOM, because the post processing can be done immediately. The last fact enables us to use the empty signature for signaling the end of the actual parameter list. 3.b) The following code implements a FSM that accepts lists of integers and prints out their values in octal notation separated by commas and surrounded by parentheses. <code> class List{ static: bit opEOMexpected= false; // for fake opEOM bit firstParameter; // for the special handling // of the first parameter State0 opCall(int elem){ // fake opMultArg assert( !opEOMexpected); // for fake opEOM opEOMexpected= true; //for fake opEOM printf("("); firstParameter= true; return state0( elem); } void opCall( ){ // fake opMultArg assert( !opEOMexpected); // for fake opEOM printf("()\n"); } struct State0{ State0 opCall(int elem){ if( firstParameter) printf("%X", elem); else printf(", %X", elem); firstParameter= false; State0 next; return next; } void opCall(){ // fake opEOM printf(")\n"); opEOMexpected= false; // for fake opEOM } } State0 state0; } void main(){ List list= new List; list(); list( 100)(); list( 100)( 200)(); list( 100)( 200)( 300)(); } </code> Again you might want to play around with this. To be continued. So long!
Apr 02 2004
MW, can you post these somewhere ? I'm usually a fan of the NG , but = reading howto-s off of it is not so fun. Wiki or Dsource ? Thanks ;), C On Fri, 02 Apr 2004 18:00:21 +0200, Manfred Nowak <svv1999 hotmail.com> = wrote:Part 3 of how to code multi parameter functions, optional parameters, positional parameters, default valued parameters and the like, using t=hethe syntax extension I just suggested. With working example using the currently available syntax. In part 2 I introduced the general way to code a finite state machine (FSM) for accepting a regular expression (RE) over a signature alphabe=t.Now to the working examples. 3) Let us start with a simple FSM that does nothing but analyze the =actual call whether it conforms to the regular expression as implemented by t=heFSM. Such FSM is called acceptor. Because I promised a working example with the current syntax and =currently there is no opMultArg it must be faked. 3.a) The following code implements an acceptor for the signature S=3Di=nt =and the regular expression r=3DS*: <code> class List{ static: State0 opCall(int elem){ // fake opMultArg return state0( elem); } void opCall(){ // fake opMultArg } struct State0{ State0 opCall(int elem){ State0 next; return next; } void opCall(){ } } State0 state0; } /* Because I promised a working example with the current syntax and there=isno semicolon allowed to separate signatures the semicolon must be fake=dwith `)(', i.e. a right followed by a left parenthesis. */ void main(){ List list=3D new List; list(); list( 1); list( 1)( 2); list( 1)( 2)( 3); } </code> Play around with this. Replace the numbers with double, real, char etc=.and watch the compiler rejecting your plays. From the code you may have noticed, that you are able to extend it, s=othat it does some preprocessing, by introducing for example some print=f'sinto the bodies of the faked opMultArg's. You can also introduce print=f'sinto the opCall's of state0, to print out the values of the actual parameters provided. But there is no way to post process the data =received because there is no opEOM. The opEOM must be faked also, by appending a signature, that is not pa=rtof the signatures that are accepted regularly. Because the coder of th=ecall might forget this appending, it must be checked for. Naturally th=ischecking must be delayed until the next call of the multi parameter function and the appending of the faked opEOM to the very last call ca=n =be checked by the destructor of the class. For the empty list of actual parameters there is no need to append a fake opEOM, because the post processing can be done immediately. The last fact enables us to use the empty signature for signaling the =endof the actual parameter list. 3.b) The following code implements a FSM that accepts lists of integer=sand prints out their values in octal notation separated by commas and surrounded by parentheses. <code> class List{ static: bit opEOMexpected=3D false; // for fake opEOM bit firstParameter; // for the special handling // of the first parameter State0 opCall(int elem){ // fake opMultArg assert( !opEOMexpected); // for fake opEOM opEOMexpected=3D true; //for fake opEOM printf("("); firstParameter=3D true; return state0( elem); } void opCall( ){ // fake opMultArg assert( !opEOMexpected); // for fake opEOM printf("()\n"); } struct State0{ State0 opCall(int elem){ if( firstParameter) printf("%X", elem); else printf(", %X", elem); firstParameter=3D false; State0 next; return next; } void opCall(){ // fake opEOM printf(")\n"); opEOMexpected=3D false; // for fake opEOM } } State0 state0; } void main(){ List list=3D new List; list(); list( 100)(); list( 100)( 200)(); list( 100)( 200)( 300)(); } </code> Again you might want to play around with this. To be continued. So long!-- = D Newsgroup.
Apr 02 2004
err, MN :) On Fri, 02 Apr 2004 11:25:58 -0800, C <dont respond.com> wrote:MW, can you post these somewhere ? I'm usually a fan of the NG , but =reading howto-s off of it is not so fun. Wiki or Dsource ? Thanks ;), C On Fri, 02 Apr 2004 18:00:21 +0200, Manfred Nowak <svv1999 hotmail.com= =wrote:Part 3 of how to code multi parameter functions, optional parameters,=thepositional parameters, default valued parameters and the like, using =the syntax extension I just suggested. With working example using the currently available syntax. In part 2 I introduced the general way to code a finite state machine=et.(FSM) for accepting a regular expression (RE) over a signature alphab=Now to the working examples. 3) Let us start with a simple FSM that does nothing but analyze the =theactual call whether it conforms to the regular expression as implemented by =FSM. Such FSM is called acceptor. Because I promised a working example with the current syntax and =int =currently there is no opMultArg it must be faked. 3.a) The following code implements an acceptor for the signature S=3D=e =and the regular expression r=3DS*: <code> class List{ static: State0 opCall(int elem){ // fake opMultArg return state0( elem); } void opCall(){ // fake opMultArg } struct State0{ State0 opCall(int elem){ State0 next; return next; } void opCall(){ } } State0 state0; } /* Because I promised a working example with the current syntax and ther=edis no semicolon allowed to separate signatures the semicolon must be fak=c.with `)(', i.e. a right followed by a left parenthesis. */ void main(){ List list=3D new List; list(); list( 1); list( 1)( 2); list( 1)( 2)( 3); } </code> Play around with this. Replace the numbers with double, real, char et=soand watch the compiler rejecting your plays. From the code you may have noticed, that you are able to extend it, =that it does some preprocessing, by introducing for example some =printf's into the bodies of the faked opMultArg's. You can also introduce =printf's into the opCall's of state0, to print out the values of the actual parameters provided. But there is no way to post process the data =artreceived because there is no opEOM. The opEOM must be faked also, by appending a signature, that is not p=heof the signatures that are accepted regularly. Because the coder of t=hiscall might forget this appending, it must be checked for. Naturally t=an =checking must be delayed until the next call of the multi parameter function and the appending of the faked opEOM to the very last call c=be checked by the destructor of the class. For the empty list of actual parameters there is no need to append a fake opEOM, because the post==processing can be done immediately. The last fact enables us to use the empty signature for signaling the=rsend of the actual parameter list. 3.b) The following code implements a FSM that accepts lists of intege=and prints out their values in octal notation separated by commas and=-- = D Newsgroup.surrounded by parentheses. <code> class List{ static: bit opEOMexpected=3D false; // for fake opEOM bit firstParameter; // for the special handling // of the first parameter State0 opCall(int elem){ // fake opMultArg assert( !opEOMexpected); // for fake opEOM opEOMexpected=3D true; //for fake opEOM printf("("); firstParameter=3D true; return state0( elem); } void opCall( ){ // fake opMultArg assert( !opEOMexpected); // for fake opEOM printf("()\n"); } struct State0{ State0 opCall(int elem){ if( firstParameter) printf("%X", elem); else printf(", %X", elem); firstParameter=3D false; State0 next; return next; } void opCall(){ // fake opEOM printf(")\n"); opEOMexpected=3D false; // for fake opEOM } } State0 state0; } void main(){ List list=3D new List; list(); list( 100)(); list( 100)( 200)(); list( 100)( 200)( 300)(); } </code> Again you might want to play around with this. To be continued. So long!
Apr 02 2004
"That's very important," the King said, turning to the jury. They were just beginning to write this down on their slates, when the White Rabbit interrupted: "Unimportant, your Majesty means, of course," he said, in a very respectful tone, but frowning and making faces at him as he spoke. "Unimportant, of course, I meant," the King hastily said, and went on to himself in an under-tone, "important--unimportant--unimportant--important----" as if he were trying which word sounded best. Some of the jury wrote it down "important," and some "unimportant." Alice could see this, as she was near enough to look over their slates; "but it doesn't matter a bit," she thought to herself. -eye Manfred Nowak schrieb:C wrote:err, MN :)Exchanging a single letter does not matter. Shortening a name to its initials does matter, even when one does it with its own name. Hiding behind an invalid email address does matter. Providing public critique without obvious interest to the public does matter. Exposing oneself as a net cop in a NG that welcomes even flame wars does matter. So long! P.S.: Please introduce me to your kill file.
Apr 02 2004
:). Theres a misunderstanding, I like the howto's, and I dont care that you = post to the newsgroup. Im asking in addition to the posting to the = newsgroup, why don't you put them on the web so its easier to read , and= = people can find it that aren't in the newsgroup. So Long! P.S. I only used MN because its in the subject of these HOWTO's On Fri, 02 Apr 2004 21:20:16 +0200, Ilya Minkov <minkov cs.tum.edu> wrot= e:"That's very important," the King said, turning to the jury. They were==just beginning to write this down on their slates, when the White Rabb=it =interrupted: "Unimportant, your Majesty means, of course," he said, in=a =very respectful tone, but frowning and making faces at him as he spoke=."Unimportant, of course, I meant," the King hastily said, and went on =to =himself in an under-tone, ="important--unimportant--unimportant--important----" as if he were =trying which word sounded best. Some of the jury wrote it down "important," and some "unimportant." =Alice could see this, as she was near enough to look over their slates=; ="but it doesn't matter a bit," she thought to herself. -eye Manfred Nowak schrieb:C wrote:err, MN :)Exchanging a single letter does not matter. Shortening a name to its initials does matter, even when one does it =with its own name. Hiding behind an invalid email address does matter. Providing public critique without obvious interest to the public does=oesmatter. Exposing oneself as a net cop in a NG that welcomes even flame wars d=-- = D Newsgroup.matter. So long! P.S.: Please introduce me to your kill file.
Apr 02 2004
C schrieb::).Nice i could do something good to this discussion which leads nowhere.Theres a misunderstanding, I like the howto's, and I dont care that you post to the newsgroup. Im asking in addition to the posting to the newsgroup, why don't you put them on the web so its easier to read , and people can find it that aren't in the newsgroup.Then i think someone can simply add them to the Wiki4D. I think this need not be the Author, because the license for usage of this newsgroup includes, IIRC, that posted material can be used to promote D. I would do it myself if i wasn't that busy picking up a good quote. ;)So Long! P.S. I only used MN because its in the subject of these HOWTO'sI figured that out. Seems that Manfred has not. -eye
Apr 02 2004
<snip>Then i think someone can simply add them to the Wiki4D. I think this need not be the Author, because the license for usage of this newsgroup includes, IIRC, that posted material can be used to promote D. I would do it myself if i wasn't that busy picking up a good quote. ;)You mean you weren't quoting from memory?! Ah man, you've just destroyed my admiration for you. ;-)Well I must admit, it is a little odd to refer to a person by their initials in direct address (especially when their name is known). But this newsgroup is an odd place, so it's "unimportant." :-)So Long! P.S. I only used MN because its in the subject of these HOWTO'sI figured that out. Seems that Manfred has not. -eye
Apr 02 2004
Ilya Minkov wrote:"That's very important," the King said, turning to the jury. They were just beginning to write this down on their slates, when the White Rabbit interrupted: "Unimportant, your Majesty means, of course," he said, in a very respectful tone, but frowning and making faces at him as he spoke. "Unimportant, of course, I meant," the King hastily said, and went on to himself in an under-tone, "important--unimportant--unimportant--important----" as if he were trying which word sounded best. Some of the jury wrote it down "important," and some "unimportant." Alice could see this, as she was near enough to look over their slates; "but it doesn't matter a bit," she thought to herself. -eyeHe he. I remember my mother thinking there was absolutely something messed up in the mind of Lewis Carroll, but for some reason I always loved these books. As crazy as they were, they always seemed full of good wholsome satire. Though posting this here may just be unnecessarily adding fuel to the fire...
Apr 02 2004
John Reimer schrieb:He he. I remember my mother thinking there was absolutely something messed up in the mind of Lewis Carroll, but for some reason I always loved these books. As crazy as they were, they always seemed full of good wholsome satire. Though posting this here may just be unnecessarily adding fuel to the fire...Whoops! I missed quotation marks! We can settle it easily. --- 8< --- At this moment the King, who had been for some time busily writing in his note-book, cackled out "Silence!" and read out from his book, "Rule Forty-two. ALL PERSONS MORE THAN A MILE HIGH TO LEAVE THE COURT." --- >8 --- which also means that everyone below that height has no reason to feel bad. ;) -eye
Apr 02 2004
C wrote: [...]reading howto-s off of it is not so funReaders of this newsgroup have requested examples for my suggested syntax extension. After giving some theoretical or general introduction I am suplying these examples, with exactly this posting. Would you please explain, why it can be off topic to provide examples for the use of suggested syntax extensions? So long!
Apr 02 2004
Manfred Nowak wrote:C wrote: [...]Manfred, I think he just thought the posting of these essays on the Wiki would make it easier for people to read (nicer formatting and all). But, I have to admit, given the intent of your essays, they are probably more appropriate to post here for now as you said.reading howto-s off of it is not so funReaders of this newsgroup have requested examples for my suggested syntax extension. After giving some theoretical or general introduction I am suplying these examples, with exactly this posting. Would you please explain, why it can be off topic to provide examples for the use of suggested syntax extensions? So long!
Apr 02 2004
Yes I like the HOW-TO's , its not off topic. I just thinking it would b= e = easier to read ( and would have a permanent place to reference them ) if= = you put them on the web somewhere. C On Fri, 02 Apr 2004 10:35:52 -0800, John Reimer <jjreimer telus.net> wro= te:Manfred Nowak wrote:C wrote: [...]reading howto-s off of it is not so funReaders of this newsgroup have requested examples for my suggested =syntax extension. After giving some theoretical or general introduction I am suplying ==these examples, with exactly this posting. Would you please explain, why it can be off topic to provide examples=kifor the use of suggested syntax extensions? So long!Manfred, I think he just thought the posting of these essays on the Wi=would make it easier for people to read (nicer formatting and all). But, I have to admit, given the intent of your essays, they are probab=lymore appropriate to post here for now as you said.-- = D Newsgroup.
Apr 02 2004
"Manfred Nowak" <svv1999 hotmail.com> wrote in message news:c4kb49$1uu6$1 digitaldaemon.com...C wrote: [...]I've been reading your posts about this and I have a quick question: if foo is declared with the ";" in the parameter list how many times is foo called when you use ";" at the call site? I had assumed foo was called once but the example you gave using opCall made me think it gets called again each time the user supplies a ";". If that is true then why not just use opCall? Is it to be able to write foo(1;2;3) instead of foo(1)(2)(3)reading howto-s off of it is not so funReaders of this newsgroup have requested examples for my suggested syntax extension. After giving some theoretical or general introduction I am suplying these examples, with exactly this posting.Would you please explain, why it can be off topic to provide examples for the use of suggested syntax extensions?I think the "off" referred to reading "off the newsgroup" and not "off-topic".
Apr 02 2004
Ben Hinkle wrote: [...]if foo is declared with the ";" in the parameter list how many times is foo called when you use ";" at the call site?I do not understand completely what the current compiler does, because the code returns a struct inside of foo, and not the representation of foo.I had assumed foo was called once but the example you gave using opCall made me think it gets called again each time the user supplies a ";".Clearly the actual call of the according opCall is prepared when the compiler analyzes the actual signature list and finds a ";".If that is true then why not just use opCall? Is it to be able to write foo(1;2;3) instead of foo(1)(2)(3)The ";" is nearly only syntax sugar. But in addition it enables the compiler to emit a request for opEOM, when it reaches the closing right parenthesis. With foo()()() there is no such implicit possibility and therefore an additional token must be appended to signal the end of the actual signature list. So long!
Apr 02 2004
Ben Hinkle wrote: [...]I had assumed foo was called once but the example you gave using opCall made me think it gets called again each time the user supplies a ";".To have a more clear picture I added a "= 0" to the right of such a call and the compiler spit out: 'list.opCall(1).opCall(2).opCall(3)' is not an lvalue Now it is quite obvious, that the compiler prepares only one call to `foo' aka `list'. So long!
Apr 05 2004