Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-14 Thread Виталий Фадеев via Digitalmars-d-learn
On Tuesday, 15 December 2020 at 05:10:27 UTC, Виталий Фадеев 
wrote:
On Tuesday, 15 December 2020 at 05:04:46 UTC, Виталий Фадеев 
wrote:
On Monday, 14 December 2020 at 16:19:18 UTC, Adam D. Ruppe 
wrote:
On Monday, 14 December 2020 at 16:11:16 UTC, Jacob Carlborg 
wrote:
Or you can call it `rgba`. It seems to be what Wikipedia 
prefers [1].


The ordering here tends to reflect the bytes. So argb puts 
the alpha byte first in the array whereas rgba puts red first.


But there's other ways here including just saying argb(...) 
or foo.as!"argb" or whatever well.


I think about .rgba.

Yes. The ordering! The logic.

ARGB = .argb

Thanks!


0x00AABBCC.argb

0x00AABBCC - is ARGB value
.argb  - is unit

...in my logic.

120.px
120   - is Pixel value
.px   - is unit

...in my logic.

100.percent
100   - is Percent value
.percent  - is unit

...in my logic.
)

Thanks!


This concept:
class X
{
this()
{
props.fontFace   = "Ubuntu Mono";
props.fontSize   = 24.px;
props.lineHeight = 15.px;
props.color  = 0xFF;
props.backColor  = 0x22;
// or
props.color  = 0xFF.rgb;
props.backColor  = 0x22.rgb;
// or
props.color  = 0x88FF.argb;
props.backColor  = 0x8822.argb;
}
}

Thanks!
)


Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-14 Thread Виталий Фадеев via Digitalmars-d-learn
On Tuesday, 15 December 2020 at 05:04:46 UTC, Виталий Фадеев 
wrote:
On Monday, 14 December 2020 at 16:19:18 UTC, Adam D. Ruppe 
wrote:
On Monday, 14 December 2020 at 16:11:16 UTC, Jacob Carlborg 
wrote:
Or you can call it `rgba`. It seems to be what Wikipedia 
prefers [1].


The ordering here tends to reflect the bytes. So argb puts the 
alpha byte first in the array whereas rgba puts red first.


But there's other ways here including just saying argb(...) or 
foo.as!"argb" or whatever well.


I think about .rgba.

Yes. The ordering! The logic.

ARGB = .argb

Thanks!


0x00AABBCC.argb

0x00AABBCC - is ARGB value
.argb  - is unit

...in my logic.

120.px
120   - is Pixel value
.px   - is unit

...in my logic.

100.percent
100   - is Percent value
.percent  - is unit

...in my logic.
)

Thanks!



Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-14 Thread Виталий Фадеев via Digitalmars-d-learn

On Monday, 14 December 2020 at 16:19:18 UTC, Adam D. Ruppe wrote:
On Monday, 14 December 2020 at 16:11:16 UTC, Jacob Carlborg 
wrote:
Or you can call it `rgba`. It seems to be what Wikipedia 
prefers [1].


The ordering here tends to reflect the bytes. So argb puts the 
alpha byte first in the array whereas rgba puts red first.


But there's other ways here including just saying argb(...) or 
foo.as!"argb" or whatever well.


I think about .rgba.

Yes. The ordering! The logic.

ARGB = .argb

Thanks!



Can ddocs link functions automatically?

2020-12-14 Thread Jack via Digitalmars-d-learn

let's say I have a comment like this:

/
call foo.baa() to validate operation
/

where foo is the module and baa the function, can ddocs generate 
a link to the html file where is this defined automatically or do 
I have to hard-code those links like this?


/
call [foo.baa()](foo.html#baa 'foo.baa()') to validate operation
/



Re: Can I use dub to generate docs?

2020-12-14 Thread Jack via Digitalmars-d-learn

Thank you guys, worked like a charm


Re: How to check that function gets ref parameter?

2020-12-14 Thread Andrey Zherikov via Digitalmars-d-learn

On Sunday, 13 December 2020 at 19:49:35 UTC, Basile B. wrote:
On Sunday, 13 December 2020 at 16:41:06 UTC, Andrey Zherikov 
wrote:
You use the wrong traits, try ParameterStorageClassTuple 
instead:


  void f(int) {}
  void g(ref int) {}
  import std.traits : ParameterStorageClass, 
ParameterStorageClassTuple;
  static assert(ParameterStorageClassTuple!g[0] == 
ParameterStorageClass.ref_);
  static assert(ParameterStorageClassTuple!f[0] != 
ParameterStorageClass.ref_);


This works. Thanks!


Re: Is there a standard function that combines take() and popFrontExactly()

2020-12-14 Thread realhet via Digitalmars-d-learn

On Monday, 14 December 2020 at 14:16:41 UTC, Dukc wrote:

On Friday, 11 December 2020 at 19:07:23 UTC, realhet wrote:
I've just made this unicode wordreplacer function working, but 
It seems not too nice and functional-ish.

Are there ways to make it more simple?



To answer the title, yes there is:



Thanks for ideas!

Yesterday I ended up making this helper funct:
auto fetchFrontExactly(R)(ref R r, size_t n) if(isInputRange!R){
auto res = r.takeExactly(n);
r.popFrontExactly(n);
return res;
}

Now I leaned from you: refRange and take-s ability to pop 
elements from a refRange.

That's what I was needed!

Now the 2 aproach looks like:

string replaceWords(alias fun = isWordChar)(string str, string 
from, string to){

if(1){
auto fetchAndReplace(Tuple!(bool, uint) p){
auto act = refRange(&str).take(p[1]).text;
return p[0] && act==from ? to : act;
}
return str.map!fun
  .group
  .map!fetchAndReplace
  .join;
}else{
string res;
foreach(isWord, len; str.map!fun.group){
auto act = (&str).refRange.take(len).text;
res ~= (isWord && act==from ? to : act);
}
return(res);
}
}

They are the same thing, but the first looks nicer because it is 
a processing pipe with the state modifying thing extracted to a 
named function (so that's makes the pipe more understandable).
However in the foreach version I can have meaningful parameter 
names: (isWord, len) instead of a tuple.


I don't want to do functional programming just for itself. I'm 
just learning it, and want to understand it better. I already 
found a lot of good uses of it for my tasks and I still discover 
a lot of cool stuff.


Thanks again!


Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-14 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 14 December 2020 at 16:11:16 UTC, Jacob Carlborg wrote:
Or you can call it `rgba`. It seems to be what Wikipedia 
prefers [1].


The ordering here tends to reflect the bytes. So argb puts the 
alpha byte first in the array whereas rgba puts red first.


But there's other ways here including just saying argb(...) or 
foo.as!"argb" or whatever well.


Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-14 Thread Jacob Carlborg via Digitalmars-d-learn

On Monday, 14 December 2020 at 05:51:28 UTC, Виталий Фадеев wrote:


It's parsing the `.a` in `.argb` as part of the number:

auto color = 0x00AABBCC.a rgb; // what the compiler sees

You can fix it with parentheses:

auto color = (0x00AABBCC).argb;


Thanks!

It is not perfect, but also beauty!


Or you can call it `rgba`. It seems to be what Wikipedia prefers 
[1].


[1] https://en.wikipedia.org/wiki/RGBA_color_model

--
/Jacob Carlborg


Re: closures + struct: Error: forward reference to inferred return type of function call

2020-12-14 Thread ddcovery via Digitalmars-d-learn

On Monday, 14 December 2020 at 12:22:26 UTC, ddcovery wrote:

int opCmp(Number other){
  return _value - other.value;
};

Correction:

bool opEquals(Number other){
  return _value == other.value;
};


Re: Is there a standard function that combines take() and popFrontExactly()

2020-12-14 Thread Dukc via Digitalmars-d-learn

On Friday, 11 December 2020 at 19:07:23 UTC, realhet wrote:
I've just made this unicode wordreplacer function working, but 
It seems not too nice and functional-ish.

Are there ways to make it more simple?



To answer the title, yes there is:

```
foreach(isWord, len; str.map!fun.group){
   auto act = (&src).refRange.take(len).text;

   res.put(isWord && act==from ? to : act);
}
```

But personally I think it does not pay to try to be more 
functional than what this snippet already is. The most important 
thing is that the program is functional on the high level. This 
means avoiding globals and static variables (`pure` may help), 
big monolithic functions, god classes and functions which get 
needless info by their parameters. Being functional in the low 
level is secondary and not always worth it.


closures + struct: Error: forward reference to inferred return type of function call

2020-12-14 Thread ddcovery via Digitalmars-d-learn
In this example, I try to use D Voldemore (fantastic) 
functionallity to implement a pattern usually used in javascript.


Basically, a function closure represents the state, and the 
methods to access this state are returned in the form of union 
(union has not state itself).


void main(){
  assert(number(10).next.value==11 );
  assert(zero()==number(0) );
  assert(zero()==number(1).previous );
  auto ten = number(10);
  auto nine = ten.previous;
  assert(nine == number(9));
}

auto number(int _value=0){
  struct Number {
int value() {
  return _value;
};
Number next() {
  return number(_value+1);
};
Number previous(){
  return number(_value-1);
};
int opCmp(Number other){
  return _value - other.value;
};
  }

  return Number();
}

auto zero() {
  return number(0);
}

Problem is that Union methods needs to call it's containing 
function and compiler doesn't accept it:


main.d(16): Error: forward reference to inferred return type of 
function call number(_value + 1)
main.d(19): Error: forward reference to inferred return type of 
function call number(_value - 1)


I know there is another ways to solve this problem easily 
(without closures), but I was really curious about if it was 
possible.





Re: Can I use dub to generate docs?

2020-12-14 Thread Basile B. via Digitalmars-d-learn

On Monday, 14 December 2020 at 02:54:12 UTC, Jack wrote:

like dmd's -D flag?


you can try

   $ dub run harbored-mod -- $(find -iname *.d)

That will generate doc for all d source in the current working 
directory.