Why Dlang use parsing expression grammar (PEG) parser not BNF?

2019-10-31 Thread lili via Digitalmars-d-learn

Hi:
   I want implementation Lua on D, I find that a PEG parser 
https://github.com/PhilippeSigaud/Pegged

   why do not use BNF parser. Is PEG better than BNF?


Is there any writeln like functions without GC?

2019-10-30 Thread lili via Digitalmars-d-learn

Hi:
   why writeln need GC?


Re: About the in expression, Why can't use with array.

2019-10-25 Thread lili via Digitalmars-d-learn

On Friday, 25 October 2019 at 21:06:53 UTC, IGotD- wrote:

On Friday, 25 October 2019 at 20:44:18 UTC, Dennis wrote:

On Friday, 25 October 2019 at 19:49:05 UTC, Ali Çehreli wrote:
I'm still not completely sold on the whole idea though 
because it's not a clear win.


Do others see other advantages in other places like 
templates? For example, could templates really be written 
generically for arrays and associative arrays?


I'm personally not concerned about generic code.
- The semantics of `in` aren't very well defined anyways.
- Those who write templates like that (hopefully) know what 
they're doing, they'll figure it out  ;)
- I can't think of situations where you actually want to write 
code that generically works on both arrays and associative 
arrays like that. (Though if anyone knows one, please share, 
I'm interested.)


I'm more concerned about the repeated reports of users being 
surprised that `in` doesn't work like they expect. In Python, 
the expression `3 in [2, 3, 4]` returns a boolean, and in D 
you can do `bool b = 15 in iota(10, 20)` because the operator 
is overloaded in Phobos for iota; But as far as actual 
language support, `in` is only defined for associative arrays:


https://dlang.org/spec/expression.html#InExpression

It returns a pointer which can be used in an if-statement, but 
also to read/modify the value. So should `in` on arrays do the 
same? It would be consistent, but usage of raw pointers is 
discouraged with the advent of scope and ref etc. Also you 
can't implicitly convert a pointer to a boolean.
Should it be a boolean then? That means part of the result of 
the linear search is discarded, making `in` less flexible.
So maybe we should leave it for now, and put a small 
explanation in the error message.


I'm also not so fond of that "in" operator returns a pointer 
which is bad fit for arrays and possibly many other container 
algorithms as well. I think the best would be that it would 
return an optional of type T and T would be user defined. For 
associative arrays, a pointer or a reference to the element. 
For arrays the index of that element would suitable. Also 
overloading would be nice so that "in" operator could return 
several possible optional types, not sure if that would be 
possible though.
I argee with your talk, lanuage designer need keep consistent 
that the 'in' semantics. or not support 'in' key word. Don't 
assumption that how user use it.




Can not understand this code.

2019-10-25 Thread lili via Digitalmars-d-learn

Hi:
What is the alias Min = xxx mean? why need defined a alias Min in 
Min template?

```
template Min(alias pred, Args...)
if (Args.length > 0 && __traits(isTemplate, pred))
{
static if (Args.length == 1)
{
alias Min = Alias!(Args[0]);
}
else static if (isLess!(pred, Args[1], Args[0]))
{
alias Min = Min!(pred, Args[1], Args[2 .. $]);
}
else
{
alias Min = Min!(pred, Args[0], Args[2 .. $]);
}
}

```


Re: About the in expression, Why can't use with array.

2019-10-24 Thread lili via Digitalmars-d-learn
On Thursday, 24 October 2019 at 22:40:31 UTC, Jonathan M Davis 
wrote:
On Thursday, October 24, 2019 7:04:56 AM MDT Paul Backus via 
Digitalmars-d- learn wrote:

On Thursday, 24 October 2019 at 12:58:11 UTC, lili wrote:
> Hi:
>In Dlang where is strange design. The in expression can 
> only

>
> use to associative array, why array can not use in 
> expression.


Checking for the presence of an item in an array requires a 
linear search. You can do it with 
std.algorithm.searching.canFind:


https://dlang.org/phobos/std_algorithm_searching.html#.canFind


In particular, the reason that linear search is considered 
unacceptable for
in is so that generic code can rely on its performance. The 
idea is that
types shouldn't implement the in operator unless they can do so 
with
O(log n) or better (O(log n) being what it costs to get to an 
item in a
balanced binary tree like a red-black tree). That way, when you 
calculate
the complexity of any algorithm using in, you can assume that 
it's O(log n)
at worst. Having it be O(n) instead (like it would be for an 
array) would
drastically increase the complexity of the algorithm and make 
it take much
longer when processing a large number of items. And the 
standard library
provides functions like canFind or find for finding elements in 
an array, so
having in work with arrays wouldn't add any functionality. It 
would
basically just change the syntax you'd use for finding an 
element in an

array.

- Jonathan M Davis


 This reason somewhat farfetched, Think about that if this reason 
is right, the operator overload can not use。 because same 
operator on different type expression same mean but different 
implementation and complexity。 so why operator overload can don't 
care about implementation but 'in' operator need。




About the in expression, Why can't use with array.

2019-10-24 Thread lili via Digitalmars-d-learn

Hi:
   In Dlang where is strange design. The in expression can only 
use to associative array, why array can not use in expression.


What do you think about About C++20 Concepts?

2019-10-22 Thread lili via Digitalmars-d-learn

Hi:
In C++20 Concepts is great idear. but I thinks it is too 
difficult to write.

I like Rust traits simple and elegancy.


Why dynamic array is InputRange but static array not.

2019-09-24 Thread lili via Digitalmars-d-learn

Hi:
  in phobos/std/range/primitives.d has this code
 ```
   static assert( isInputRange!(int[]));
   static assert( isInputRange!(char[]));
   static assert(!isInputRange!(char[4]));
   static assert( isInputRange!(inout(int)[]));
```
 but the dynamic array and static array neither not has 
popFront/front/empty.

https://dlang.org/spec/arrays.html#array-properties properties


what is the mean that call function start with a dot.

2019-09-21 Thread lili via Digitalmars-d-learn

Hi:
   yesterday I saw some d code, where is an .fn() call syntax, 
what is it mean.


Re: Is there has an pdf document for Phobos.

2019-09-04 Thread lili via Digitalmars-d-learn

On Wednesday, 4 September 2019 at 04:21:10 UTC, Mike Parker wrote:

On Wednesday, 4 September 2019 at 03:07:18 UTC, lili wrote:

Hi:
   For some reason it too slow that some times i visited 
dlang.org, Can admin make a pdf document for download.


Documentation is installed with the compiler.


Thanks


Re: Is there has an pdf document for Phobos.

2019-09-04 Thread lili via Digitalmars-d-learn

On Wednesday, 4 September 2019 at 04:21:10 UTC, Mike Parker wrote:

On Wednesday, 4 September 2019 at 03:07:18 UTC, lili wrote:

Hi:
   For some reason it too slow that some times i visited 
dlang.org, Can admin make a pdf document for download.


Documentation is installed with the compiler.


How to open it?


Is there has an pdf document for Phobos.

2019-09-03 Thread lili via Digitalmars-d-learn

Hi:
   For some reason it too slow that some times i visited 
dlang.org, Can admin make a pdf document for download.


Re: How stdin.readf ignore space char?

2019-09-03 Thread lili via Digitalmars-d-learn

On Tuesday, 3 September 2019 at 13:21:16 UTC, a11e99z wrote:

On Tuesday, 3 September 2019 at 12:55:29 UTC, lili wrote:

Hi guys:

   input is two line, first line is a number n and second line 
is n float point number,

e.g. 3
 1.1 2.2 3.3
how use stdin.readf get all number.


https://dlang.org/library/std/stdio/readf.html
see example


string d = "3.43.3 ";
double a;
double b;

//formattedRead(d,"%f %f", , );

d.readf!" %s %s"(a,b);//hug
writeln(a,b);



How stdin.readf ignore space char?

2019-09-03 Thread lili via Digitalmars-d-learn

Hi guys:

   input is two line, first line is a number n and second line is 
n float point number,

e.g. 3
 1.1 2.2 3.3
how use stdin.readf get all number. i code below but not work 
well.


int n;
stdin.readf!"%d\n"(n);
writeln("read n:",n);

foreach (i; 0..n)
{
double x;
stdin.readf!"%f"(x); //only return first number, 
why?

writeln(x);
}



Re: How to learn Phobos,Phbos hard to used for me.

2019-08-28 Thread lili via Digitalmars-d-learn

On Wednesday, 28 August 2019 at 12:32:59 UTC, Andre Pany wrote:

On Wednesday, 28 August 2019 at 11:34:27 UTC, lili wrote:

Hi:
Masters who can write a book for Phbos, the dlang doc not 
friendly to beginner.


There are 2 articles which I really like:

http://nomad.uk.net/articles/hidden-treasure-in-the-d-standard-library.html

http://nomad.uk.net/articles/more-hidden-treasure-in-the-d-standard-library.html

Also this book is a good starting point:
https://ddili.org/ders/d.en/index.html

Are you interested in some specific parts of Phobos?

Kind regards
Andre


Thanks, In'D is great book, not not cover Phobos, I relay need 
some document for containers, range.




How to learn Phobos,Phbos hard to used for me.

2019-08-28 Thread lili via Digitalmars-d-learn

Hi:
Masters who can write a book for Phbos, the dlang doc not 
friendly to beginner.


Re: [Help!] Use two different assembly symbol in D, but they are same address.

2019-08-25 Thread lili via Digitalmars-d-learn

On Saturday, 24 August 2019 at 12:55:57 UTC, a11e99z wrote:

On Saturday, 24 August 2019 at 12:16:34 UTC, lili wrote:

On Saturday, 24 August 2019 at 12:09:19 UTC, a11e99z wrote:

On Saturday, 24 August 2019 at 11:53:01 UTC, lili wrote:

 [...]


resb 8
just reserving 8 bytes not initializing it.
probably u compare some garbage. sometimes it equals, 
sometimes not.

no?


I write wrong, not  if (_vga_x == _vga_y) but if (&_vga_x == 
&_vga_y)


try to do next:
add funtion in asm that returns real addresses to vga_x,y
extern(C) void asmVgas( int** px, int** py)
call it
int *px, *py;
asmVgas( , );
writefln( "%s=%s,%s=%s",px, &_vga_x,py, &_vga_y);
and see result


I followed your suggest, call asm_fn in d function. it return 
address not 0 but is a correct

address same as the var address show in link map file.
when a try define a __shared int xx, the  also 0.
after linked all variables address is 0 that in .bss segment.
do you know why occur this?

[global asm_fn]
asm_fn:
mov rax, p2_table
ret



Re: [Help!] Use two different assembly symbol in D, but they are same address.

2019-08-24 Thread lili via Digitalmars-d-learn

On Saturday, 24 August 2019 at 12:09:19 UTC, a11e99z wrote:

On Saturday, 24 August 2019 at 11:53:01 UTC, lili wrote:

 [...]


resb 8
just reserving 8 bytes not initializing it.
probably u compare some garbage. sometimes it equals, sometimes 
not.

no?


I write wrong, not  if (_vga_x == _vga_y) but if (&_vga_x == 
&_vga_y)


[Help!] Use two different assembly symbol in D, but they are same address.

2019-08-24 Thread lili via Digitalmars-d-learn

Hi:
  definition _vga_x and _vga_y symbol in asm, compile use nasm -f 
elf64 -o boot.o boot.asm

  [section .bss]
...

  [global _vga_x]
  _vga_x:
  resb 8
  [global _vga_y]
  _vga_y:
  resb 8


  and nm boot.o show below
...
   00107000 B _vga_x
   00107008 B _vga_y

 and In another D file use this two symbol

extern(C) {
 extern __gshared int _vga_x; //definition in boot.asm
 extern __gshared int _vga_y; //definition in boot.asm
}

 void tt()
 {
if (_vga_x == _vga_y)
  //where is true, why?
 }

 but when a run tt so strange things happend that the test is 
true.

 Is where has a coding mistake.
 src  https://github.com/lilijreey/OS-D





how to definition a non-const pointer that point a const var.

2019-08-23 Thread lili via Digitalmars-d-learn

Hi:
  In C we can definition const int *ncp_to_cv;
   or int * const cp_to_ncv;
  How to do this in D.


How to removes an variable topmost const. like remove_const in C++.

2019-08-22 Thread lili via Digitalmars-d-learn

Hi:
   I write a template function is below, that need to remove 
const topmost if has.

How to do this?

   const int i =3;
   println(i);
  void println(A...)(A a)
{
char[20] numStr = void;

foreach(v ; a) {
if (is(v.type == byte)  || is(v.type == ubyte) ||
is(v.type == short) || is(v.type == ushort) ||
is(v.type == int)   || is(v.type == uint) ||
is(v.type == long)  || is(v.type == ulong)) {
//did not wirte const types ... again.

ulong n = cast(ulong)v;
bool isNeg = false;
if (v < 0) {
isNeg = true;
if (n != 1<<63)
n = -v;
}

int i=0;
while(n !=0 ) {
numStr[i++] = (n%10) + '0';
n/=10;
}

if (isNeg)
putc('-');

while (--i >= 0)
putc(numStr[i]);
} else if (is(v.type == char*) || is(v.type == const 
char*)) {

puts(v);
} else if (is(v.type == bool)) {
 puts(v ? "true":"false");
} else if (is(v.type == char)) {
 putc(v);
} else {
static assert(false);
}
}
}


Re: How to write __traits(isSame, T, int) use another way

2019-08-22 Thread lili via Digitalmars-d-learn

On Thursday, 22 August 2019 at 17:01:09 UTC, Adam D. Ruppe wrote:

On Thursday, 22 August 2019 at 16:54:56 UTC, lili wrote:

   I think the __traits(isSame, T, int) syntax is too uglily,
   Is where an other way rewrite it. like this 
isSameType!(T,int)


For types you can (and often should) just use

is(T == int)


the isSame thing is more about comparing aliases rather than 
types.


Thanks alot, How to get a variable's type?

void println(A...)(A a)
{
//TODO static if type
foreach(c ; a) {
static if (??(c) == int) //How to get c's type???

}
}


How to write __traits(isSame, T, int) use another way

2019-08-22 Thread lili via Digitalmars-d-learn

Hi:
   I think the __traits(isSame, T, int) syntax is too uglily,
   Is where an other way rewrite it. like this isSameType!(T,int)


How to set a global var to a user defined section.

2019-08-20 Thread lili via Digitalmars-d-learn

Hi:
  With gcc we can use  _ attribute _((section("name")) var; how 
to same in dlang?




What the abstrac final class mean?

2019-08-12 Thread lili via Digitalmars-d-learn

Hi:
Why need defined an abstract final class?
see  
https://github.com/Rikarin/Trinix/blob/master/Kernel/arch/amd64/gdt.d


How to mark a condition is likeyly or unlikey ?

2019-08-07 Thread lili via Digitalmars-d-learn

Hi:
In C there has likely unlikely marco used by condition 
expression。

#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
if (likely(var > 1)) do...

How to do this in Dlang?


Where can find the GC impletement source code?

2019-06-26 Thread lili via Digitalmars-d-learn

Hi Guys:
   I look for the GC source code in /usr/include/dmd dir, 
unfortunately not find.




There is a computer languages benchmark compare site, but no Dlang benchmark. I think they should support D.

2019-06-21 Thread lili via Digitalmars-d-learn
A nick site, has a lot of languages, unfortunately no dlang in 
there. 
https://benchmarksgame-team.pages.debian.net/benchmarksgame/


Re: What is iota function full name

2019-06-21 Thread lili via Digitalmars-d-learn

On Friday, 21 June 2019 at 09:09:33 UTC, aliak wrote:

On Friday, 21 June 2019 at 09:01:17 UTC, lili wrote:

Hi Guys:
What is range.iota function full name


That is the full name. Or what do you mean?

Found on the internet somewhere:

"The function is named after the integer function ⍳ from the 
programming language APL."


 I mean is that the what is iota stands for.

in dictionary iota means:
a tiny or scarcely detectable amount
the 9th letter of the Greek alphabet
 but this function is not that mean.


What is iota function full name

2019-06-21 Thread lili via Digitalmars-d-learn

Hi Guys:
What is range.iota function full name


What is the difference between extern(C++) extern(D)

2019-06-19 Thread lili via Digitalmars-d-learn

Hi Guys;
   In the dmd source code, has lot of extern (C++), Why need this 
and what is difference between extern(C++) extern(D), Thanks your 
answer.


Re: Where can find fix length array memory layout document

2019-06-19 Thread lili via Digitalmars-d-learn

On Wednesday, 19 June 2019 at 12:53:05 UTC, Cym13 wrote:


Did you import it properly?

```
void main() {
import core.stdcpp.array;
auto a = array!(int, 4)();
}
```

compiles and runs without issue for me. You'll have to show 
your code if you want people to help you there.


Ok, where has some mistake in my code. thanks.



Re: Where can find fix length array memory layout document

2019-06-18 Thread lili via Digitalmars-d-learn

On Tuesday, 18 June 2019 at 17:29:49 UTC, Cym13 wrote:

On Tuesday, 18 June 2019 at 17:25:42 UTC, Cym13 wrote:

On Tuesday, 18 June 2019 at 13:05:03 UTC, lili wrote:

On Tuesday, 18 June 2019 at 12:39:45 UTC, Dennis wrote:

[...]

Thanks a lot, where is a core.stdcpp.array , How to user it?
I test  but get a error
```
  auto aa = array!(int, 4); //error
```


Please don't shorten your code or errors to the point where 
there's hardly any information left: it's hard to help you if 
we can't know what you did and what went wrong.


Forgot to say that it's probably because you don't actually 
build an array here, try adding parentheses:


```
  auto aa = array!(int, 4)();
```


array!(int,4)(); compile occurs a error say: no overload matches 
for array




Re: Why after writeln the binaryHeap become empty?

2019-06-18 Thread lili via Digitalmars-d-learn

On Tuesday, 18 June 2019 at 17:25:51 UTC, Johannes Loher wrote:

The result of heapify is a BinaryHeap, which is a range. writeln
basically prints ranges by iterating over them and printing 
each element
(except for the types which are special cased, such as dynamic 
arrays
etc.). However, ranges are consumed by iterating over them, 
which
explains the behavior because writeln is not special cased for 
BinaryHeaps.


Funnily enough, BinaryHeap does not implement a "save" method, 
which is the usual way of making ranges copiable, i.e. making 
them ForwardRanges. In this case I believe save could even 
simply be an alias to dup.


Do you known reason for why Dlang Range are consumed by iterating 
over them. I this design is strange.


Why after writeln the binaryHeap become empty?

2019-06-18 Thread lili via Digitalmars-d-learn

Hi Guys:
   see this code
~~~
int[] ar = [1,2,3,4,52,34,22];
auto h = heapify(ar);
assert(h.length() == ar.length);
writeln("h:",h);
assert(h.empty());
~~~
dmd v2.086.0  run all assert passed. Why?


Re: Where can find fix length array memory layout document

2019-06-18 Thread lili via Digitalmars-d-learn

On Tuesday, 18 June 2019 at 12:39:45 UTC, Dennis wrote:

On Tuesday, 18 June 2019 at 12:26:14 UTC, lili wrote:

Hi guys:
   Is the Dlang fix-length array alloc on stack?  when a test
writeln([1]).sizeof //16
writeln([2]).sizeof //16
Why, What is the fix-length array memory layout.


I'm assuming you mean writeln([1].sizeof).
An array literal is a slice of a dynamic array (which is length 
+ pointer, so 2*size_t size).
A fixed size array has to be declared as a local / member 
variable, and then the content is on the stack:


```
int[10] a;
writeln(a.sizeof); // 40
writeln(a[].sizeof); // 16 on 64-bit or 8 on 32-bit
```

To get a static array literal, you can use the library function 
staticArray:

```
import std.array;
writeln([1, 2, 3].staticArray.sizeof); // 12
```

Thanks a lot, where is a core.stdcpp.array , How to user it?
I test  but get a error
```
  auto aa = array!(int, 4); //error
```


Where can find fix length array memory layout document

2019-06-18 Thread lili via Digitalmars-d-learn

Hi guys:
   Is the Dlang fix-length array alloc on stack?  when a test
writeln([1]).sizeof //16
writeln([2]).sizeof //16
Why, What is the fix-length array memory layout.


Where can find dmd back-end source code.

2019-06-17 Thread lili via Digitalmars-d-learn

Hi gues:
  I clone the dmd source code from github but i can find backend 
code. there is a backend dir
in src but can not find x86 native code generator. and the dmd 
wiki page just say

Back end
FileFunction
html.c 	Extracts D source code from .html files  but source can't 
find html.c file.