July 31, 2022

On Saturday, 30 July 2022 at 23:40:44 UTC, pascal111 wrote:

>

Provide me a free solution better than code::blocks with available gdc compiler I found.

>

SDB@79

I don't know if's "better" but there is Visual Studio Code and IntelliJ IDEA for example.

Yeah ctrl+v doesn't work on XTERM, the middle mouse button should. I found this in the wild:

>

is super weird but in xterm you can copy just by selecting the text, the text is going to get copied to xwindows clipboard not to gnome one so ctrl+v or menus are not going to work for pasting you need to use the middle button of the mouse and in some windows shift+insert uses to work too.

so: select the text in the terminal keep it open go to any text editor or the browser and press the middle button to paste

if you are on a mac you can simulate the middle button pressing the touchpad with 3 fingers and if you have a 2 buttons mouse you can simulate the middle one pressing both at the same time.

A probably more sane option would be to configure codeblocks to use gnome-terminal instead of xterm, in settings -> environment -> general settings you can change it but it seems to close as soon as you try to launch the app

If that doesn't work you have to try another keyboard layout or such configuration or bind the function to another key if your middle mouse button is not present or is not recognized properly.

July 31, 2022

On Sunday, 31 July 2022 at 00:58:47 UTC, pascal111 wrote:

>

Another version of the program:

https://github.com/pascal111-fra/D/blob/main/proj04.d

I have a few more suggestions for you; Among them the first is on the following sample:

  auto sentence_x = "she has six oxen";
  auto noNeedTrim = sentence_x.d_strtok(" ");

  foreach(token; noNeedTrim)
  {
    //token = token.strrtrim;
    if(token.canFind("s"))
    {
      assert(token.length == 3);
    } else token.writeln; // oxen
  }

But if it's because of typos, it's ok. Lets continue...

Why are you using const for strings? After all, they are protected by immutable. Moreover, since you do not use refs, copies are taken in every function and also you have created extra copy for results.

enum str = "five hundred twelve";
auto test = str.strltirim;
assert(test == "five hundred twelve");

string strltrim(const string ch)
{
    string ch_cpy=ch;

    while(ch_cpy.strleft(1)==" ")
        ch_cpy=ch_cpy.strdel(0,1);

    return ch_cpy;
}

There are also nicer ways to delete spaces in a text. Have you ever tried using the default arguments and auto?


//string[] d_strtok(const string ch, const string delim)
auto d_strtok(string ch, string delim = " ")//*/
{
    import std.functional : not; // [bonus]
    string[] tokens = ch.
    splitter!(c => delim.canFind(c)).
    filter!(not!empty).array;

    return tokens;
}

Functions may optionally define default arguments. This avoids the tedious work of declaring redundant overloads.

[bonus] And using selective imports where necessary is also a nice feature of D.

SDB@79

July 31, 2022

On Sunday, 31 July 2022 at 07:43:06 UTC, Salih Dincer wrote:

>

Why are you using const for strings? After all, they are protected by immutable. Moreover, since you do not use refs, copies are taken in every function and also you have created extra copy for results.

Note sure if I'm misunderstanding, but: D does not copy strings on value passing, because they're inherently reference types.

You can think of a string (or any array) as a struct { size_t length; T* ptr; } combined with a bunch of syntax magic.

July 31, 2022

On Sunday, 31 July 2022 at 07:43:06 UTC, Salih Dincer wrote:

>

On Sunday, 31 July 2022 at 00:58:47 UTC, pascal111 wrote:

>

Another version of the program:

https://github.com/pascal111-fra/D/blob/main/proj04.d

I have a few more suggestions for you; Among them the first is on the following sample:

  auto sentence_x = "she has six oxen";
  auto noNeedTrim = sentence_x.d_strtok(" ");

  foreach(token; noNeedTrim)
  {
    //token = token.strrtrim;
    if(token.canFind("s"))
    {
      assert(token.length == 3);
    } else token.writeln; // oxen
  }

I don't know how "assert" works, if you explained it I'll be able to get the idea of your suggestion to apply the appropriate changes on my code.

>

But if it's because of typos, it's ok. Lets continue...

I think "typos" are mistakes of typing? I'm not sure.

>

Why are you using const for strings? After all, they are protected by immutable. Moreover, since you do not use refs, copies are taken in every function and also you have created extra copy for results.

enum str = "five hundred twelve";
auto test = str.strltirim;
assert(test == "five hundred twelve");

string strltrim(const string ch)
{
    string ch_cpy=ch;

    while(ch_cpy.strleft(1)==" ")
        ch_cpy=ch_cpy.strdel(0,1);

    return ch_cpy;
}

There are also nicer ways to delete spaces in a text. Have you ever tried using the default arguments and auto?


//string[] d_strtok(const string ch, const string delim)
auto d_strtok(string ch, string delim = " ")//*/
{
    import std.functional : not; // [bonus]
    string[] tokens = ch.
    splitter!(c => delim.canFind(c)).
    filter!(not!empty).array;

    return tokens;
}

Functions may optionally define default arguments. This avoids the tedious work of declaring redundant overloads.

I think you are right, I'll add a default argument in "d_strtok".

[bonus] And using selective imports where necessary is also a nice feature of D.

Beginners are reading my library, so I have some limitations to provide 'em understood code, so if I'll apply a new D syntax, I'll explain it in a video before providing the beginners the code with the new syntax.

>

SDB@79

July 31, 2022

On Sunday, 31 July 2022 at 14:52:03 UTC, FeepingCreature wrote:

>

Note sure if I'm misunderstanding, but: D does not copy strings on value passing, because they're inherently reference types.

You can think of a string (or any array) as a struct { size_t length; T* ptr; } combined with a bunch of syntax magic.

You got it right, but I didn't explain it right. I think you are right. How could I forget! String is actually a struct, embedded in the language. For example, it has members like .dub, .ptr, capacity and .length (get/set).

Of course we should get a copy with .dub to avoid side effects. But now that I've tested it, I haven't seen a problem with split() and sort() . Okay, yes sort() can have side effects, for example nums is affected by this. I also had to use to!(dchar[]) because of the UTF:

auto sortStr(string E)(string str) {
  import std.algorithm, std.conv;
  return str.to!(dchar[]).sort!E;
}

auto splitStr(string E)(string str) {
  import std.string;
  return str.split!string(E);
}

auto sortArray(T)(T[] arr)
{
  import std.algorithm;
  return arr.sort;
}

void main()
{
  import std.stdio : writeln;

  string test = "alphabet";
  auto nums = [ 1, 9, 4, 0, 3 ];

  test.sortStr!"a > b".writeln;
  assert(test == "alphabet");

  test.splitStr!"a".writeln;
  assert(test == "alphabet");

  test.sortStr!"a < b".writeln;
  assert(test == "alphabet");

  nums.sortArray.writeln;
  assert(nums == [0, 1, 3, 4, 9]);
}
/* Prints:
tplhebaa
["", "lph", "bet"]
aabehlpt
[0, 1, 3, 4, 9]
*/

In conclusion, one has to be careful, but D is a reliable language.

SDB@79

July 31, 2022

On Sunday, 31 July 2022 at 15:01:21 UTC, pascal111 wrote:

>

I don't know how "assert" works, if you explained it I'll be able to get the idea of your suggestion to apply the appropriate changes on my code.

// This code runs forever:

  string str;
  assert(str is null);

  str = "test";
  assert(str !is null);
  assert(str.length >= 1);

  str = "";
  assert(str !is null);
  assert(str.length == 0);

  int count;
  assert(count == 0); // true

  assert(true);
  while(true) { // endless loop }

// This code runs in a little bit:

  count = 100;
  //assert(count); /* or:
  assert(count > 1); //*/

  while(--count) { }
  assert(count); // false and assert error

> >

But if it's because of typos, it's ok. Lets continue...

I think "typos" are mistakes of typing? I'm not sure.

Yes, typos == "mistakes of typing" for example:

  void main()
{
  import std.string : split;
  auto test = "I hav e a car  s";
  auto result = split!string(test, " ");
  // ["I", "hav", "e", "a", "car", "", "s"]

  auto tilly = result[2]; // extra character
  auto solecism = result[3]; // car is plural
  auto doubled = result[5]; // doubled separetor

  import std.stdio : writeln;
  writeln(tilly, solecism, doubled);
}

SDB@79

July 31, 2022

On Sunday, 31 July 2022 at 17:03:59 UTC, Salih Dincer wrote:

>

On Sunday, 31 July 2022 at 15:01:21 UTC, pascal111 wrote:

>

I don't know how "assert" works, if you explained it I'll be able to get the idea of your suggestion to apply the appropriate changes on my code.

// This code runs forever:

  string str;
  assert(str is null);

  str = "test";
  assert(str !is null);
  assert(str.length >= 1);

  str = "";
  assert(str !is null);
  assert(str.length == 0);

  int count;
  assert(count == 0); // true

  assert(true);
  while(true) { // endless loop }

// This code runs in a little bit:

  count = 100;
  //assert(count); /* or:
  assert(count > 1); //*/

  while(--count) { }
  assert(count); // false and assert error

You got the attention by the good understanding of D grammar. I think I got the idea of "assert".

>

SDB@79

1 2
Next ›   Last »