Re: technology discussion → does the world need a "new" C ?

Liste des GroupesRevenir à cl c 
Sujet : Re: technology discussion → does the world need a "new" C ?
De : already5chosen (at) *nospam* yahoo.com (Michael S)
Groupes : comp.lang.c
Date : 11. Jul 2024, 09:13:57
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240711111357.00007712@yahoo.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
User-Agent : Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32)
On Wed, 10 Jul 2024 21:28:15 +0200
David Brown <david.brown@hesbynett.no> wrote:

On 10/07/2024 19:14, Michael S wrote:
On Wed, 10 Jul 2024 08:48:05 -0700
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
 
bart <bc@freeuk.com> writes:
 
I earlier asked this:
>
"So if arrays aren't passed by value in C, and they aren't passed
by reference, then how the hell ARE they passed?!" 
>
They aren't.  C allows lots of things to be passed as an argument
to a function:  several varieties of numeric values, structs,
unions, and pointers, including both pointers to object types and
pointers to function types.  C does not have a way for a function
to take an argument that is either an array or a function.  There
is a way to take pointers to those things, but not the things
themselves.  Arrays and functions are second-class values in C.
 
 
I'd like to see an example of the language that permits
ahead-of-time compilation and has functions as first-class values.
 
 
Haskell is the first the comes to mind for me, but you could pick any
compiled functional programming language.
 
I am by no means a Haskell expert, and I am not at all familiar with
the way the language is compiled.  But it is quite clear that it is
an example of a language that has functions as first-class objects,
and which is ahead-of-time compiled.  The example below defines an
int-to-int function "doubler", and also a function-to-function
function "doTwice", and a function quadrupler that is defined as the
result of applying the higher-order function doTwice to doubler.
These are all compiled to assembly.
 
<https://godbolt.org/z/Tb7hGYsdv>
 
 
module Example where
 
doubler :: Int -> Int
doubler x = 2 * x
 
doTwice :: (Int -> Int) -> (Int -> Int)
doTwice f x = f (f x)
 
quadrupler = doTwice doubler
 
shouldBeEighty = quadrupler 20
 
 
 
You can write much the same in C++ using lambdas (which are objects
and can be passed around and returned as such) and templates (which
are needed because the type of lambdas is hidden).  Unfortunately,
this also means that the functions don't get individually generated
functions in assembly:
 
<https://godbolt.org/z/KvPWz3n8z>
 
auto doubler = [](int x) -> int { return 2 * x; };
 
auto doTwice = [](auto f) -> auto
{
     return [f](int x) -> int { return f(f(x)); };
};
 
auto quadrupler = doTwice(doubler);
 
auto shouldBeEiqhty = quadrupler(20);
 

I fail to see a material difference between first class function values
in Haskell and C++ and first class function pointer values in C:

int doubler(int x) {
  return x*2;
}
int doTwice(int (*foo)(int), int x) {
  return foo(foo(x));
}
int quadrupler(int x) {
  return doTwice(doubler, x);
}

I am willing to believe that the difference exists, but your example is
too basic to demonstrate it.




Date Sujet#  Auteur
6 Jul 24 * Re: technology discussion → does the world need a "new" C ?256Lawrence D'Oliveiro
6 Jul 24 +* Re: technology discussion → does the world need a "new" C ?240BGB
6 Jul 24 i+- Re: technology discussion → does the world need a "new" C ?1BGB
6 Jul 24 i+* Re: technology discussion → does the world need a "new" C ?10James Kuyper
9 Jul 24 ii`* Re: technology discussion → does the world need a "new" C ?4David Brown
9 Jul 24 ii `* Re: technology discussion → does the world need a "new" C ?3Michael S
9 Jul 24 ii  +- Re: technology discussion → does the world need a "new" C ?1David Brown
9 Jul 24 ii  `- Re: technology discussion → does the world need a "new" C ?1BGB
6 Jul 24 i`* Re: technology discussion → does the world need a "new" C ?228Keith Thompson
7 Jul 24 i +* Re: technology discussion → does the world need a "new" C ?223BGB
7 Jul 24 i i`* Re: technology discussion → does the world need a "new" C ?222James Kuyper
7 Jul 24 i i `- Re: technology discussion → does the world need a "new" C ?221BGB
10 Jul 24 i `* Re: technology discussion → does the world need a "new" C ?4Lawrence D'Oliveiro
10 Jul 24 i  +- Re: technology discussion → does the world need a "new" C ?1Keith Thompson
10 Jul 24 i  `* Re: technology discussion → does the world need a "new" C ?2James Kuyper
10 Jul 24 i   `- Re: technology discussion → does the world need a "new" C ?1Kaz Kylheku
6 Jul 24 +* Re: technology discussion → does the world need a "new" C ?9James Kuyper
6 Jul 24 i+* Re: technology discussion → does the world need a "new" C ?5bart
10 Jul 24 ii+- Re: technology discussion → does the world need a "new" C ?1Lawrence D'Oliveiro
10 Jul 24 ii+* Re: technology discussion → does the world need a "new" C ?2James Kuyper
10 Jul 24 iii`- Re: technology discussion → does the world need a "new" C ?1bart
12 Aug 24 ii`- Re: technology discussion → does the world need a "new" C ?1Tim Rentsch
6 Jul 24 i`* Re: technology discussion → does the world need a "new" C ?3Keith Thompson
7 Jul 24 i `* Re: technology discussion → does the world need a "new" C ?2James Kuyper
7 Jul 24 i  `- Re: technology discussion → does the world need a "new" C ?1Keith Thompson
6 Jul 24 `* Re: technology discussion → does the world need a "new" C ?6Keith Thompson
10 Jul 24  `* Re: technology discussion → does the world need a "new" C ?5Lawrence D'Oliveiro
10 Jul 24   +- Re: technology discussion → does the world need a "new" C ?1James Kuyper
10 Jul 24   +- Re: technology discussion → does the world need a "new" C ?1Keith Thompson
10 Jul 24   `* Re: technology discussion → does the world need a "new" C ?2Kaz Kylheku
10 Jul 24    `- Re: technology discussion → does the world need a "new" C ?1Ben Bacarisse

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal