Question about a solution to excercise 4-13 in K & R

E

Eric Sosman

Richard Heathfield wrote On 08/01/06 17:57,:
Keith Thompson said:

Richard Heathfield said:
(e-mail address removed) said:
[...]

You're entitled to your opinion of what's clear, just
as other people are entitled to their opinion of what's
competent.

Quite so. Incidentally, I don't doubt /your/ competence - but you could
use a class in diplomacy. (Probably so could I.)

But who around here could teach it? :cool:}


Chris Torek as head of department, Steve Summit as principal lecturer, and
Stefan Wilms (if he ever manages to find his way back here after his
somewhat extended lunch break) as TA.

Orals administered by Dan Pop.
 
E

ena8t8si

Richard said:
(e-mail address removed) said:

Quite so. Incidentally, I don't doubt /your/ competence - but you could use
a class in diplomacy. (Probably so could I.)

"Yes sir, Mr. Pot," said Mr. Kettle.

If you read my other postings you'll see that my diplomacy
varies according to what, and sometimes who, I'm responding
to. I can be tactful, or not. A posting/poster showing
tact usually gets tact from me in return. And frequently
vice versa.
C is not a functional programming language. (I can imagine a few people
making hay with that statement, but I know /you/ know what I mean by
"functional" in this context.)

Your comments were about (among other things) writing an
algorithm in a functional programming style. It's
reasonable to judge those comments by the standards of the
community that does functional programming. The distance
between C and functional programming is not as big as you
seem to think it is.
 
P

Philip Potter

Your comments were about (among other things) writing an
algorithm in a functional programming style. It's
reasonable to judge those comments by the standards of the
community that does functional programming. The distance
between C and functional programming is not as big as you
seem to think it is.

It has state (variables, memory allocation).
It has control flow operations (while loops, gotos, breaks, the humble
semicolon)
It does not have anonymous functions.
It does not have function types.
It does not have polymorphism to the extent required by functional
languages.

I think these are pretty fundamental reasons for C to be considered "not a
functional language".

Philip
 
R

Richard Heathfield

(e-mail address removed) said:
"Yes sir, Mr. Pot," said Mr. Kettle.

If you read my other postings

I have done so.
you'll see that my diplomacy varies according to what, and sometimes who,
I'm responding to. I can be tactful, or not.

I've seen a lot of the latter, and almost none of the former. It's why I
hardly ever bother responding to you. And now I will resume that policy.
Ciao.
 
E

ena8t8si

Philip said:
It has state (variables, memory allocation).
It has control flow operations (while loops, gotos, breaks, the humble
semicolon)
It does not have anonymous functions.
It does not have function types.
It does not have polymorphism to the extent required by functional
languages.

Lisp is a functional language. Lisp has state (variables, setq).
Lisp has control flow operations (while loops, sequencing,
sometimes others depending on which Lisp). Lisp does have
functions but it doesn't have function types, or almost any type
other than list or atom. Lisp does not have polymorphism.

Also, C does have function types, and more importantly pointer to
function, which acts as a first-class function value. It's true,
C doesn't have closures (anonymous functions), but a lot of
functional programming can be done without using closures. It's
also not too difficult to construct C data values that behave
like closures.
I think these are pretty fundamental reasons for C to be considered "not a
functional language".

You'll notice I didn't say C is a functional language, only that
C can be used effectively to write in a functional programming
style. At least to the degree necessary to express the functions
that have been discussed in this thread.
 
E

ena8t8si

Richard said:
(e-mail address removed) said:


I have done so.


I've seen a lot of the latter, and almost none of the former. It's why I
hardly ever bother responding to you. And now I will resume that policy.
Ciao.

I'm sorry my sometimes strong language offends you. But
I'm not writing it just for your benefit.
 
D

Dave Thompson

Lisp is a functional language. Lisp has state (variables, setq).
Lisp has control flow operations (while loops, sequencing,
sometimes others depending on which Lisp). Lisp does have

Actually I'd call LISP is a mixture or hybrid of imperative and
functional, for precisely this reason. Classically its functional
parts got more emphasis and IINM use precisely because there were
(plenty of) other choices for imperative.
functions but it doesn't have function types, or almost any type
other than list or atom. Lisp does not have polymorphism.
Even classical LISP has lists (really conses) and two kinds of atoms:
number (integer) and symbol (name). Later ones, including the standard
Common LISP, have several distinguishable number kinds, character
strings, and more. Primitive arithmetic functions are usually
polymorphic over number types, EQUAL effectively is over all types,
and some others have special handling or special cases that are
arguably polymorphic like (CAR NIL) => NIL. Not to mention optional OO
dispatching which provides 'true' polymorphism among OO types.

Although user functions are canonically (and importantly) 'just
lists', primitive or compiled functions are usually a distinct type,
something like #EXPR, and closures at least sometimes are.
Also, C does have function types, and more importantly pointer to
function, which acts as a first-class function value. It's true,
C doesn't have closures (anonymous functions), but a lot of
functional programming can be done without using closures. It's
also not too difficult to construct C data values that behave
like closures.
Well, you can capture the data (needed) for a closure, as indeed you
can in almost any language, but it doesn't have any behavior.

You'll notice I didn't say C is a functional language, only that
C can be used effectively to write in a functional programming
style. At least to the degree necessary to express the functions
that have been discussed in this thread.

Agree there. Although I'd have to be under severe stress to think it's
worth the trouble when languages designed for it are available.

- David.Thompson1 at worldnet.att.net
 
E

ena8t8si

Dave said:
Actually I'd call LISP is a mixture or hybrid of imperative and
functional, for precisely this reason. Classically its functional
parts got more emphasis and IINM use precisely because there were
(plenty of) other choices for imperative.

Lisp surely has accreted many imperative constructs over the
years. But essentially Lisp started with just the Lambda Calculus,
widely acknowledged as the original basis for functional
programming. The direction was the opposite of what's suggested
above - Lisp started as almost completely functional, and
imperative features were added and got more use because of
other imperative languages.
Even classical LISP has lists (really conses) and two kinds of atoms:
number (integer) and symbol (name). Later ones, including the standard
Common LISP, have several distinguishable number kinds, character
strings, and more.

Yes, maybe it's an oversimplification to lump those
all together under just "atom". But no user defined
types.
Primitive arithmetic functions are usually
polymorphic over number types, EQUAL effectively is over all types,
and some others have special handling or special cases that are
arguably polymorphic like (CAR NIL) => NIL.

Operators in C apply to multiple types, but that doesn't
make C polymorphic.

When I say Lisp doesn't have polymorphism what I mean is
that there are no linguistic mechanisms to support defining
polymorphic functions. Saying Lisp is polymorphic is like
saying C is polymorphic because a function can switch() on
one member of a struct and cast another member to one type
or another.
Not to mention optional OO
dispatching which provides 'true' polymorphism among OO types.

Lisp object systems are layered on top of Lisp, not part
of Lisp. An OO language can be implemented in C, but
that doesn't make C an OO language.
Although user functions are canonically (and importantly) 'just
lists', primitive or compiled functions are usually a distinct type,
something like #EXPR, and closures at least sometimes are.

Probably an important implementation detail, but it
doesn't seem like much more than that.
Well, you can capture the data (needed) for a closure, as indeed you
can in almost any language, but it doesn't have any behavior.

Behavior can be included with the data by means of
a function pointer, which is the key point. This
often can't be done in other languages, when they
lack first class function values -- as in Pascal, for
example.
Agree there. Although I'd have to be under severe stress to think it's
worth the trouble when languages designed for it are available.

In my experience most programs have some parts that are better
done functionally, and other parts that are better done
imperatively, no matter what language they're written in.
I think people who do no functional programming in C
"because it isn't a functional language" are missing out
on an important part of program construction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top