Jump to page: 1 24  
Page
Thread overview
void returns
May 22, 2004
Benedikt Meurer
May 22, 2004
J C Calvarese
May 22, 2004
Andy Friesen
May 22, 2004
J C Calvarese
May 22, 2004
Matthew
May 22, 2004
davepermen
May 22, 2004
Matthew
May 22, 2004
Kris
May 23, 2004
Matthew
May 23, 2004
Walter
May 23, 2004
Matthew
May 23, 2004
Walter
May 23, 2004
Matthew
May 23, 2004
Hwa Hwa
May 27, 2004
Kevin Bealer
May 27, 2004
Matthew
May 28, 2004
Kevin Bealer
May 28, 2004
Arcane Jill
May 22, 2004
James McComb
May 23, 2004
Juan C
May 23, 2004
davepermen
May 23, 2004
Walter
May 23, 2004
Benedikt Meurer
May 23, 2004
Walter
May 24, 2004
Arcane Jill
May 24, 2004
Sean Kelly
May 23, 2004
Norbert Nemec
May 23, 2004
Bent Rasmussen
May 23, 2004
Norbert Nemec
May 24, 2004
James McComb
May 24, 2004
Norbert Nemec
May 24, 2004
Matthew
May 24, 2004
Ivan Senji
May 25, 2004
Kevin Bealer
May 26, 2004
Norbert Nemec
May 26, 2004
Arcane Jill
May 26, 2004
Juan C
May 26, 2004
Regan Heath
May 27, 2004
Derek Parnell
May 27, 2004
Antti Sykäri
May 22, 2004
Hello,

Would it be possible to add support for void returns, as in

void f1 () { ... }
void f2 () { ...; return f1 (); }

to D? This would be invaluably helpful in template programming. Else one has to either make heavy use of mixins or write a lot of specialisations.

(Looking at the code, it seems, that only dmd/statement.c has to be modified to archive this goal).

regards,
Benedikt

--
NetBSD Operating system:                       http://www.NetBSD.org/
pkgsrc "Work in progress":                  http://pkgsrc-wip.sf.net/
XFce desktop environment:                        http://www.xfce.org/
German Unix-AG Association:                   http://www.unix-ag.org/
os-network:                                 http://www.os-network.de/

OpenPGP Key: http://www.home.unix-ag.org/bmeurer/#gpg
May 22, 2004
Benedikt Meurer wrote:
> Hello,
> 
> Would it be possible to add support for void returns, as in
> 
> void f1 () { ... }
> void f2 () { ...; return f1 (); }
> 
> to D? This would be invaluably helpful in template programming. Else one has to either make heavy use of mixins or write a lot of specialisations.
> 
> (Looking at the code, it seems, that only dmd/statement.c has to be modified to archive this goal).
> 
> regards,
> Benedikt

In D, void means the function doesn't return a value. But that doesn't prevent you from calling another function. I'm not sure I understand what your goal is. You can already do this:

void f1()
{
    printf("Running f1...\n");
}

void f2()
{
    bit itsAGoodIdea = true;
    printf("Running f2...\n");
    if(itsAGoodIdea)
    {
        f1();
        return;
    }
    printf("Don't go there.\n");
}

void main()
{
    f2();
    printf("The end.\n");
}

/*
Output:

Running f2...
Running f1...
The end.
*/


> 
> -- 
> NetBSD Operating system:                       http://www.NetBSD.org/
> pkgsrc "Work in progress":                  http://pkgsrc-wip.sf.net/
> XFce desktop environment:                        http://www.xfce.org/
> German Unix-AG Association:                   http://www.unix-ag.org/
> os-network:                                 http://www.os-network.de/
> 
> OpenPGP Key: http://www.home.unix-ag.org/bmeurer/#gpg


-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
May 22, 2004
J C Calvarese wrote:
> In D, void means the function doesn't return a value. But that doesn't prevent you from calling another function. I'm not sure I understand what your goal is. 

Right.  He's referring to syntactically allowing 'void' to be returned.

void f1() { }
void f2() { return f1(); }

f1 has no return value, and neither does f2, so it... sort of, makes sense.  The big reason to allow it is because the return type may be parameterized:

template t(T) {
   T f1() { ... }
   T f2() { return f1(); }
}

If void can be returned, T can be void, in this example.

 -- andy
May 22, 2004
Andy Friesen wrote:
> J C Calvarese wrote:
> 
>> In D, void means the function doesn't return a value. But that doesn't prevent you from calling another function. I'm not sure I understand what your goal is. 
> 
> 
> Right.  He's referring to syntactically allowing 'void' to be returned.
> 
> void f1() { }
> void f2() { return f1(); }
> 
> f1 has no return value, and neither does f2, so it... sort of, makes sense.  The big reason to allow it is because the return type may be parameterized:
> 
> template t(T) {
>    T f1() { ... }
>    T f2() { return f1(); }
> }
> 
> If void can be returned, T can be void, in this example.
> 
>  -- andy

Oops. Somehow I missed his reference to templates (perhaps my eyes started to glaze after after I saw his example). Sounds like a good idea since it'd help templatization.

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
May 22, 2004
Ah, something I've always wanted in C++...

I echo the request.

"Benedikt Meurer" <benedikt.meurer@unix-ag.uni-siegen.de> wrote in message news:c8o52s$1j0l$1@digitaldaemon.com...
> Hello,
>
> Would it be possible to add support for void returns, as in
>
> void f1 () { ... }
> void f2 () { ...; return f1 (); }
>
> to D? This would be invaluably helpful in template programming. Else one has to either make heavy use of mixins or write a lot of specialisations.
>
> (Looking at the code, it seems, that only dmd/statement.c has to be modified
> to archive this goal).
>
> regards,
> Benedikt
>
> --
> NetBSD Operating system:                       http://www.NetBSD.org/ pkgsrc "Work in progress":                  http://pkgsrc-wip.sf.net/ XFce desktop environment:                        http://www.xfce.org/ German Unix-AG Association:                   http://www.unix-ag.org/ os-network:                                 http://www.os-network.de/
>
> OpenPGP Key: http://www.home.unix-ag.org/bmeurer/#gpg


May 22, 2004
works in c++...

should be working in D, too, indeed.

"Matthew" <matthew.hat@stlsoft.dot.org> schrieb im Newsbeitrag news:c8okjt$28o9$1@digitaldaemon.com...
> Ah, something I've always wanted in C++...
>
> I echo the request.
>
> "Benedikt Meurer" <benedikt.meurer@unix-ag.uni-siegen.de> wrote in message news:c8o52s$1j0l$1@digitaldaemon.com...
> > Hello,
> >
> > Would it be possible to add support for void returns, as in
> >
> > void f1 () { ... }
> > void f2 () { ...; return f1 (); }
> >
> > to D? This would be invaluably helpful in template programming. Else one
has
> > to either make heavy use of mixins or write a lot of specialisations.
> >
> > (Looking at the code, it seems, that only dmd/statement.c has to be
modified
> > to archive this goal).
> >
> > regards,
> > Benedikt
> >
> > --
> > NetBSD Operating system:                       http://www.NetBSD.org/ pkgsrc "Work in progress":                  http://pkgsrc-wip.sf.net/ XFce desktop environment:                        http://www.xfce.org/ German Unix-AG Association:                   http://www.unix-ag.org/ os-network:                                 http://www.os-network.de/
> >
> > OpenPGP Key: http://www.home.unix-ag.org/bmeurer/#gpg
>
>


May 22, 2004
Yes, but it's a relatively late addition, and several recent or still in use compilers don't support it, which makes its use a portability problem.

Here's another one to consider. In C++ I've had occasion to require a
sizeof(void), and had to resort to traits in order to get it. Does anyone see a
downside with sizeof(void) being legal in D?

"davepermen" <davepermen@hotmail.com> wrote in message news:c8ol00$29c3$1@digitaldaemon.com...
> works in c++...
>
> should be working in D, too, indeed.
>
> "Matthew" <matthew.hat@stlsoft.dot.org> schrieb im Newsbeitrag news:c8okjt$28o9$1@digitaldaemon.com...
> > Ah, something I've always wanted in C++...
> >
> > I echo the request.
> >
> > "Benedikt Meurer" <benedikt.meurer@unix-ag.uni-siegen.de> wrote in message news:c8o52s$1j0l$1@digitaldaemon.com...
> > > Hello,
> > >
> > > Would it be possible to add support for void returns, as in
> > >
> > > void f1 () { ... }
> > > void f2 () { ...; return f1 (); }
> > >
> > > to D? This would be invaluably helpful in template programming. Else one
> has
> > > to either make heavy use of mixins or write a lot of specialisations.
> > >
> > > (Looking at the code, it seems, that only dmd/statement.c has to be
> modified
> > > to archive this goal).
> > >
> > > regards,
> > > Benedikt
> > >
> > > --
> > > NetBSD Operating system:                       http://www.NetBSD.org/ pkgsrc "Work in progress":                  http://pkgsrc-wip.sf.net/ XFce desktop environment:                        http://www.xfce.org/ German Unix-AG Association:                   http://www.unix-ag.org/ os-network:                                 http://www.os-network.de/
> > >
> > > OpenPGP Key: http://www.home.unix-ag.org/bmeurer/#gpg
> >
> >
>
>


May 22, 2004
I suppose sizeof(void) would need to reflect the size of void[] elements,
which are 1 byte each ...

"Matthew" <matthew.hat@stlsoft.dot.org>
> Here's another one to consider. In C++ I've had occasion to require a sizeof(void), and had to resort to traits in order to get it. Does anyone
see a
> downside with sizeof(void) being legal in D?


May 22, 2004
Benedikt Meurer wrote:
> Hello,
> 
> Would it be possible to add support for void returns, as in
> 
> void f1 () { ... }
> void f2 () { ...; return f1 (); }

According to Bertrand Meyer, creator of Eiffel, there are two kinds of routines:
   Commands (i.e. functions that return void), and
   Queries (i.e. functions that return non-void).

According to Meyer, Commands should be used to change state, and Queries should be used only to query that state.

What is the point of this distinction? For a variety of reasons, the most important being exception-safety, Queries should not have side-effects (roughly, they should not change state). This is why pop() doesn't return a value in the STL stack. pop() is the Command, and top() is the Query.

If functions that return void and functions that return non-void should be used for fundamentally different purposes, when would it be a good idea to have function template parameterized to sometimes return void and sometimes return non-void?

James McComb
May 23, 2004
<snip>
>According to Meyer, Commands should be used to change state, and Queries should be used only to query that state.
</snip>

Well then I submit that a knife is to cut food, and a fork is to pick up food (with a spoon being a specialized type of fork?). So one should not use a fork to cut pancakes.


« First   ‹ Prev
1 2 3 4