Jump to page: 1 2
Thread overview
[HOWTO](MN002, part 3) Coding typesafe multi parameter functions, optional parameters and the like
Apr 02, 2004
Manfred Nowak
Apr 02, 2004
C
Apr 02, 2004
C
Apr 02, 2004
Ilya Minkov
Apr 02, 2004
C
Apr 02, 2004
Ilya Minkov
Apr 02, 2004
John Reimer
Apr 02, 2004
John Reimer
Apr 02, 2004
Ilya Minkov
Apr 02, 2004
Manfred Nowak
Apr 02, 2004
John Reimer
Apr 02, 2004
C
Apr 02, 2004
Ben Hinkle
Apr 02, 2004
Manfred Nowak
Apr 05, 2004
Manfred Nowak
April 02, 2004
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!
April 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 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!



-- 
D Newsgroup.
April 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,
>> 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!
>
>
>



-- 
D Newsgroup.
April 02, 2004
C wrote:

[...]
> reading howto-s off of it is not so fun

Readers 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!
April 02, 2004
Manfred Nowak wrote:

> C wrote:
> 
> [...]
>> reading howto-s off of it is not so fun
> 
> Readers 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!

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.
April 02, 2004
"Manfred Nowak" <svv1999@hotmail.com> wrote in message news:c4kb49$1uu6$1@digitaldaemon.com...
> C wrote:
>
> [...]
> > reading howto-s off of it is not so fun
>
> Readers 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.

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)

> 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".


April 02, 2004
Yes I like the HOW-TO's , its not off topic.  I just thinking it would be 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> wrote:

> Manfred Nowak wrote:
>
>> C wrote:
>>
>> [...]
>>> reading howto-s off of it is not so fun
>>
>> Readers 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!
>
> 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.



-- 
D Newsgroup.
April 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!
April 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.  
April 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> 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.
>
> -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.



-- 
D Newsgroup.
« First   ‹ Prev
1 2