Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Truth has always been found to promote the best interests of mankind... -- Percy Bysshe Shelley


devel / comp.lang.c++ / Re: Let's do that functional

SubjectAuthor
* Let's do that functionalBonita Montero
+* Re: Let's do that functionalAlf P. Steinbach
|`- Re: Let's do that functionalBonita Montero
+* Re: Let's do that functionalPavel
|`* Re: Let's do that functionalBonita Montero
| `- Re: Let's do that functionalPavel
`* Re: Let's do that functionalAndrey Tarasevich
 `- Re: Let's do that functionalBonita Montero

1
Let's do that functional

<ubf8mm$2npob$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1034&group=comp.lang.c%2B%2B#1034

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Let's do that functional
Date: Tue, 15 Aug 2023 09:15:37 +0200
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <ubf8mm$2npob$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 15 Aug 2023 07:15:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="21be441b1771a498c1ef80c80319ddc7";
logging-data="2877195"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182wIz6O6ukqj30inPyjwQZmgK+6yHmuog="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:FeEjKnZTmBJtp/20jZcfRtWPoKQ=
Content-Language: de-DE
 by: Bonita Montero - Tue, 15 Aug 2023 07:15 UTC

I wanted to check the typed of different Win32 HANDLEs. Although this
is documented I wanted to do that myself. I did that with the functional
programming style I love so much - having code in an initializer_list<>.

#include <WinSock2.h>
#include <Windows.h>
#include <iostream>
#include <functional>
#include <system_error>

using namespace std;

int main( int argc, char **argv )
{ WSADATA wsaData;
(void)WSAStartup( MAKEWORD(2, 2), &wsaData );
using fn_ret_t = pair<char const *, HANDLE>;
using fn_t = function<fn_ret_t ()>;
static fn_t const functions[] =
{
[&]() -> fn_ret_t
{
if( argc < 1 || !argv[0] )
return { nullptr, NULL };
return { "file: ", CreateFileA( argv[0], GENERIC_READ,
FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ) };
},
[]() -> fn_ret_t { return { "stdin: ", GetStdHandle( STD_INPUT_HANDLE
) }; },
[]() -> fn_ret_t { return { "TCP-socket: ", (HANDLE)socket( AF_INET,
SOCK_STREAM, IPPROTO_TCP ) }; },
[]() -> fn_ret_t { return { "UDP-socket: ", (HANDLE)socket( AF_INET,
SOCK_DGRAM, IPPROTO_UDP ) }; },
[]() -> fn_ret_t { return { "ICMP-socket: ", (HANDLE)socket( AF_INET,
SOCK_RAW, IPPROTO_ICMP ) }; }
};
using map_t = pair<DWORD, char const*>;
static map_t const mappings[] =
{
{ FILE_TYPE_CHAR, "FILE_TYPE_CHAR" },
{ FILE_TYPE_DISK, "FILE_TYPE_DISK" },
{ FILE_TYPE_PIPE, "FILE_TYPE_PIPE" },
{ FILE_TYPE_REMOTE, "FILE_TYPE_REMOTE" },
{ FILE_TYPE_UNKNOWN, "FILE_TYPE_UNKNOWN" }
};
for( fn_t const &fn : functions )
if( fn_ret_t fr = fn(); fr.first && fr.second )
{
DWORD dwFileType = GetFileType( fr.second );
map_t const *type = find_if( mappings, end( mappings ), [&]( map_t
const &mapEntry ) { return mapEntry.first == dwFileType; } );
if( type == end( mappings ) )
continue;
cout << fr.first << type->second << endl;
}
}

Re: Let's do that functional

<ubg0hc$2rjco$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1036&group=comp.lang.c%2B%2B#1036

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: alf.p.steinbach@gmail.com (Alf P. Steinbach)
Newsgroups: comp.lang.c++
Subject: Re: Let's do that functional
Date: Tue, 15 Aug 2023 16:02:19 +0200
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <ubg0hc$2rjco$1@dont-email.me>
References: <ubf8mm$2npob$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 15 Aug 2023 14:02:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c9af94c4a651d94dce17067496bbc6cc";
logging-data="3001752"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9mfea/WIL2QUYz7B9x4MG"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:ulo9l074YcrO4Sgi2W8fjUo+2e0=
Content-Language: en-US
In-Reply-To: <ubf8mm$2npob$1@dont-email.me>
 by: Alf P. Steinbach - Tue, 15 Aug 2023 14:02 UTC

On 2023-08-15 9:15 AM, Bonita Montero wrote:
> I wanted to check the typed of different Win32 HANDLEs. Although this
> is documented I wanted to do that myself. I did that with the functional
> programming style I love so much - having code in an initializer_list<>.
>
> #include <WinSock2.h>
> #include <Windows.h>
> #include <iostream>
> #include <functional>
> #include <system_error>
>
> using namespace std;
>
> int main( int argc, char **argv )
> {
>     WSADATA wsaData;
>     (void)WSAStartup( MAKEWORD(2, 2), &wsaData );
>     using fn_ret_t = pair<char const *, HANDLE>;
>     using fn_t = function<fn_ret_t ()>;
>     static fn_t const functions[] =
>     {
>         [&]() -> fn_ret_t
>         {
>             if( argc < 1 || !argv[0] )
>                 return { nullptr, NULL };
>             return { "file: ", CreateFileA( argv[0], GENERIC_READ,
> FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ) };
>         },
>         []() -> fn_ret_t { return { "stdin: ", GetStdHandle(
> STD_INPUT_HANDLE ) }; },
>         []() -> fn_ret_t { return { "TCP-socket: ", (HANDLE)socket(
> AF_INET, SOCK_STREAM, IPPROTO_TCP ) }; },
>         []() -> fn_ret_t { return { "UDP-socket: ", (HANDLE)socket(
> AF_INET, SOCK_DGRAM, IPPROTO_UDP ) }; },
>         []() -> fn_ret_t { return { "ICMP-socket: ", (HANDLE)socket(
> AF_INET, SOCK_RAW, IPPROTO_ICMP ) }; }
>     };
>     using map_t = pair<DWORD, char const*>;
>     static map_t const mappings[] =
>     {
>         { FILE_TYPE_CHAR, "FILE_TYPE_CHAR" },
>         { FILE_TYPE_DISK, "FILE_TYPE_DISK" },
>         { FILE_TYPE_PIPE, "FILE_TYPE_PIPE" },
>         { FILE_TYPE_REMOTE, "FILE_TYPE_REMOTE" },
>         { FILE_TYPE_UNKNOWN, "FILE_TYPE_UNKNOWN" }
>     };
>     for( fn_t const &fn : functions )
>         if( fn_ret_t fr = fn(); fr.first && fr.second )
>         {
>             DWORD dwFileType = GetFileType( fr.second );
>             map_t const *type = find_if( mappings, end( mappings ),
> [&]( map_t const &mapEntry ) { return mapEntry.first == dwFileType; } );
>             if( type == end( mappings ) )
>                 continue;
>             cout << fr.first << type->second << endl;
>         }
> }

I don't see any purpose of the lambda expressions. You can use
expressions directly for the HANDLEs. With a conditional expression for
the first.

- Alf

Re: Let's do that functional

<ubg4rk$2sf7j$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1037&group=comp.lang.c%2B%2B#1037

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Let's do that functional
Date: Tue, 15 Aug 2023 17:16:07 +0200
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <ubg4rk$2sf7j$1@dont-email.me>
References: <ubf8mm$2npob$1@dont-email.me> <ubg0hc$2rjco$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 15 Aug 2023 15:16:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="21be441b1771a498c1ef80c80319ddc7";
logging-data="3030259"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9cffEam504WZClmgMCXeKdkmPxApotJ8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Ycl7ak6B/7/4n997CwKaWjXd/vU=
In-Reply-To: <ubg0hc$2rjco$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Tue, 15 Aug 2023 15:16 UTC

Am 15.08.2023 um 16:02 schrieb Alf P. Steinbach:
> On 2023-08-15 9:15 AM, Bonita Montero wrote:
>> I wanted to check the typed of different Win32 HANDLEs. Although this
>> is documented I wanted to do that myself. I did that with the functional
>> programming style I love so much - having code in an initializer_list<>.
>>
>> #include <WinSock2.h>
>> #include <Windows.h>
>> #include <iostream>
>> #include <functional>
>> #include <system_error>
>>
>> using namespace std;
>>
>> int main( int argc, char **argv )
>> {
>>      WSADATA wsaData;
>>      (void)WSAStartup( MAKEWORD(2, 2), &wsaData );
>>      using fn_ret_t = pair<char const *, HANDLE>;
>>      using fn_t = function<fn_ret_t ()>;
>>      static fn_t const functions[] =
>>      {
>>          [&]() -> fn_ret_t
>>          {
>>              if( argc < 1 || !argv[0] )
>>                  return { nullptr, NULL };
>>              return { "file: ", CreateFileA( argv[0], GENERIC_READ,
>> FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ) };
>>          },
>>          []() -> fn_ret_t { return { "stdin: ", GetStdHandle(
>> STD_INPUT_HANDLE ) }; },
>>          []() -> fn_ret_t { return { "TCP-socket: ", (HANDLE)socket(
>> AF_INET, SOCK_STREAM, IPPROTO_TCP ) }; },
>>          []() -> fn_ret_t { return { "UDP-socket: ", (HANDLE)socket(
>> AF_INET, SOCK_DGRAM, IPPROTO_UDP ) }; },
>>          []() -> fn_ret_t { return { "ICMP-socket: ", (HANDLE)socket(
>> AF_INET, SOCK_RAW, IPPROTO_ICMP ) }; }
>>      };
>>      using map_t = pair<DWORD, char const*>;
>>      static map_t const mappings[] =
>>      {
>>          { FILE_TYPE_CHAR, "FILE_TYPE_CHAR" },
>>          { FILE_TYPE_DISK, "FILE_TYPE_DISK" },
>>          { FILE_TYPE_PIPE, "FILE_TYPE_PIPE" },
>>          { FILE_TYPE_REMOTE, "FILE_TYPE_REMOTE" },
>>          { FILE_TYPE_UNKNOWN, "FILE_TYPE_UNKNOWN" }
>>      };
>>      for( fn_t const &fn : functions )
>>          if( fn_ret_t fr = fn(); fr.first && fr.second )
>>          {
>>              DWORD dwFileType = GetFileType( fr.second );
>>              map_t const *type = find_if( mappings, end( mappings ),
>> [&]( map_t const &mapEntry ) { return mapEntry.first == dwFileType; } );
>>              if( type == end( mappings ) )
>>                  continue;
>>              cout << fr.first << type->second << endl;
>>          }
>> }
>
> I don't see any purpose of the lambda expressions. You can use
> expressions directly for the HANDLEs. With a conditional expression for
> the first.

But you'd have multiple calls of the lambdas. That's just a pattern
for me which I use often to make code mor easily extendible.

Re: Let's do that functional

<tCXCM.132385$cc2c.67713@fx37.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1041&group=comp.lang.c%2B%2B#1041

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx37.iad.POSTED!not-for-mail
Subject: Re: Let's do that functional
Newsgroups: comp.lang.c++
References: <ubf8mm$2npob$1@dont-email.me>
From: pauldontspamtolk@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <ubf8mm$2npob$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 70
Message-ID: <tCXCM.132385$cc2c.67713@fx37.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Wed, 16 Aug 2023 03:44:25 UTC
Date: Tue, 15 Aug 2023 23:44:14 -0400
X-Received-Bytes: 3558
 by: Pavel - Wed, 16 Aug 2023 03:44 UTC

Bonita Montero wrote:
> I wanted to check the typed of different Win32 HANDLEs. Although this
> is documented I wanted to do that myself. I did that with the functional
> programming style I love so much
(Yours is not the functional style but hybrid at best
(because
(functional programmers don't use
(or
(iterative loops)
(mutable variables
(truly functional programmers don't use mutable variables either)
(hence functional programmers don't use cout
(and not only because of the above))))))
(-Pavel))

> - having code in an initializer_list<>.
>
> #include <WinSock2.h>
> #include <Windows.h>
> #include <iostream>
> #include <functional>
> #include <system_error>
>
> using namespace std;
>
> int main( int argc, char **argv )
> {
>     WSADATA wsaData;
>     (void)WSAStartup( MAKEWORD(2, 2), &wsaData );
>     using fn_ret_t = pair<char const *, HANDLE>;
>     using fn_t = function<fn_ret_t ()>;
>     static fn_t const functions[] =
>     {
>         [&]() -> fn_ret_t
>         {
>             if( argc < 1 || !argv[0] )
>                 return { nullptr, NULL };
>             return { "file: ", CreateFileA( argv[0], GENERIC_READ,
> FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ) };
>         },
>         []() -> fn_ret_t { return { "stdin: ", GetStdHandle(
> STD_INPUT_HANDLE ) }; },
>         []() -> fn_ret_t { return { "TCP-socket: ", (HANDLE)socket(
> AF_INET, SOCK_STREAM, IPPROTO_TCP ) }; },
>         []() -> fn_ret_t { return { "UDP-socket: ", (HANDLE)socket(
> AF_INET, SOCK_DGRAM, IPPROTO_UDP ) }; },
>         []() -> fn_ret_t { return { "ICMP-socket: ", (HANDLE)socket(
> AF_INET, SOCK_RAW, IPPROTO_ICMP ) }; }
>     };
>     using map_t = pair<DWORD, char const*>;
>     static map_t const mappings[] =
>     {
>         { FILE_TYPE_CHAR, "FILE_TYPE_CHAR" },
>         { FILE_TYPE_DISK, "FILE_TYPE_DISK" },
>         { FILE_TYPE_PIPE, "FILE_TYPE_PIPE" },
>         { FILE_TYPE_REMOTE, "FILE_TYPE_REMOTE" },
>         { FILE_TYPE_UNKNOWN, "FILE_TYPE_UNKNOWN" }
>     };
>     for( fn_t const &fn : functions )
>         if( fn_ret_t fr = fn(); fr.first && fr.second )
>         {
>             DWORD dwFileType = GetFileType( fr.second );
>             map_t const *type = find_if( mappings, end( mappings ),
> [&]( map_t const &mapEntry ) { return mapEntry.first == dwFileType; } );
>             if( type == end( mappings ) )
>                 continue;
>             cout << fr.first << type->second << endl;
>         }
> }

Re: Let's do that functional

<ubi15o$37vc3$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1042&group=comp.lang.c%2B%2B#1042

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Let's do that functional
Date: Wed, 16 Aug 2023 10:25:29 +0200
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <ubi15o$37vc3$1@dont-email.me>
References: <ubf8mm$2npob$1@dont-email.me> <tCXCM.132385$cc2c.67713@fx37.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 16 Aug 2023 08:25:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="968e0a5f39da2f43ea5079336edb49b8";
logging-data="3407235"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GPFmX2JZDdXYaO9XQN09SHUxM3Zw4hUA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:yJAijGPDjxlKdqQ3JlJy83aLkgk=
In-Reply-To: <tCXCM.132385$cc2c.67713@fx37.iad>
Content-Language: de-DE
 by: Bonita Montero - Wed, 16 Aug 2023 08:25 UTC

Am 16.08.2023 um 05:44 schrieb Pavel:
> Bonita Montero wrote:
>> I wanted to check the typed of different Win32 HANDLEs. Although this
>> is documented I wanted to do that myself. I did that with the functional
>> programming style I love so much
> (Yours is not the functional style but hybrid at best
>  (because
>   (functional programmers don't use
>    (or
>     (iterative loops)
>     (mutable variables
>      (truly functional programmers don't use mutable variables either)
>      (hence functional programmers don't use cout
>       (and not only because of the above))))))
>  (-Pavel))

Pure functional languages like SQL don't have any control flow. I like
the mix of imperative programming with OOP and functional programming,
but not pure functional but _with_ state like with C++11. I discovered
functional programming in C++ much later than C++ can (2011).

>
>> - having code in an initializer_list<>.
>>
>> #include <WinSock2.h>
>> #include <Windows.h>
>> #include <iostream>
>> #include <functional>
>> #include <system_error>
>>
>> using namespace std;
>>
>> int main( int argc, char **argv )
>> {
>>      WSADATA wsaData;
>>      (void)WSAStartup( MAKEWORD(2, 2), &wsaData );
>>      using fn_ret_t = pair<char const *, HANDLE>;
>>      using fn_t = function<fn_ret_t ()>;
>>      static fn_t const functions[] =
>>      {
>>          [&]() -> fn_ret_t
>>          {
>>              if( argc < 1 || !argv[0] )
>>                  return { nullptr, NULL };
>>              return { "file: ", CreateFileA( argv[0], GENERIC_READ,
>> FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ) };
>>          },
>>          []() -> fn_ret_t { return { "stdin: ", GetStdHandle(
>> STD_INPUT_HANDLE ) }; },
>>          []() -> fn_ret_t { return { "TCP-socket: ", (HANDLE)socket(
>> AF_INET, SOCK_STREAM, IPPROTO_TCP ) }; },
>>          []() -> fn_ret_t { return { "UDP-socket: ", (HANDLE)socket(
>> AF_INET, SOCK_DGRAM, IPPROTO_UDP ) }; },
>>          []() -> fn_ret_t { return { "ICMP-socket: ", (HANDLE)socket(
>> AF_INET, SOCK_RAW, IPPROTO_ICMP ) }; }
>>      };
>>      using map_t = pair<DWORD, char const*>;
>>      static map_t const mappings[] =
>>      {
>>          { FILE_TYPE_CHAR, "FILE_TYPE_CHAR" },
>>          { FILE_TYPE_DISK, "FILE_TYPE_DISK" },
>>          { FILE_TYPE_PIPE, "FILE_TYPE_PIPE" },
>>          { FILE_TYPE_REMOTE, "FILE_TYPE_REMOTE" },
>>          { FILE_TYPE_UNKNOWN, "FILE_TYPE_UNKNOWN" }
>>      };
>>      for( fn_t const &fn : functions )
>>          if( fn_ret_t fr = fn(); fr.first && fr.second )
>>          {
>>              DWORD dwFileType = GetFileType( fr.second );
>>              map_t const *type = find_if( mappings, end( mappings ),
>> [&]( map_t const &mapEntry ) { return mapEntry.first == dwFileType; } );
>>              if( type == end( mappings ) )
>>                  continue;
>>              cout << fr.first << type->second << endl;
>>          }
>> }
>

Re: Let's do that functional

<p7fDM.132388$cc2c.66425@fx37.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1061&group=comp.lang.c%2B%2B#1061

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.neodome.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx37.iad.POSTED!not-for-mail
Subject: Re: Let's do that functional
Newsgroups: comp.lang.c++
References: <ubf8mm$2npob$1@dont-email.me> <tCXCM.132385$cc2c.67713@fx37.iad>
<ubi15o$37vc3$1@dont-email.me>
From: pauldontspamtolk@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <ubi15o$37vc3$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 83
Message-ID: <p7fDM.132388$cc2c.66425@fx37.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Thu, 17 Aug 2023 01:56:37 UTC
Date: Wed, 16 Aug 2023 21:56:18 -0400
X-Received-Bytes: 4376
 by: Pavel - Thu, 17 Aug 2023 01:56 UTC

Bonita Montero wrote:
> Am 16.08.2023 um 05:44 schrieb Pavel:
>> Bonita Montero wrote:
>>> I wanted to check the typed of different Win32 HANDLEs. Although this
>>> is documented I wanted to do that myself. I did that with the functional
>>> programming style I love so much
>> (Yours is not the functional style but hybrid at best
>>   (because
>>    (functional programmers don't use
>>     (or
>>      (iterative loops)
>>      (mutable variables
>>       (truly functional programmers don't use mutable variables either)
>>       (hence functional programmers don't use cout
>>        (and not only because of the above))))))
>>   (-Pavel))
>
> Pure functional languages like SQL don't have any control flow.
SQL IS NOT PURE FUNCTIONAL AS IT HAS TEMPORARY TABLES FOR VARIABLES QED
I like
> the mix of imperative programming with OOP and functional programming,
> but not pure functional but _with_ state like with C++11. I discovered
> functional programming in C++ much later than C++ can (2011).
>
>>
>>> - having code in an initializer_list<>.
>>>
>>> #include <WinSock2.h>
>>> #include <Windows.h>
>>> #include <iostream>
>>> #include <functional>
>>> #include <system_error>
>>>
>>> using namespace std;
>>>
>>> int main( int argc, char **argv )
>>> {
>>>      WSADATA wsaData;
>>>      (void)WSAStartup( MAKEWORD(2, 2), &wsaData );
>>>      using fn_ret_t = pair<char const *, HANDLE>;
>>>      using fn_t = function<fn_ret_t ()>;
>>>      static fn_t const functions[] =
>>>      {
>>>          [&]() -> fn_ret_t
>>>          {
>>>              if( argc < 1 || !argv[0] )
>>>                  return { nullptr, NULL };
>>>              return { "file: ", CreateFileA( argv[0], GENERIC_READ,
>>> FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
>>> ) };
>>>          },
>>>          []() -> fn_ret_t { return { "stdin: ", GetStdHandle(
>>> STD_INPUT_HANDLE ) }; },
>>>          []() -> fn_ret_t { return { "TCP-socket: ", (HANDLE)socket(
>>> AF_INET, SOCK_STREAM, IPPROTO_TCP ) }; },
>>>          []() -> fn_ret_t { return { "UDP-socket: ", (HANDLE)socket(
>>> AF_INET, SOCK_DGRAM, IPPROTO_UDP ) }; },
>>>          []() -> fn_ret_t { return { "ICMP-socket: ", (HANDLE)socket(
>>> AF_INET, SOCK_RAW, IPPROTO_ICMP ) }; }
>>>      };
>>>      using map_t = pair<DWORD, char const*>;
>>>      static map_t const mappings[] =
>>>      {
>>>          { FILE_TYPE_CHAR, "FILE_TYPE_CHAR" },
>>>          { FILE_TYPE_DISK, "FILE_TYPE_DISK" },
>>>          { FILE_TYPE_PIPE, "FILE_TYPE_PIPE" },
>>>          { FILE_TYPE_REMOTE, "FILE_TYPE_REMOTE" },
>>>          { FILE_TYPE_UNKNOWN, "FILE_TYPE_UNKNOWN" }
>>>      };
>>>      for( fn_t const &fn : functions )
>>>          if( fn_ret_t fr = fn(); fr.first && fr.second )
>>>          {
>>>              DWORD dwFileType = GetFileType( fr.second );
>>>              map_t const *type = find_if( mappings, end( mappings ),
>>> [&]( map_t const &mapEntry ) { return mapEntry.first == dwFileType; } );
>>>              if( type == end( mappings ) )
>>>                  continue;
>>>              cout << fr.first << type->second << endl;
>>>          }
>>> }
>>
>

Re: Let's do that functional

<ubnvmo$9r1v$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1074&group=comp.lang.c%2B%2B#1074

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: andreytarasevich@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c++
Subject: Re: Let's do that functional
Date: Fri, 18 Aug 2023 07:37:11 -0700
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <ubnvmo$9r1v$1@dont-email.me>
References: <ubf8mm$2npob$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 18 Aug 2023 14:37:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e782545ecb86af62ab5406d0b73e73d3";
logging-data="322623"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19A88ZSr4ZcqD7r3D2qPezj"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:CKkd5Q/GPJ7jBobDH2XFYiWmPQU=
In-Reply-To: <ubf8mm$2npob$1@dont-email.me>
Content-Language: en-US
 by: Andrey Tarasevich - Fri, 18 Aug 2023 14:37 UTC

On 08/15/23 12:15 AM, Bonita Montero wrote:
> I wanted to check the typed of different Win32 HANDLEs. Although this
> is documented I wanted to do that myself. I did that with the functional
> programming style I love so much - having code in an initializer_list<>.
>

Huh? There's no "code in an initializer_list<>" in the code you posted.

--
Best regards,
Andrey

Re: Let's do that functional

<ubo3jg$ages$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1075&group=comp.lang.c%2B%2B#1075

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Let's do that functional
Date: Fri, 18 Aug 2023 17:43:44 +0200
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <ubo3jg$ages$1@dont-email.me>
References: <ubf8mm$2npob$1@dont-email.me> <ubnvmo$9r1v$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 18 Aug 2023 15:43:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aea22d724f6adf17b2a10ce8004bc827";
logging-data="344540"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18eFtHXYfkz3CJZobdUDYi+Y4Z997WXDow="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:kJN3msSyYlor4vdv260pReXu5Y4=
Content-Language: de-DE
In-Reply-To: <ubnvmo$9r1v$1@dont-email.me>
 by: Bonita Montero - Fri, 18 Aug 2023 15:43 UTC

Am 18.08.2023 um 16:37 schrieb Andrey Tarasevich:

> Huh? There's no "code in an initializer_list<>" in the code you posted.

Right, it's just a C-style array.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor