Re: Hello world/Web server task on RosettaCode fails

2021-07-16 Thread btiffin via Digitalmars-d-learn

On Friday, 16 July 2021 at 20:04:21 UTC, jfondren wrote:

On Friday, 16 July 2021 at 19:25:32 UTC, btiffin wrote:
Using gdc-11 and Seamonkey.  
https://rosettacode.org/wiki/Hello_world/Web_server#D does not 
compile.


The `while` as you noted is wrong. The server also doesn't turn 
REUSEADDR on for the server socket, so this will be very 
annoying to test as you'll frequently get "address already in 
use" errors when you restart the server. The delimited string 
leads to your last problem: a blank space between the headers 
and the body of the response results in "\r\n \r\n" being sent 
rather than "\r\n\r\n", so the browser gives up on the invalid 
HTTP.


Ahh, thanks.  The spaces.  And turning on REUSEADDR made playing 
with the code a fair bit more fun.


But, I mainly made the note to motivate a D aficionado to update 
and fix the Rosetta entry so that it at least compiles. Perhaps 
the whole *be bold* thing, and make the sources as idiomatic and 
correctly concise as D deserves.  As a for instance, task 
description calls for Goodbye as the text in the solution.




This works if you're careful to not re-add any stray whitespace 
in the response:

...


But this *still violates HTTP* by not receiving the client's 
request, so it's still not a good answer for the task. A vibe 
hello world would make a lot more sense:

https://github.com/vibe-d/vibe.d/blob/master/examples/http_server/source/app.d

If this is the wrong place for this kind of info note, I'll 
gladly move to or redo the post in a more appropriate spot.


You're in the right place.


Cool.  It's a nice place.  :-)

Cheers


Hello world/Web server task on RosettaCode fails

2021-07-16 Thread btiffin via Digitalmars-d-learn
Using gdc-11 and Seamonkey.  
https://rosettacode.org/wiki/Hello_world/Web_server#D does not 
compile.


```d
prompt$ gdc-11 helloServer.d
helloServer.d:12:29: error: cannot cast expression currSock = 
listener.accept() of type std.socket.Socket to bool

   12 |   while(cast(bool)(currSock = listener.accept())) {
  | ^
```

Then, tweaking the while loop to not cast but just run forever, 
`while (true) ...`, the code runs, but no data is shipped to 
browser.  Ctrl-U shows empty page after the accept and sendTo 
calls.


If this is the wrong place for this kind of info note, I'll 
gladly move to or redo the post in a more appropriate spot.


Have good, make well


For fun, and executable lame joke

2021-05-30 Thread btiffin via Digitalmars-d-learn

Here's the short version

`["hip", "hip"]`  the hip hip array (or hooray as suits the lame 
joke).


Here's some executable code

```d
void array(string[] a) {
   import std.stdio : writeln;
   foreach(t; a) writeln(t);
}
void main() { D(); }

void
   D() { ["hip", "hip"].array; }
```

Is there a way to make that less codey, more jokey, *but still 
compile and execute the hip hip array*?


Have good,
Blue


Re: wanting to try a GUI toolkit: needing some advice on which one to choose

2021-05-30 Thread btiffin via Digitalmars-d-learn

On Thursday, 27 May 2021 at 01:17:44 UTC, someone wrote:

Any comments are welcomed, even any comments regarding anyone 
experience with GUI development within D, no matter whether the 
answer would be relevant to my specific question seeking a 
choice or not.


Along that tack, and as an informational tidbit, if you (any one, 
not just to someone) ever find yourself with a desperate need for 
a gui, but lack development tooling, there is always the 
messaging interface to GTK, GTK-Server, by Peter van Eerten, 
author of BaCon.


gtk-server is GTK by proxy.  Send messages, get GUIs.  Not fast, 
but readily available to hundreds of programming languages.


https://gtk-server.org/intro.html

And for anyone interested in how some geniuses create programming 
environments, BaCon is a BASIC to C converter.  Ships as a shell 
script, that reads itself to self-host a C codegen pass, to 
produce a native compiled bacon compiler.  Self hosted as a shell 
script.  *That alone should warrant a trophy.*  And Peter has 
coded the shell script so that it can actually run as the 
converter compiler for BASIC, or convert itself to C to native 
bacon.


http://basic-converter.org/ worthy of a read.

Have good, make well,
Blue


Offtopic: A tune for vibers, maybe

2021-05-30 Thread btiffin via Digitalmars-d-learn

21 Pilots, Outside

https://www.youtube.com/watch?v=m2w6GkV3U6Q

On note, "Kids'll try to take my vibes.  Or am I on the outside?"
Outro: "Little did they know, they can't touch me.  I'm VIBIN', 
VIBIN'."


Have good, make well,
Blue


Re: wanting to try a GUI toolkit: needing some advice on which one to choose

2021-05-29 Thread btiffin via Digitalmars-d-learn

On Thursday, 27 May 2021 at 16:49:41 UTC, Dejan Lekic wrote:

[...]


I humbly believe the most complete one is GtKD.

https://gtkdcoding.com/
https://gtkd.org

We all wish there was a STANDARD D GUI library out there, but 
that is a huge effort one or two individuals can't do by 
themselves (that is why all such efforts failed in the past)...


Agree about GTK and completeness (though D explorations still 
counted under 100 hours).


Will politely disagree about 1 or 2 can't do by themselves...  
Yeah, yeah they can.  :-)  Magic people.  Ok, people with skills 
so advanced (relative to the rest of us) as to be 
indistinguishable from magic.


REBOL, Carl on REBOL dialects for layout with a partner coding 
view graphic drivers.  For example.  It can happen, and does 
happen.  Super star doers.


Rare, yes.  Happens.  There is hope.  And yes, agree, lots of 
fail, *but not all, fail*.


Have good, make well,
Blue


Re: wanting to try a GUI toolkit: needing some advice on which one to choose

2021-05-27 Thread btiffin via Digitalmars-d-learn

On Thursday, 27 May 2021 at 01:17:44 UTC, someone wrote:

Yes, I know this is a question lacking a straightforward answer.

I'm only on a third serious with D day, but I want to take a kick 
at wrapping libAgar now.


libagar is a nice little framework.  But, it's C still (and Ada, 
Perl, COBOL), not D yet.  Will see how it goes.


Very cross platform, the Uniike (unixlike, sans tm) systems, 
nintendo, c64, but that's microagar.  Developed on a BSD system.


http://libagar.org/


Re: coreutils with D trials, wc, binary vs well formed utf

2021-05-25 Thread btiffin via Digitalmars-d-learn

On Tuesday, 25 May 2021 at 18:03:29 UTC, Imperatorn wrote:

Nice that you're also hopeful about the future for D ☀️ I also 
think slow steady growth is the best.


We just need to focus and D will be great 


D is already great. It just needs to take over (a larger chunk 
of) the world. ;-)


Now for some more noob level questions.  I modified Robert's 
entry to include totals.


(Gee, I hope I'm not stepping into copyright issues - the code 
has no explicit license, and I've haven't yet figured out what 
the default assumption is in the dlang.org terms of service.  If 
this is stepping out of bounds, I'll edit out the copied sources).


```d
/++ wc word counting +/
/+ Tectonics: gdc -o wc wc.d +/
module wc;

import std.stdio : writefln, File;
import std.algorithm : map, fold, splitter;
import std.range : walkLength;
import std.typecons : Yes;
import std.uni : byCodePoint;

struct Line {
   size_t chars;
   size_t words;
}

struct Output {
   size_t lines;
   size_t words;
   size_t chars;
}

Output combine(Output a, Line b) pure nothrow {
   return Output(a.lines + 1, a.words + b.words, a.chars + 
b.chars);

}

//Line toLine(char[] l) pure {
//   return Line(l.byCodePoint.walkLength, l.splitter.walkLength);
//}

Line toLine(char[] l) pure {
   import std.array : array;
   import std.algorithm : filter;
   import std.utf : byDchar, replacementDchar;

   auto valid = l.byDchar.filter!(c => c!=replacementDchar).array;
   return Line(valid.byCodePoint.walkLength, 
valid.splitter.walkLength);

}

void main(string[] args) {
   Output tot;

   foreach (int i, string fn; args) {
   if (i == 0) continue;
   auto f = File(fn);
   Output o = f
 .byLine(Yes.keepTerminator)
 .map!(l => toLine(l))
 .fold!(combine)(Output(0, 0, 0));

   writefln!"%7u %7u %11u %s"(o.lines, o.words, o.chars, fn);

   tot.lines += o.lines;
   tot.words += o.words;
   tot.chars += o.chars;
   }
   if (args.length > 2) {
   writefln!"%7u %7u %11u %s"(tot.lines, tot.words, 
tot.chars, "total");

   }
}
```

This is no longer a branchless piece of code, but still a joy to 
toyol with.


Oh, and a by the by.  I use a portmanteau of *toy* and *tool* for 
*toyol*.  A toy tool toiled for the joy of it. *because inventing 
words is fun*.


I also like to add a Tectonics line to sources; the commands used 
to build given the source listing, using this rather archaic 
definition of tectonics from the dict databases.


```text
"Tectonics" gcide "The Collaborative International Dictionary of 
English v.0.48"

Tectonics \Tec*ton"ics\, n.
1. The science, or the art, by which implements, vessels,
dwellings, or other edifices, are constructed, both
agreeably to the end for which they are designed, and in
conformity with artistic sentiments and ideas.
[1913 Webster]
```

One last by the by, I usually go by the nickname Bluey, and sign 
as Blue.


The question.  Is there a more concise D idiom for adding the 
Output struct fields into the total?  Or is it three separate 
statements?


Ok, one more question.  Can the foreach loop that scans the 
argument list be folded into a chain somehow?  *I'm not there yet 
in D learning, but might as well try and choose an idiomatic 
path, if possible*.


Have good,
Blue


Re: coreutils with D trials, wc, binary vs well formed utf

2021-05-24 Thread btiffin via Digitalmars-d-learn

Thanks for these hints.

I'm new here, but not so much to programming.  Been following D 
since, well 2007 or 8.  Awaiting the GCCing to gel.  Nice.  Still 
a little rough on Ubuntu 18.04, dub package seems to want ldc and 
dmd from dlang borks with a segfault in start (which is probably 
a my end problem and linker searches).  The pkg-config settings 
pass -L-l, and I'm not sure gdc is overly friendly with that.  
gtkD in Ubuntu is smoother with ldc too, but tis ok.  Choice is 
good, and having three installations is still pretty easy to 
explore.


Looking forward to more bragging about D.  An early integration 
trial with GnuCOBOL (2015ish) looked promising.  New ease of use 
is making that even more promising.


And a note to contributors.  Nicely done.  With some 10 million 
programmers, and what? 750 million excel macro writers assuming a 
life time average of a line of code an hour for professional 
programmers, we live in a field that evolves at 4ish million 
hours an hour.  Nice to see how a few of those hours can really 
make a difference.


Have good.



coreutils with D trials, wc, binary vs well formed utf

2021-05-24 Thread btiffin via Digitalmars-d-learn

Hello,

New here. A little background.  Old guy, program for both work 
and recreation, GNU maintainer for the GnuCOBOL package; written 
in C, compiles COBOL via C intermediates.  Fell into the role of 
maintainer mainly due to being a documentation writer and early 
on cheerleader.  Experienced in quite a few programming 
languages, with a "10,000ish hours in" definition of expert 
expertise in C, Forth and COBOL.


Assuming that with gdc in GCC mainline now that D usage will 
continue to grow.  Also of the opinion that slow, long tail 
growth is the best kind of growth.  Not hype, not marketing, but 
adoption due to worthiness and merit.  That is the current 
headspace.  Want D to succeed, can't point to a specific why, 
just feel deep down that it should succeed and have an open ended 
relevant life span.  Thanks, Walter, Andrei, Iain, Ari, et al...


Just bumped into 
https://dlang.org/blog/2020/01/28/wc-in-d-712-characters-without-a-single-branch/


Way cool.  Then bumped into this:

prompt$ ./wc *
std.utf.UTFException@/usr/lib/gcc/i686-linux-gnu/11/include/d/std/utf.d(1380): 
Invalid UTF-8 sequence (at index 1)

That was from an a.out file in the directory.  Early days, very 
limited D, so answers of "just set ...", will fly over head, 
actual gdc command lines and noob jargon will sink in faster at 
this point.  Is there a(n easy-ish) way to fix up that wc.d 
source in the blog to fallback to byte stream mode when a utf-8 
reader fails an encoding?


Have good, make well,
Brian