473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C doubts

1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto

2)what exactly is the purpose of tmpfile() ? will it open a temporary
file ?

3)why there is no article on dangling pointer in the FAQ ?
Nov 15 '07 #1
28 1640
In article
<59**********************************@e10g2000prf. googlegroups.com>,
so**********@gmail.com <so**********@gmail.comwrote on Thursday 15
Nov 2007 11:52 pm:
1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto
If there is such a program it's likely to be contrived. Most real world
programs can avoid goto if necessary, though most make *some* use of
it.
2)what exactly is the purpose of tmpfile() ? will it open a temporary
file ?
Yes. It returns a pointer to a stream which will be valid until it is
closed via fclose() or by normal program termination.
3)why there is no article on dangling pointer in the FAQ ?
See question 7.1

Nov 15 '07 #2
On Nov 15, 1:38 pm, santosh <santosh....@gmail.comwrote:
In article
<59873ca2-b9a9-4e2a-87a9-4d0cc4844...@e10g2000prf.googlegroups.com>,
sophia.ag...@gmail.com <sophia.ag...@gmail.comwrote on Thursday 15
Nov 2007 11:52 pm:
1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto

If there is such a program it's likely to be contrived. Most real world
programs can avoid goto if necessary, though most make *some* use of
it.
2)what exactly is the purpose of tmpfile() ? will it open a temporary
file ?

Yes. It returns a pointer to a stream which will be valid until it is
closed via fclose() or by normal program termination.
3)why there is no article on dangling pointer in the FAQ ?

See question 7.1
Question 7.1 points to this link:-
http://c-faq.com/malloc/malloc1.html
is n't it?

but it does n't say any thing about dangling pointer
Nov 15 '07 #3
jacob navia wrote, On 15/11/07 19:07:
so**********@gmail.com wrote:
>1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto

This code snippet demonstrates that:

switch (integer) {
case 534:
switch (n) {
case 254:
goto goon;
case 566:
//
break;
}
printf("Sub-item for 534 not found");
break;
}
return 0;
goon:
return 6445;
}

Obviously that *could* be rearranged
Very easily, so it is not an example that demonstrates your point.
but the point is that the language
does not provide a "named" break statement. If you want to break from
nested switches, nested loops, or nested constructs like that you have
to use the goto statement
Or a flag, or sometimes you can do it by using another layer of function
and a return, or...

I believe that C would still be Turing complete without goto, i.e. there
are no programs for which goto is required. However, that does not mean
it is advisable to avoid using goto just for the sake of avoiding using
goto.

<snip>
--
Flash Gordon
Nov 15 '07 #4
On Thu, 15 Nov 2007 10:22:04 -0800 (PST), so**********@gmail.com
wrote:
>1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto
No, yes, no, and yes. The answer is no because every program
that contains gotos can be rewritten using only structured
constructs. The answer is yes because such rewrites are not
equivalent to the original program in terms of execution time and
program space. The answer is no because such programs cannot be
effectively written by human beings. The answer is yes because
such programs can be generated by other programs.
>
2)what exactly is the purpose of tmpfile() ? will it open a temporary
file ?

3)why there is no article on dangling pointer in the FAQ ?
Richard Harter, cr*@tiac.net
http://home.tiac.net/~cri, http://www.varinoma.com
In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die
Nov 15 '07 #5

sophia.ag...@gmail.com wrote:
1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto
void compact()
{
if (f())
goto F;
if (g())
goto G;
doX();
return; /* this can be omitted, the goto is still needed */

F: doY();
G: doZ();
}

/* same without goto */
void bloat()
{
if (f()) {
doY();
doZ();
return;
}
if (g()) {
doZ();
return;
}
doX();
}

without goto you either repeat some code (doZ() in this example) which
can be painful if you have many local variables, many nested loops
etc, or double check one of the return values (f(), g())

this situation typically occures with resource allocations:

void resources() {
resource_t r1, r2;

r1 = alloc_res1();
if (!r1)
goto fail1;
r2 = alloc_res2();
if (!r2)
goto fail2;
use(r1, r2);
/* return 1; */ /* depends on the situation */

release_res2(r2);
fail2: release_res1(r1);
fail1:
/* return 0; */
}
another favourite example:

void loop()
{
while(f())
if (g())
goto G;
x();
G:
y();
}

same situation as above
goto can be avoided if while had an else clause for the case when the
loop condition fails

/* not c code */
void loop()
{
while(f()) {
if (g())
break;
} else { /* not c */
x();
}
y();
}

with any other solution you either repeat code or double check one of
the conditions.

(of course double checking a condition is not too much waste of time,
also in certain situations the compiler can be clever and do the
optimizations for you)
Nov 15 '07 #6
so**********@gmail.com wrote On 11/15/07 13:22,:
1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto
It depends on what you mean by "a C program."

In a formal sense, it's easy to see that goto can always
be eliminated. (Somebody or other proved this in a paper
that always gets cited, but it always seemed to me that they
had proved the sky was blue. But then, I haven't read the
paper.)

However, the source code changes to eliminate goto might
make a particular program larger than it had been, and it
might become too big for the compiler to compile or for the
host computer to execute. So it is at least conceivable that
there exists at least one (very large) program which would
cease to function if the goto's were eliminated. Constructing
such a program would probably require a very large effort.
2)what exactly is the purpose of tmpfile() ? will it open a temporary
file ?
It creates and opens a temporary file. "Temporary"
means that the file will be deleted from the permanent file
storage when the program ends, even if the program doesn't
call remove() on it. It can be useful when a program must
process large amounts of data in multiple "passes," where
one pass writes to the temporary file and others read it
back in again.
3)why there is no article on dangling pointer in the FAQ ?
Maybe the questions about dangling pointers aren't FA.

--
Er*********@sun.com
Nov 15 '07 #7
Szabolcs Nagy wrote On 11/15/07 17:20,:
sophia.ag...@gmail.com wrote:
>>1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto


void compact()
{
if (f())
goto F;
if (g())
goto G;
doX();
return; /* this can be omitted, the goto is still needed */

F: doY();
G: doZ();
}
void compact(void) {
int quo = 17;
while (quo != 42) {
switch (quo) {
case 44:
doY();
quo = 666;
break;
case 43:
doX();
quo+=-1;
break;
case 17:
quo = f() ? 44 : 31;
break;
case 51;
doZ();
quo -= 9;
break;
case 31:
quo += g() ? 20 : 12;
break;
}
}
}

Structured control flow at its very best.

--
Er*********@sun.com
Nov 15 '07 #8
Walter Roberson wrote:
>
In article <59**********************************@e10g2000prf. googlegroups.com>,
<so**********@gmail.comwrote:
1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto

I'm not sure, but possibly the following:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void) {
srand( (unsigned int) time(0) );
if (rand() < 1234)
goto FOO;
{ const unsigned char bar = 17;
FOO: printf("%d\n", (int) bar);
}
return 0;
}

This -relies- upon bar having an indeterminate value at the time
of the printf. The value will not be a trapping value because
unsigned char never has trapping values. The usual method of
rewriting this to avoid the goto would be to have something like
[...]

Would this code do the same thing?

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void) {
srand( (unsigned int) time(0) );
switch ( rand() < 1234 )
{
case 0:
{
const unsigned char bar = 17;
case 1:
printf("%d\n",bar);
}
}
return 0;
}

Those nasty inner braces can be gotten rid of if your compiler
supports variables declared within the code.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Nov 15 '07 #9
In article <fh**********@registered.motzarella.orgsantosh <sa*********@gmail.comwrites:
In article
<59**********************************@e10g2000prf. googlegroups.com>,
so**********@gmail.com <so**********@gmail.comwrote on Thursday 15
Nov 2007 11:52 pm:
1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto

If there is such a program it's likely to be contrived. Most real world
programs can avoid goto if necessary, though most make *some* use of
it.
I do not know whether it applies, but back in the days of Algol 60 there
hase been a discussion between van Wijgaarden and somebody else about the
possibility to rewrite every program into a gotoless program. At that
time van Wijngaarden came up to transform a program with goto's into a
program without goto's. (Strange enough the process first eliminated
every function call into something containing a lot of goto's. And after
that it changed goto's into function calls...) It worked for Algol 60,
I would now know why it should not also work for C, there are a lot of
similarities, the only main major block might be the lack of nested
functions in C. But off-hand I would state that every program using
goto's can be rewritten into a goto-less program.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 16 '07 #10
Szabolcs Nagy wrote:
sophia.ag...@gmail.com wrote:
1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto

void compact()
{
if (f())
goto F;
if (g())
goto G;
doX();
return; /* this can be omitted, the goto is still needed */

F: doY();
G: doZ();
}

/* same without goto */
void bloat()
{
if (f()) {
doY();
doZ();
return;
}
if (g()) {
doZ();
return;
}
doX();
}
You yourself have just demonstrated that it doesn't need 'goto'. She
didn't ask for examples where 'goto' was convenient, she asked for
examples where use of 'goto' cannot be avoided.
Nov 16 '07 #11
On Thu, 15 Nov 2007 23:58:39 GMT, "Dik T. Winter" <Di********@cwi.nl>
wrote:
>In article <fh**********@registered.motzarella.orgsantosh <sa*********@gmail.comwrites:
In article
<59**********************************@e10g2000prf. googlegroups.com>,
so**********@gmail.com <so**********@gmail.comwrote on Thursday 15
Nov 2007 11:52 pm:
1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto
If there is such a program it's likely to be contrived. Most real world
programs can avoid goto if necessary, though most make *some* use of
it.

I do not know whether it applies, but back in the days of Algol 60 there
hase been a discussion between van Wijgaarden and somebody else about the
possibility to rewrite every program into a gotoless program.
Look up Boehm - Jacopini.

IBM had a published algorithm for converting arbitrary programs into
structured (goto-less) programs.
At that
time van Wijngaarden came up to transform a program with goto's into a
program without goto's. (Strange enough the process first eliminated
every function call into something containing a lot of goto's. And after
that it changed goto's into function calls...) It worked for Algol 60,
I would now know why it should not also work for C, there are a lot of
similarities, the only main major block might be the lack of nested
functions in C. But off-hand I would state that every program using
goto's can be rewritten into a goto-less program.
--
Al Balmer
Sun City, AZ
Nov 16 '07 #12
Szabolcs Nagy said:

<snip>
so in these examples 'goto' _cannot_ be avoided
This doesn't follow. All it shows is that you have not avoided goto in
these examples.

The goto keyword is always avoidable. In practical terms, the time to avoid
it is at the specification stage. When you're deciding what the program
must do, you don't think in terms of goto, but in terms of modules.
Properly carried out, functional decomposition will allow you to design a
gotoless solution if that's what you want. So *first* decide what you want
to do, and write it down not in C but in English. Then you should easily
be able to design a solution that doesn't use goto.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 16 '07 #13
so**********@gmail.com wrote:
1)can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the keyword
goto
Dik and Al have mentioned a paper showing how to de-goto a program;
I'd just like to add what I found an illuminating tactic in understanding
the possibilities of goto-removal.

You can /clearly/ rewrite a [non-threaded] program into a single loop,
containing a single switch, using a single switch index variable; each
case of the switch does some work and then updates the index to refer
to the next case to execute.

We do this rewriting all the time: it's called "compilation", and the
loop-and-switch is encoded in your processor.

This shows [informally] that (a) you can always de-goto a [threadless]
program, (b) that a formal proof, while satisfying, may not really be
saying very much, and (c) just because some code is "structured" in
terms of while/if-switch/sequence doesn't mean its /good/.

--
Chris "IMAO" Dollin

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Nov 16 '07 #14
In article <fh**********@tadcaster.hpl.hp.com>,
Chris Dollin <ch**********@hp.comwrote:
>Dik and Al have mentioned a paper showing how to de-goto a program;
I'd just like to add what I found an illuminating tactic in understanding
the possibilities of goto-removal.

You can /clearly/ rewrite a [non-threaded] program into a single loop,
containing a single switch, using a single switch index variable; each
case of the switch does some work and then updates the index to refer
to the next case to execute.

We do this rewriting all the time: it's called "compilation", and the
loop-and-switch is encoded in your processor.
Alternatively, ask a nearby functional programmer to explain
continuation-passing style. (This is especially good if you're the
sort of person who likes having your brain explode.)

Having sort of wrapped my head around how that works is even turning
out to be useful for C programming of a less pathological sort than
removing gotos[1], since the GUI toolkit I'm trying to figure out how
to use[2] doesn't appear to support modal loops, so I'm having to write
operations requiring user interaction as chained callbacks in CPS
form: Set up a widget, attach a callback for the next step in the
process, go back to the main event loop and let the widget I just set
up invoke the callback when the user has reacted appropriately. (Or,
at least, that's the first way I came up with to make it work. There
may very well be an obvious and easy way to do what I'm trying to
accomplish that requires a little bit less of a bent mind to understand
it.)
dave

[1] Though I've heard rumours that there are people who would not
exactly describe Xt as "less pathological" than anything this side
of INTERCAL.
[2] ObC: It's implemented as a C API. Actually, it could be
(and, if I'm not mistaken, is or is mostly) implemented entirely in
C-plus-calls-to-a-lower-level-API-also-with-C-bindings, and the
nonportable bits of the whole thing end up being reducible to
not much more than pushing data through a socket.

Nov 17 '07 #15
so**********@gmail.com wrote:
>
1) can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the
keyword goto
It has been shown (long ago) that any goto implemented program can
be implemented with only if and while.
>
2) what exactly is the purpose of tmpfile() ? will it open a
temporary file ?

3) why there is no article on dangling pointer in the FAQ ?
I have no idea what you are talking about here. Please reference
the place in the C standard that defines these things.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 17 '07 #16
jacob navia wrote:
so**********@gmail.com wrote:
>1) can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the
keyword goto

This code snippet demonstrates that:

switch (integer) {
case 534:
switch (n) {
case 254:
goto goon;
case 566:
//
break;
}
printf("Sub-item for 534 not found");
break;
}
return 0;
goon:
return 6445;
}

Obviously that *could* be rearranged but the point is that the
language does not provide a "named" break statement. If you want
to break from nested switches, nested loops, or nested constructs
like that you have to use the goto statement
Nonsense. The computer world has known better for about 50 years.
IF and WHILE suffice for any language.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 17 '07 #17
CBFalconer wrote:
so**********@gmail.com wrote:
>1) can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the
keyword goto

It has been shown (long ago) that any goto implemented program can
be implemented with only if and while.
>2) what exactly is the purpose of tmpfile() ? will it open a
temporary file ?

3) why there is no article on dangling pointer in the FAQ ?

I have no idea what you are talking about here. Please reference
the place in the C standard that defines these things.
tmpfile(): 7.19.4.3

dangling pointers: while that name is not used in the standard, it is a
name in common use for something the standard does describe: a pointer
whose value used to point at or into an object whose lifetime has since
ended. See 6.2.4p1 for the clause that allows such pointers to be
dangerous to use.
Nov 17 '07 #18
On Sat, 17 Nov 2007 22:21:12 GMT, James Kuyper
<ja*********@verizon.netwrote:
>CBFalconer wrote:
>so**********@gmail.com wrote:
>>1) can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the
keyword goto

It has been shown (long ago) that any goto implemented program can
be implemented with only if and while.
>>2) what exactly is the purpose of tmpfile() ? will it open a
temporary file ?

3) why there is no article on dangling pointer in the FAQ ?

I have no idea what you are talking about here. Please reference
the place in the C standard that defines these things.

tmpfile(): 7.19.4.3

dangling pointers: while that name is not used in the standard, it is a
name in common use for something the standard does describe: a pointer
whose value used to point at or into an object whose lifetime has since
ended. See 6.2.4p1 for the clause that allows such pointers to be
dangerous to use.
But it is not allowed. 6.2.4p2 specifically states that the value of
the pointer will indeterminate after the pointed to object's lifetime
has ended. Any use of an indeterminate value results in undefined
behavior.
Remove del for email
Nov 18 '07 #19
Barry Schwarz wrote:
>
On Sat, 17 Nov 2007 22:21:12 GMT, James Kuyper
<ja*********@verizon.netwrote:
dangling pointers: while that name is not used in the standard,
it is a name in common use for something
the standard does describe: a pointer
whose value used to point at or into an object
whose lifetime has since ended.
See 6.2.4p1 for the clause that allows such pointers to be
dangerous to use.

But it is not allowed. 6.2.4p2 specifically states that the value of
the pointer will indeterminate after the pointed to object's lifetime
has ended. Any use of an indeterminate value results in undefined
behavior.
I think that is very similar in meaning to:

"allows such pointers to be dangerous to use"

--
pete
Nov 18 '07 #20
Barry Schwarz <sc******@doezl.netwrites:
On Sat, 17 Nov 2007 22:21:12 GMT, James Kuyper
<ja*********@verizon.netwrote:
>>CBFalconer wrote:
>>so**********@gmail.com wrote:
1) can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the
keyword goto

It has been shown (long ago) that any goto implemented program can
be implemented with only if and while.

2) what exactly is the purpose of tmpfile() ? will it open a
temporary file ?

3) why there is no article on dangling pointer in the FAQ ?

I have no idea what you are talking about here. Please reference
the place in the C standard that defines these things.

tmpfile(): 7.19.4.3

dangling pointers: while that name is not used in the standard, it is a
name in common use for something the standard does describe: a pointer
whose value used to point at or into an object whose lifetime has since
ended. See 6.2.4p1 for the clause that allows such pointers to be
dangerous to use.

But it is not allowed. 6.2.4p2 specifically states that the value of
the pointer will indeterminate after the pointed to object's lifetime
has ended. Any use of an indeterminate value results in undefined
behavior.
No one said it is allowed. James was merely pointing out that "dangling
pointers" is a well known programming issue and is something people
should be aware of. Falconers typically abrasive and rude reply
suggested that because "dangling pointers" are not *specifically*
mentioned in the standard then anyone who talks about the things known
as "dangling pointers" is stupid and ignorant.
Nov 18 '07 #21
CBFalconer wrote:
Nonsense. The computer world has known better for about 50 years.
IF and WHILE suffice for any language.
WHILE doesn't work at all for pure-functional languages: it relies
on state in a way that IF doesn't.

On a less nit-picky level, I believe you're conflating theoretical
sufficiency with psychological efficacy (and that that's a bad thing).

--
Chris "programs are for people, not for theorems" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Nov 19 '07 #22
Barry Schwarz wrote:
On Sat, 17 Nov 2007 22:21:12 GMT, James Kuyper
<ja*********@verizon.netwrote:
>>CBFalconer wrote:
>>so**********@gmail.com wrote:
1) can any one give an example for a C program that can be written
using goto only ? i.e a program in which we cannot avoid the
keyword goto

It has been shown (long ago) that any goto implemented program can
be implemented with only if and while.

2) what exactly is the purpose of tmpfile() ? will it open a
temporary file ?

3) why there is no article on dangling pointer in the FAQ ?

I have no idea what you are talking about here. Please reference
the place in the C standard that defines these things.

tmpfile(): 7.19.4.3

dangling pointers: while that name is not used in the standard, it is a
name in common use for something the standard does describe: a pointer
whose value used to point at or into an object whose lifetime has since
ended. See 6.2.4p1 for the clause that allows such pointers to be
dangerous to use.

But it is not allowed. 6.2.4p2 specifically states that the value of
the pointer will indeterminate after the pointed to object's lifetime
has ended. Any use of an indeterminate value results in undefined
behavior.
I think James might be thinking that provoking undefined behaviour would
be dangerous.

--
Chris "never call a pointer Davies" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Nov 19 '07 #23
Chris Dollin <ch**********@hp.comwrites:
CBFalconer wrote:
>Nonsense. The computer world has known better for about 50 years.
IF and WHILE suffice for any language.

WHILE doesn't work at all for pure-functional languages: it relies
on state in a way that IF doesn't.
[Nit and now off-topic at that:] SASL and FP have "while". Miranda
and Haskell went for "until" but it could just have easily have been
while. There are probably others. While is quite logical in purely
function languages.

--
Ben.
Nov 19 '07 #24
Barry Schwarz wrote:
On Sat, 17 Nov 2007 22:21:12 GMT, James Kuyper
<ja*********@verizon.netwrote:
....
>dangling pointers: while that name is not used in the standard, it is a
name in common use for something the standard does describe: a pointer
whose value used to point at or into an object whose lifetime has since
ended. See 6.2.4p1 for the clause that allows such pointers to be
dangerous to use.

But it is not allowed. 6.2.4p2 specifically states that the value of
the pointer will indeterminate after the pointed to object's lifetime
has ended. Any use of an indeterminate value results in undefined
behavior.
The standard doesn't disallow it; it only says that the behavior is
undefined. It's up to the programmer to realize that undefined behavior
is a bad idea. If the programmer doesn't realize that, and writes and
executes the program anyway, the clauses that you and I referred to are
the ones that allow the implementation to produce results that the
programmer would probably be very unhappy about.
Nov 19 '07 #25
Ben Bacarisse wrote:
Chris Dollin <ch**********@hp.comwrites:
>CBFalconer wrote:
>>Nonsense. The computer world has known better for about 50 years.
IF and WHILE suffice for any language.

WHILE doesn't work at all for pure-functional languages: it relies
on state in a way that IF doesn't.

[Nit and now off-topic at that:] SASL and FP have "while". Miranda
and Haskell went for "until" but it could just have easily have been
while. There are probably others. While is quite logical in purely
function languages.
Yeahbut -- they require that the condition be some kind of functional
abstraction, yes? [Easy in FP, which IIRC is all functional abstractions.]

Otherwise, (fx:red-face).

--
Chris "it's been too long" Dollin

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Nov 19 '07 #26
Chris Dollin wrote:
CBFalconer wrote:
>Nonsense. The computer world has known better for about 50 years.
IF and WHILE suffice for any language.

WHILE doesn't work at all for pure-functional languages: it relies
on state in a way that IF doesn't.
What do you mean? To me, while operates on a logical expression.
So does if. Languages vary on how to define the controlled
expression(s).

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 20 '07 #27
CBFalconer wrote:
Chris Dollin wrote:
>CBFalconer wrote:
>>Nonsense. The computer world has known better for about 50 years.
IF and WHILE suffice for any language.

WHILE doesn't work at all for pure-functional languages: it relies
on state in a way that IF doesn't.

What do you mean?
Exactly what I said.
To me, while operates on a logical expression.
So does if. Languages vary on how to define the controlled
expression(s).
In `while E do C`, the /same expression/ `E` is evaluated potentially
multiple times, with different results. This works only because there's
an underlying mutable state.

In `if E then Y else N endif`, `E` is evaluated but once [in this context].
So it need not be state-sensitive.

[If you use a p-f language with a while, the control expression won't have
type boolean, but something more complicated, typically a function type
whatever -boolean -- /not/ just boolean: ie, it won't be "a logical
expression".]

--
Chris "the reader is expected to detect humour(*) for themselves" Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Nov 20 '07 #28
Philip Potter wrote:
CBFalconer wrote:
>Philip Potter wrote:
.... snip ...
>>
>>I can see how my argument may have been confusing. What I meant was
"all functions depend only on their arguments, so it is impossible
for a function to use a WHILE which depends on a state-based guard."
I didn't say that IF or WHILE are functions.

OK, cleared up. However, another annoying factor might be
explainable. In my earlier replies I have taken care to preserve
the missing blank line separators between paragraphs, and
especially between paragraphs originated by different people. They
have disappeared again in the above copy, leaving confusion. WHY?

I was unaware of this misquoting before you pointed this out. It seems
to be my newsreader (Mozilla Thunderbird). As an example, I have not
changed the quoting in this message at all, so you can see the effect it
has. Along with their ill-conceived "graphical quoting", these are two
misfeatures of the software.
Sigh. Still insects in T'bird. That is why I use Netscape as my
newsreader. This is another one of which I was not aware. If I
ever get exclusively onto Linux I shall be very annoyed.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 22 '07 #29

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: abbas reji | last post by:
--0-599929911-1059996886=:4358 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Content-Id: Content-Disposition: inline ...
1
by: Piotre Ugrumov | last post by:
I have some problems and some doubts. I have implemented a class hierachy. The base class Velivolo, from Velivolo derive Militare and Civile, from militare derive Aereo and Elicottero, from Civile...
6
by: ritesh | last post by:
Hi, I have been reading some text on C and C++ (i.e advanced books). One of the books mentioned that C++ requires a runtime support whereas C does not - what the author was trying to say was...
17
by: ranjeet.gupta | last post by:
Dear All Below are the few doubts which I got while studying about C 1. Is there any method in C by which we can process the entire string in one unit, 2. Does there exist any way to...
13
by: maadhuu | last post by:
hello everybody, i have 2 doubts . 1. is this always defined ?? int i =10; int a = i++ + i++; and also, i tried this in gcc, answer was 20, so what the sequence points for evaluation of...
6
by: Chua Wen Ching | last post by:
Hi there, I have some questions to ask... just say i have this xml file: Scenario :- Script.xml ======== <software> <settings>
2
by: VMI | last post by:
I'm having doubts as to how the compiler interprets this If statement: bool bIsTrue = true; if (! bIsTrue) { //RUN PROCESS } Here, will "RUN PROCESS" be executed? Or is this just wrong?...
1
by: Chris Leffer | last post by:
Hi. Reading some Microsoft materials about asp.net I came into two doubts. The following sentence is found on the topic "Application State" in the NET Framework documentation: "Calling Lock...
4
by: project | last post by:
Anybody can solve following doubts? 1. Normalization rules. 2. Garbage Collection 3.LinkList Posted Via Usenet.com Premium Usenet Newsgroup Services...
1
by: NagaKiran | last post by:
Hi I want to post VBA related doubts. Where can I post my doubts in VBA? thanks bye
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.