weird formattedRead

2021-04-09 Thread Oleg B via Digitalmars-d-learn
Hello, I have some doubts about working `formattedRead` with 
space chars.


Example:
```d
import std : formattedRead, DateTime, stderr, each;

DateTime parseDT(string str)
{
int d,mo,y, h,m,s;
formattedRead!"%d/%d/%d %d:%d:%d"(str, d,mo,y, h,m,s);
return DateTime(y,mo,d, h,m,s);
}

void tryParse(string s)
{
try
{
auto dt = parseDT(s);
stderr.writefln!"valid '%s': %s"(s, dt);
}
catch (Exception e)
stderr.writefln!"INVALID '%s': %s"(s, e.msg);
}

void main()
{
auto vs = [
"",
"1",
"1/1",
"1/1/1",
"1/1/1 1",
"1/1/1 1:1",
"1/1/1 1:1:1",
];
vs.each!tryParse;
}
```

outputs:

```
INVALID '': 0 is not a valid month of the year.
INVALID '1': parseToFormatSpec: Cannot find character '/' in the 
input string.
INVALID '1/1': parseToFormatSpec: Cannot find character '/' in 
the input string.

valid '1/1/1': 0001-Jan-01 00:00:00 <<< see here
INVALID '1/1/1 1': parseToFormatSpec: Cannot find character ':' 
in the input string.
INVALID '1/1/1 1:1': parseToFormatSpec: Cannot find character ':' 
in the input string.

valid '1/1/1 1:1:1': 0001-Jan-01 01:01:01
```

Is space a special char for `formattedRead` and it simple stop 
parse without throwing exception if not found space (that 
represented in fmt string)?

Have `formattedRead` any other special chars?
Or it's bug?


Re: isPOD is broken?

2021-03-27 Thread Oleg B via Digitalmars-d-learn

On Friday, 26 March 2021 at 12:13:29 UTC, kinke wrote:
A class *reference* is always a POD. Only structs can be 
non-PODs.


In this case what means "does not have virtual functions, does 
not inherit"? Structs doesn't have virtual methods and they can't 
inherits.


isPOD is broken?

2021-03-26 Thread Oleg B via Digitalmars-d-learn

Hi all!

class Foo
{
private int val;

this(int v) { val = v; }
int vv() { return val*2; }
~this() { }
}

class Bar : Foo
{
this(int v) { super(v); }
override int vv() { return val*3; }
}

pragma(msg, __traits(isPOD, Foo));
pragma(msg, __traits(isPOD, Bar));

prints

true
true


example1
https://run.dlang.io/is/Fvru18

example2
https://run.dlang.io/is/GrXdGy

May be POD is not what I mean? Bad docs? 
https://dlang.org/glossary.html#pod


Re: Truly algebraic Variant and Nullable

2020-12-21 Thread Oleg B via Digitalmars-d-announce
On Sunday, 20 December 2020 at 11:00:05 UTC, Tobias Pankrath 
wrote:

On Sunday, 15 November 2020 at 04:54:19 UTC, 9il wrote:
Truly algebraic Variant and Nullable with an order-independent 
list of types.


Thanks for sharing it!

Could you give a (very short) explanation on why sumtype could 
not meet your requirements? I am just starting a new D project 
and have to choose between sumtype and your solution.




The work has been sponsored by Kaleidic Associates and 
Symmetry Investments.


Much appreciated!


For me choose between sumtype and mir.algebraic ends when I not 
found
any solution for working with type kind [1] in sumtype. Kind 
represents in
taggedalgebraic [2] too, but it can't work in compile time 
(important for
me in current project). Also I find tagged_union [3] library, but 
it haven't

any visit [4] or match functions.

[1] http://mir-core.libmir.org/mir_algebraic.html#.TaggedVariant
[2] https://code.dlang.org/packages/taggedalgebraic
[3] https://code.dlang.org/packages/tagged_union
[4] http://mir-core.libmir.org/mir_algebraic.html#visit


Re: Truly algebraic Variant and Nullable

2020-12-16 Thread Oleg B via Digitalmars-d-announce

On Wednesday, 16 December 2020 at 15:58:21 UTC, 9il wrote:

On Wednesday, 16 December 2020 at 14:54:26 UTC, Oleg B wrote:

On Sunday, 15 November 2020 at 04:54:19 UTC, 9il wrote:
Truly algebraic Variant and Nullable with an 
order-independent list of types.


Nullable is defined as
```
alias Nullable(T...) = Variant!(typeof(null), T);
```

Variant and Nullable with zero types are allowed.

`void` type is supported.

Visitors are allowed to return different types.

Cyclic referencing between different variant types are 
supported.


More features and API:

http://mir-core.libmir.org/mir_algebraic.html

Cheers,
Ilya

The work has been sponsored by Kaleidic Associates and 
Symmetry Investments.


Great library! Have you any plan to separate it from mir-core 
(to mir-algebraic for example)?


Thanks! Maybe, but mir-core is quite small itself and 
mir.algebraic is the only part that would be extended or 
updated in the near future. Other parts are quite stable. If 
there would be a strong reason to split it, we can do it.


That are you planing update? It's will be perfect if you add 
`get` overload for kind type and more work with tags [2]


like that:
```
alias TUnion = Algebraic!(
TaggedType!(int, "count"),
TaggedType!(string, "str")
);

auto v = TUnion("hello");

S: final switch (v.kind)
{
  static foreach (i, k; EnumMembers!(k.Kind))
case k:
  someFunction(v.get!k); // [1] by now 
v.get!(TUnion.AllowedTypes[i])

  break S;
}

if (v.is_count) // [2]
writeln(v.count);
```

or may be I miss this feature in docs?



Re: Truly algebraic Variant and Nullable

2020-12-16 Thread Oleg B via Digitalmars-d-announce

On Sunday, 15 November 2020 at 04:54:19 UTC, 9il wrote:
Truly algebraic Variant and Nullable with an order-independent 
list of types.


Nullable is defined as
```
alias Nullable(T...) = Variant!(typeof(null), T);
```

Variant and Nullable with zero types are allowed.

`void` type is supported.

Visitors are allowed to return different types.

Cyclic referencing between different variant types are 
supported.


More features and API:

http://mir-core.libmir.org/mir_algebraic.html

Cheers,
Ilya

The work has been sponsored by Kaleidic Associates and Symmetry 
Investments.


Great library! Have you any plan to separate it from mir-core (to 
mir-algebraic for example)?


Re: How to define delegate what returns ref?

2020-08-28 Thread Oleg B via Digitalmars-d-learn

On Friday, 28 August 2020 at 11:50:35 UTC, kinke wrote:

On Friday, 28 August 2020 at 11:46:15 UTC, Oleg B wrote:

How to do this more clearly?


alias Dg = ref int delegate();
Dg foo;


Thanks!


How to define delegate what returns ref?

2020-08-28 Thread Oleg B via Digitalmars-d-learn

Hello all!

syntax

ref int delegate() foo0;

or

ref(int) delegate() foo1;

or

int delegate() ref foo2;

are not valid.

if I try alias

alias refint = ref int;
refint delegate() foo3;

foo3 have type `int delegate()` (without `ref`)
and it can't store delegate from object method that have `int 
delegate() ref` (that can be printed if we use 
`typeof().stringof`)


I found only one ugly way to do this

interface Foo { ref int func(); }
typeof() foo4;

How to do this more clearly?


Re: Overload comparison operators for "nullable" types

2020-08-01 Thread Oleg B via Digitalmars-d-learn

On Thursday, 30 July 2020 at 14:52:17 UTC, H. S. Teoh wrote:
On Thu, Jul 30, 2020 at 01:41:05PM +, Oleg B via 
Digitalmars-d-learn wrote: [...]
Logically we can compare versions, but what must return 
`opCmp` if one of versions has 'not comparible' state?

[...]

opCmp is allowed to return float; so you could return float.nan 
in this case.



T


Thank you! Simple answer but not in documentation...


Overload comparison operators for "nullable" types

2020-07-30 Thread Oleg B via Digitalmars-d-learn

Hello!

For example we can imagine struct Version.
Version can be old or new and can be 'badly formed' or 
'undefined' or other 'not comparible' ('uncompatible') state.


Logically we can compare versions, but what must return `opCmp` 
if one of versions has 'not comparible' state?


I think strategy of throwing exception in `opCmp` is bad because 
some types can be 'not comparible' not because they is `null` or 
`undefined`, 'not comparible' can be two objects in some working 
states.


If we add `opEquals` we can check 'not comparible' and return 
`false`, but operators `a <= b` and `a >= b` not expands under 
the hood as `a < b || a == b`, they only call `opCmp` and if it 
returns 0 considered arguments are equals.


Rewrite `a <= b` as `a < b || a == b` is not intuitive and can 
get bugs if new user will use code (or old user forgot about 
this). Checking 'not comparible' state before `a <= b` is not 
intuitive too.


`opBinary` can't overload comparison.

We have same type of problem if wrap simple `double` into struct 
and try overload comparison (double.nan has own behavior).


Problem can be solved if we add new `opCmpEx` into language spec 
that return 4 states: more, less, equal, not equal.

Or if we allow `opBinary` overload comparisons.

May be I don't understand something important and this problem is 
not exists?


May be in cases where can be 'not comparible' state we should not 
use overload of comparison operators? But it looks like 
overloading conception isn't completed and can be improved.


aslike: duck-typing with check interface

2020-07-11 Thread Oleg B via Digitalmars-d-announce

Hello!

I wrote library, that can be helpful in some cases:

1. easy and readable check interface of structures without 
'templatisation' of function or method

2. cache virtual methods table lookup for OOP implementations

using:
1. define interface
2. use `Like` wrap as argument
3. wrap objects by `as` function

example:
https://github.com/deviator/aslike/blob/master/example/struct/app.d
https://github.com/deviator/aslike/blob/master/example/cache/app.d

in cache example at my machine I have ~2 increase of performance:

```
$ ldc2 -O -I../../source/ app.d; and rm app.o; and ./app
delegates avg: [18 ms, 281 μs, and 7 hnsecs]
impliface avg: [36 ms, 70 μs, and 3 hnsecs]
likecache avg: [18 ms and 243 μs]
```

dub: https://code.dlang.org/packages/aslike
git: https://github.com/deviator/aslike


Re: gtkui: aux lib for using gtkd with glade

2020-02-14 Thread Oleg B via Digitalmars-d-announce
On Wednesday, 12 February 2020 at 14:12:29 UTC, Ferhat Kurtulmuş 
wrote:

On Tuesday, 11 February 2020 at 18:40:33 UTC, Oleg B wrote:
If you want use Glade [1] as UI builder with gtkd [2] you can 
be interested by this library


[Dub] http://code.dlang.org/packages/gtkui
[Git] https://github.com/deviator/gtkui

[1] https://glade.gnome.org/
[2] https://gtkd.org/


Very good. I wish attribute names would follow Vala's rules as 
much as it could be so that possible transitions from vala-gtk 
users can feel home. But this is my personal choice though:

eg. gtkwidget -> GtkChild


Good idea, thanks! But I think it should follow d-style for UDA 
https://dlang.org/dstyle.html#naming_udas and should be camelCase 
or fully lowercase like @nogc.


I will add @gtkchild and @gtkcallback in next version and add 
deprecate message for @gtkwidget and @gtksignal.


gtkui: aux lib for using gtkd with glade

2020-02-11 Thread Oleg B via Digitalmars-d-announce
If you want use Glade [1] as UI builder with gtkd [2] you can be 
interested by this library


[Dub] http://code.dlang.org/packages/gtkui
[Git] https://github.com/deviator/gtkui

[1] https://glade.gnome.org/
[2] https://gtkd.org/


Re: ssll - simple shared library loader

2020-01-10 Thread Oleg B via Digitalmars-d-announce

On Monday, 6 January 2020 at 10:04:38 UTC, Sönke Ludwig wrote:
I've written something similar with the goal to make it work 
transparently with existing static bindings: 
https://code.dlang.org/packages/dynamic


It uses a mixin to specify the module(s) containing the 
declarations instead of a UDA


Interesting solution. Do you plain implement betterC compatible?


Re: ssll - simple shared library loader

2020-01-10 Thread Oleg B via Digitalmars-d-announce

On Monday, 6 January 2020 at 04:32:25 UTC, Mike Parker wrote:

On Sunday, 5 January 2020 at 23:23:48 UTC, Oleg B wrote:

Nice work! One thing I would recommend, though, is that you not 
bake in extern(C). Some libraries require extern(System) 
(because they're stdcall on Windows and cdecl everywhere else).


So to be robust, you'll want to implement support for both into 
SSLL.


Thanks for the advice! I will continue work on ssll and will try 
implement this feature.


There are only two declarations required for the dynamic 
bindings in BindBC: an alias and a pointer. And of course the 
loader is separate. The reason is historical. When I was 
working on the earliest version of Derelict back in 2004, we 
didn't have all the fancy compile-time features we have now. I 
(and a couple of contributors) tried doing it by declaring the 
function pointers without aliases, but we ran into a couple of 
issues and settled for taking the alias + pointer approach. 
(It's been so long that I can't recall what the issues were).


Thanks for the clarification and thanks for Derelict bindings!


ssll - simple shared library loader

2020-01-05 Thread Oleg B via Digitalmars-d-announce

It's analog of bindbc, but without need write boilerplate code.
May be bindbc is designed for another cases, but I don't 
understand need writing triple definition for one function 
(pointer, loading, wrap-function).
ssll betterC compatible too, and tested on windows (x86) and 
linux (x86, ARM).


package: http://code.dlang.org/packages/ssll
github: https://github.com/deviator/ssll

Example usage:

Mosquitto binding and wrapper
https://github.com/deviator/mosquittod/blob/master/source/mosquittod/api/load.d

libsystemd binding
https://github.com/deviator/sdutil/blob/master/source/systemd/daemon.d

I think somebody can find it handy.


must scope for delegates restrict compilation?

2019-10-03 Thread Oleg B via Digitalmars-d-learn

Hello all

I think this code must get compilation error, but it didn't, 
furthermore result program get UB.


https://run.dlang.io/is/Qpr278

Is this correct behavior and why?


Re: Cross-compiling dub projects with LDC

2019-08-27 Thread Oleg B via Digitalmars-d-announce
Is this supports only in dub-1.17.0-beta.2 and it's not include 
to ldc2-1.17.0?


It feature only in dub-master by now

But it's cool works) Thanks!


Re: Cross-compiling dub projects with LDC

2019-08-27 Thread Oleg B via Digitalmars-d-announce

On Sunday, 25 August 2019 at 21:16:22 UTC, kinke wrote:

The resulting cctest.exe (incl. 2 DLLs) can be copied to a 
Win64 box and then runs fine, as long as a Visual C++ runtime ≥ 
2015 is installed. Tested on a Linux host, but should work on 
any host.


Is this supports only in dub-1.17.0-beta.2 and it's not include 
to ldc2-1.17.0?


Re: Is betterC affect to compile time?

2019-07-25 Thread Oleg B via Digitalmars-d-learn

On Thursday, 25 July 2019 at 12:34:15 UTC, rikki cattermole wrote:

Those restrictions don't stop at runtime.


It's vary sad.

What reason for such restrictions? It's fundamental idea or 
temporary implementation?


Re: Is betterC affect to compile time?

2019-07-25 Thread Oleg B via Digitalmars-d-learn

On Thursday, 25 July 2019 at 12:20:04 UTC, Mike Franklin wrote:


If you read the documentation for betterC 
(https://dlang.org/spec/betterc.html#consequences) you'll see 
that there are features of the D language which are not 
supported. Therefore, libraries that use such features (e.g. 
std.format, std.array) are also not supported, and that is why 
you are encountering such errors.


There are some features of Phobos which can be used in betterC 
builds, but you're going to find that it's hit-and-miss.


Mike


You don't understand my question and don't read code. I ask about 
compile time evaluation (`format` used inside `mixin` that means 
it must be computed at compile time). I know that I can't use 
many features with betterC at runtime.


Is betterC affect to compile time?

2019-07-25 Thread Oleg B via Digitalmars-d-learn

Hello everyone!

I try build this code with betterC

import core.stdc.stdio;
import std.format : format;

extern(C) int main()
{
mixin(format!`enum str = "%s\0";`("hello"));
fprintf(stderr, "%s\n", str.ptr);
return 0;
}

but compilation fails

/dlang/dmd/linux/bin64/../../src/phobos/std/format.d(6278): 
Error: Cannot use try-catch statements with -betterC
/dlang/dmd/linux/bin64/../../src/phobos/std/format.d(6308): 
Error: template instance `std.format.checkFormatException!("enum 
str = \"%s\\0\";", string)` error instantiating
onlineapp.d(6):instantiated from here: format!("enum str 
= \"%s\\0\";", string)
/dlang/dmd/linux/bin64/../../src/phobos/std/format.d(6311):   
 while evaluating: static assert(!e)
/dlang/dmd/linux/bin64/../../src/phobos/std/array.d(3204): Error: 
TypeInfo cannot be used with -betterC


Is this a bug?

https://run.dlang.io/is/TG1uhg


Re: usable @nogc Exceptions with Mir Runtime

2018-10-30 Thread Oleg via Digitalmars-d-announce

Thanks for your work!


Example
===
///
@safe pure nothrow @nogc
unittest
{
import mir.exception;
import mir.format;
try throw new MirException(stringBuf() << "Hi D" << 2 << 
"!" << getData);

catch(Exception e) assert(e.msg == "Hi D2!");
}

===


I don't understand why you choose C++ format style instead of 
D-style format?





Re: serialport v1.0.0

2018-05-13 Thread Oleg B via Digitalmars-d-announce

On Wednesday, 9 May 2018 at 14:41:45 UTC, Andrea Fontana wrote:

On Sunday, 6 May 2018 at 22:02:05 UTC, Oleg B wrote:

Stable version of serialport package

* Blocking `SerialPortBlk` for classic usage

* Non-blocking `SerialPortNonBlk` and `SerialPortFR` for usage 
in fibers or in vibe-d


* Variative initialization and configuration

* Hardware flow control config flag

Doc: http://serialport.dpldocs.info/v1.0.0/serialport.html
Dub: http://code.dlang.org/packages/serialport
Git: https://github.com/deviator/serialport


I wonder if someone can benchmark serialport lib against this 
test:

http://codeandlife.com/2012/07/03/benchmarking-raspberry-pi-gpio-speed/


I think it's different things.
serialport is wrap around system calls, it's not control hardware 
directly.
You could be misled by the phrase about 'hardware flow control': 
is't set on or off using of RTS and CTS pins of UART. Firmware 
control RTS and CTS pins directly.

http://www.brainboxes.com/faq/items/what-is-rts--cts-hardware-flow-control-


serialport v1.0.0

2018-05-06 Thread Oleg B via Digitalmars-d-announce

Stable version of serialport package

* Blocking `SerialPortBlk` for classic usage

* Non-blocking `SerialPortNonBlk` and `SerialPortFR` for usage in 
fibers or in vibe-d


* Variative initialization and configuration

* Hardware flow control config flag

Doc: http://serialport.dpldocs.info/v1.0.0/serialport.html
Dub: http://code.dlang.org/packages/serialport
Git: https://github.com/deviator/serialport


betterC and noboundscheck

2017-11-22 Thread Oleg B via Digitalmars-d-learn

Hello. I try compile simple example:

import core.stdc.stdio;
import std.algorithm : min;

extern (C) void main()
{
char[256] buf;
buf[] = '\0';

auto str = "hello world";
auto ln = min(buf.length, str.length);
buf[0..ln] = str[0..ln];
printf("%s\n", buf.ptr);
}

rdmd -betterC bettercarray2.d

and get error:

/tmp/.rdmd-1000/rdmd-bettercarray2.d-435C14EC3DAF09FFABF8ED6919B624C1/objs/bettercarray2.o:
 In function `main':
bettercarray2.d:(.text.main[main]+0xbc): undefined reference to 
`_d_arraycopy'

collect2: error: ld returned 1 exit status
Error: linker exited with status 1

If I understand correctly _d_arraycopy is part of druntime and it 
check bounds of array access.


If I add -noboundscheck flag all works fine.

dmd version is 2.076.1

Why -betterC flag not 'include' -noboundscheck flag?
It's bug or in some cases it's useful?


Re: RAII in betterC

2017-11-20 Thread Oleg B via Digitalmars-d

On Monday, 20 November 2017 at 18:14:46 UTC, Nick Treleaven wrote:

On Monday, 20 November 2017 at 17:13:37 UTC, Oleg B wrote:
Hello. I know about some implementation issues 
http://forum.dlang.org/thread/nqctbzhrdldmnffch...@forum.dlang.org


What work must be done for fix it? For what time is it 
scheduled?


Looks like Walter is working on it:
https://github.com/dlang/dmd/pull/7304
https://github.com/dlang/dmd/pull/7305


Cool! Thanks!


RAII in betterC

2017-11-20 Thread Oleg B via Digitalmars-d
Hello. I know about some implementation issues 
http://forum.dlang.org/thread/nqctbzhrdldmnffch...@forum.dlang.org


What work must be done for fix it? For what time is it scheduled?


Re: call Pascal DLL functions from D

2017-10-25 Thread Oleg B via Digitalmars-d-learn
On Wednesday, 25 October 2017 at 03:36:54 UTC, Adam D. Ruppe 
wrote:
I'd suggest just trying it and seeing if the functions return 
what you expect.


Unfortunately they returns unexpected codes. Otherwise I wouldn't 
post question here. I go here then I have no idea to resolve 
problem.


Re: call Pascal DLL functions from D

2017-10-25 Thread Oleg B via Digitalmars-d-learn

On Wednesday, 25 October 2017 at 04:30:12 UTC, Basile B. wrote:

On Wednesday, 25 October 2017 at 03:12:56 UTC, Oleg B wrote:

2. `array[A..B] of TFoo` is `TFoo[B-A+1]` (static array)


No A-B. In Pascal the upper bound of a range (like here but i'm 
not sure this i called like that in the grammar) or of a slice 
is inclusive.



alias HarmonicArray = OneHarmonic[49];


48 !

Most likely the problem is the array length.


If I wrote `array[5..7] of ...` I get array that can be indexed 
by `5`, `6` and `7`, right? It means that array have 3 elements. 
If A=5, B=7 then length of array is B-A+1, 7-5+1=3. In my case I 
have [1..49] and [2..50] ranges: 49-1+1=49, 50-2+1=49. I don't 
understand why length must be 48...
In any case I tried 48 and CheckSignalData function returns other 
error code, but it point to current field too (incorrect value of 
coefs - it can be if floating point value is badly read).


call Pascal DLL functions from D

2017-10-24 Thread Oleg B via Digitalmars-d-learn
Hello. I have DLL written on Pascal and "headers" for use it 
(types and functions signatures definitions). How I can port 
"headers" to D?


Calling convention is `stdcall` (`extern (Windows)` for D), 
arguments of some functions is structs of structs and etc with 
static array fields:


```Pascal
type
  TOneHarmonic = record
Koef: Single;
Angle: Single;
  end;

  THarmonicsArray = array[2..50] of TOneHarmonic;
  TInterharmonicsArray = array[1..49] of TOneHarmonic;

  TVoltageCurrentOneFaza = record
KalibKoef: Single;
IncludeMainFreq: Boolean;
MainFreqVoltCur: TOneHarmonic;
Harmonics: THarmonicsArray;
Interharmonics: TInterharmonicsArray;
  end;

  TVoltageCurrent = record
Enable: Boolean;
NominalID: Byte;
Faza_A: TVoltageCurrentOneFaza;
Faza_B: TVoltageCurrentOneFaza;
Faza_C: TVoltageCurrentOneFaza;
  end;

  TSignal = record
HasInterharmonics: Boolean;
Voltage: TVoltageCurrent;
Current: TVoltageCurrent;
...
  end;
  ...
```

in other file

```Pascal
function CheckSignalData(SignalData: PUserSignalData): Word;
  stdcall; external SIGNALK2MDLL;
```
PUserSignalData is pointer to TUserSignalData, first field of 
TUserSignalData is Signal, other fields is pointers to other types


If I understand correctly
1. `Single` is `float` in D, `Byte` is `byte`, `Boolean` is 
`bool`, `Word` is `ushort`

2. `array[A..B] of TFoo` is `TFoo[B-A+1]` (static array)

Can I rewrite records to structs like this?

```d
alias Word = short;
alias Single = float;
alias Byte = byte;
alias Boolean = bool;

struct OneHarmonic
{
Single coef;
Single angle;
}

alias HarmonicArray = OneHarmonic[49];

// TVoltageCurrentOneFaza
struct PhaseInfo
{
// Must I align fields and/or structs?
Single calibCoef;
Boolean includeMainFreq;
OneHarmonic mainFreqVoltCur;
HarmonicArray harmonics; // Can I replace Pascal static 
arrays with D static arrays?

HarmonicArray interharmonics;
}

// TVoltageCurrent
struct ChannelInfo
{
Boolean enable;
Byte nominalID;
PhaseInfo[3] phase; // Can I replace 3 fields to static array?
}

struct Signal
{
Boolean hasInterharmonics;
ChannelInfo voltage;
ChannelInfo current; // #1
...
}
```

In this case I have error about current values (#1) and I think I 
badly rewrite Pascal records to D structs (ChannelInfo, 
PhaseInfo, OneHarmonic) and lose alignments and/or something else.


PS original pascal naming is very bad, I know


Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn

On Tuesday, 3 October 2017 at 12:32:43 UTC, kdevel wrote:
IMHO a program should sleep (consume 0 CPU time and 0 energy) 
if there is nothing to process. This is best accomplished by 
not polling on a file descriptor in order to check if data has 
arrived. If your program must yield() there's probably 
something wrong with the design. I would suggest you put all 
the filedescriptors into a fd_set an then select(3) on the set.


Programs based on fibers can't sleep while wait data and it's not 
a design problem.




Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn

On Tuesday, 3 October 2017 at 10:45:21 UTC, kdevel wrote:

On Tuesday, 3 October 2017 at 00:22:28 UTC, Oleg B wrote:

but get error "Resource temporarily unavailable".


You get EAGAIN because there is no data available at the time 
of reading.


From the manpage of read:

ERRORS
   EAGAIN Non-blocking  I/O has been selected using 
O_NONBLOCK and no data

  was immediately available for reading.


I found only one way: C-style

auto pp = pipeShell(updaterScriptCommand, Redirect.all,
null, Config.none, workDir);

import core.sys.posix.unistd : read;
import core.stdc.errno;
import core.sys.posix.fcntl;

int fd = pp.stdout.fileno;
int flags = fcntl(fd, F_GETFL, 0);
flags |= O_NONBLOCK;
fcntl(fd, F_SETFL, flags); // C-style setting file config

char[256] buf;
while (!tryWait(pp.pid).terminated)
{
auto cnt = read(fd, buf.ptr, buf.length); // C-style 
reading
if (cnt == -1 && errno == EAGAIN) // C-style error 
checking

yield();
else if (cnt > 0)
{
doSomething(buf[0..cnt]);
yield();
}
}


Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn

On Tuesday, 3 October 2017 at 10:45:21 UTC, kdevel wrote:

On Tuesday, 3 October 2017 at 00:22:28 UTC, Oleg B wrote:

but get error "Resource temporarily unavailable".


You get EAGAIN because there is no data available at the time 
of reading.


From the manpage of read:

ERRORS
   EAGAIN Non-blocking  I/O has been selected using 
O_NONBLOCK and no data

  was immediately available for reading.


And I can't check this without using exception handling?


non-block reading from pipe stdout

2017-10-02 Thread Oleg B via Digitalmars-d-learn
Hello. I run program through std.process.pipeShell and want to 
read from it stdout in loop. How do this non-blocking?


I try

int fd = p.stdout.fileno;
int flags = fcntl(fd, F_GETFL, 0);
flags |= O_NONBLOCK;
fcntl(fd, F_SETFL, flags);

but get error "Resource temporarily unavailable".


betterC and struct destructors

2017-09-11 Thread Oleg B via Digitalmars-d-learn
Hello. I try using destructor in betterC code and it's work if 
outer function doesn't return value (void). Code in `scope 
(exit)` works as same (if func is void all is ok).


In documentation I found 
https://dlang.org/spec/betterc.html#consequences 12 paragraph: 
Struct deconstructors.


Why struct destructor need Druntime? Compiler must simply past 
call of destructor before exit from scope or return statement. 
Where is Druntime here (dynamic allocations, pointers to scopes 
and other)?


I think struct destructor must work in betterC code. Otherwise it 
will be one step to be likeC, not betterC.


Re: Automatic function body writing howto?

2017-08-17 Thread Oleg B via Digitalmars-d-learn

On Wednesday, 16 August 2017 at 22:48:59 UTC, Meta wrote:
It's hard to tell offhand but I would recommend that you 
extract the inner string into a function that generates that 
string, allowing you to print out the finished product before 
mixing it in.


It's have a same result...


Automatic function body writing howto?

2017-08-16 Thread Oleg B via Digitalmars-d-learn
I want declare only signature of function and build body code by 
CTFE.


module mdl;
import std.stdio;
import std.traits;
import std.string;

enum autofnc;

@autofnc
{
int foo(int);
int bar(int);
}

void main()
{
writeln(foo(12));
}

mixin cfuncR;

mixin template cfuncR()
{
mixin impl!(getSymbolsByUDA!(mdl, autofnc));

mixin template impl(funcs...)
{
static if (funcs.length == 1)
{
mixin("pragma(msg, typeof(%1$s)); // !!! here I get 
_error_
			ReturnType!%1$s %1$s(Parameters!%1$s vals) { return vals[0] * 
2; }".format(__traits(identifier, funcs[0]));

}
else
{
mixin impl!(funcs[0..$/2]);
mixin impl!(funcs[$/2..$]);
}
}
}

I get this output:

/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.object is not visible from module traits
/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.std is not visible from module traits
mdl.d-mixin-29(30): Error: template instance 
std.traits.ReturnType!(foo) does not match template declaration 
ReturnType(func...) if (func.length == 1 && isCallable!func)
mdl.d-mixin-29(30): Error: template instance Parameters!foo does 
not match template declaration Parameters(func...) if 
(func.length == 1 && isCallable!func)

_error_
mdl.d(34): Error: mixin mdl.cfuncR!().impl!(foo, bar).impl!(foo) 
error instantiating
mdl.d-mixin-29(30): Error: template instance 
std.traits.ReturnType!(bar) does not match template declaration 
ReturnType(func...) if (func.length == 1 && isCallable!func)
mdl.d-mixin-29(30): Error: template instance Parameters!bar does 
not match template declaration Parameters(func...) if 
(func.length == 1 && isCallable!func)

_error_
mdl.d(35): Error: mixin mdl.cfuncR!().impl!(foo, bar).impl!(bar) 
error instantiating
mdl.d(23): Error: mixin mdl.cfuncR!().impl!(foo, bar) error 
instantiating

mdl.d(19): Error: mixin mdl.cfuncR!() error instantiating
Failed: ["dmd", "-v", "-o-", "mdl.d", "-I."]

I think 'template instance std.traits.ReturnType!(foo) does not 
match template declaration' because 'foo' is '_error_' on it's 
instancing moment. But I don't understand why 'foo' is '_error_'.


But if I replace '%1$s' in building function name to '_%1$s' 
pragma(msg, foo) works normal and compiler behavior is 
predictable (defined '_foo', but 'foo' has no body and can't 
linked):


/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.object is not visible from module traits
/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.std is not visible from module traits

int(int)
int(int)
/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.object is not visible from module traits
/usr/include/dmd/phobos/std/traits.d-mixin-7671(7671): 
Deprecation: mdl.std is not visible from module traits

int(int)
int(int)
/tmp/.rdmd-1000/rdmd-mdl.d-9F3ADBC813DCE463C0EFA2CA038B009E/objs/mdl.o: In 
function `_Dmain':
mdl.d:(.text._Dmain+0xa): undefined reference to `_D3mdl3fooFiZi'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

But if I wrote this code by hands:

ReturnType!foo foo(Parameters!foo vals) { return vals[0] * 2; }
ReturnType!bar bar(Parameters!bar vals) { return vals[0] * 2; }

all works fine!!

What am I doing wrong?

dmd 2.074
ldc 1.3.0 (main compiler, because can cross compile to arm)


Re: LDC 1.3.0-beta2

2017-06-13 Thread Oleg B via Digitalmars-d-announce

On Monday, 12 June 2017 at 17:49:46 UTC, kinke wrote:

Hi everyone,

LDC 1.3.0-beta2, the LLVM-based D compiler, is available for 
download!
This release is based on the 2.073.2 frontend and standard 
library and supports LLVM 3.5-4.0.


It's been a while since beta1, so besides numerous fixes there 
are also new features.


Change log and downloads: 
https://github.com/ldc-developers/ldc/releases/tag/v1.3.0-beta2


Regards,
kinke


You plain build armhf version, like for 1.1.0? Or will it never 
happen again?


Re: ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn

On Tuesday, 30 May 2017 at 21:42:03 UTC, Daniel Kozak wrote:

Compiler do many assumptions (it is sometimes useful).


but if compiler find one-to-one correspondence it don't make 
assumptions, like here?



import std.stdio;

void f(ushort u)
{
writeln("ushort");
}

void f(ubyte u)
{
writeln("ubyte");
}

void main()
{
ushort y = 0;
immutable ushort x = 0;

f(y);
f(x);
}

RESULT IS:
ushort
ushort


or it can?


Re: ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn

and this is unexpected for me too

immutable ushort y = 0;
foo(y); // byte


ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn

Hello. I have this code

import std.stdio;

void foo(byte a) { writeln(typeof(a).stringof); }
void foo(short a) { writeln(typeof(a).stringof); }
void foo(int a) { writeln(typeof(a).stringof); }

void main()
{
foo(0); // int, and byte if not define foo(int)
foo(ushort(0)); // byte (unexpected for me)
foo(cast(ushort)0); // byte (unexpected too)

foo(cast(short)0); // short
foo(short(0)); // short

ushort x = 0;
foo(x); // short
}

Is this a bug or I don't understand something?


Enums and immutables

2017-03-18 Thread Oleg B via Digitalmars-d-learn
Hello. I found strange behavior while casting enum array and 
immutable array.


import std.stdio;

void main()
{
enum arr = cast(ubyte[])[0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4];

auto arr1 = cast(void[])arr;
immutable arr2 = cast(immutable(void)[])arr;
enum arr3 = cast(void[])arr;

writeln(cast(ushort[])arr1); // [0, 256, 0, 512, 0, 768, 0, 
1024]
writeln(cast(ushort[])arr2); // [0, 256, 0, 512, 0, 768, 0, 
1024]
writeln(cast(ushort[])arr3); // [0, 0, 0, 1, 0, 0, 0, 2, 0, 
0, 0, 3, 0, 0, 0, 4]

}

I think it's related to representation of enums by compiler as 
#define.

It's right? It's behavior by design?


getSymbolsByUDA toSymbols error instantiating

2017-02-27 Thread Oleg B via Digitalmars-d-learn

Hello. I have this code:

```d
import std.traits;

enum myuda;

class A { @myuda int x; }

class B : A
{
@myuda int some;
void foo() { foreach (s; getSymbolsByUDA!(typeof(this), 
myuda)) {} }

}

void main() { (new B).foo(); }
```

And have this error:

```
% rdmd uda_symbols.d
/usr/include/dmd/phobos/std/traits.d-mixin-7250(7250): Error: 
template instance AliasSeq!(some, x) AliasSeq!(some, x) is nested 
in both B and A
/usr/include/dmd/phobos/std/traits.d(7259): Error: template 
instance std.traits.getSymbolsByUDA!(B, myuda).toSymbols!("some", 
"x") error instantiating
uda_symbols.d(10):instantiated from here: 
getSymbolsByUDA!(B, myuda)

```

If I understand correctly it's happens because code in std.traits 
can't choose between A.x and B.x, but I don't understand why. 
It's a bug or it's has a more complex base?


Package visibility strange behaviour

2017-02-27 Thread Oleg B via Digitalmars-d-learn
Hello. Is this behavior normal, or it's a bug? And if it's normal 
why it's normal? I want to use function with `package` visibility 
in same package where it's defined, but I don't.


```d
module package_visible;
package void foo() { }
void main() { foo(); }
```

```
% rdmd package_visible.d
package_visible.d(3): Error: function package_visible.foo is not 
accessible from module package_visible

Failed: ["dmd", "-v", "-o-", "package_visible.d", "-I."]
```

dmd version v2.073.1


Re: How to get the name for a Tid

2017-02-27 Thread Oleg B via Digitalmars-d-learn
On Wednesday, 23 November 2016 at 21:04:38 UTC, Christian Köstlin 
wrote:
std.concurrency contains the register function to associate a 
name with
a Tid. This is stored internally in an associative array 
namesByTid.
I see no accessors for this. Is there a way to get to the 
associated

names of a Tid?

Thanks,
Christian


I have a same problem and I use workaround with manualy register 
threads and my own list of threads names. I think it's a little 
mistake and can be changed in dmd updates in the near future.


Re: Cross-compile with LDC

2017-02-08 Thread Oleg B via Digitalmars-d-learn

On Wednesday, 8 February 2017 at 16:21:49 UTC, kinke wrote:

On Wednesday, 8 February 2017 at 14:57:41 UTC, Oleg B wrote:
Hello all! I want to build ldc cross compiller. I found this 
instruction  
https://wiki.dlang.org/LDC_cross-compilation_for_ARM_GNU/Linux, but I have some doubts: will it works with ldc-1.1.0? Particularly interested in the patch https://gist.githubusercontent.com/claudemr/3367c13095b15d449b1591eb38d098d9/raw/3517a5db2228e57da9dd8880a82d6bfe6f0e38f1/ldc_1.0.0_gnu_arm. It's for ldc-1.0.0 and sources can be changed.

Maybe somewhere I found patch for ldc-1.1.0?
Maybe someone already build cross ldc for linux x86_64?))


Hi Oleg,

first of all, we have an LDC forum/NG 
(http://forum.dlang.org/group/ldc) which would be more 
appropriate for your question. The referenced LDC patch is 
derived from https://github.com/ldc-developers/ldc/pull/1317, 
which hasn't been merged yet (but will be in not-too-distant 
future).
As you haven't explicitly specified what your target platform 
is, I can only assume that it's 32-bit ARM. With a vanilla LDC, 
cross-compiling to ARM with its double-precision reals will 
only work correctly if your LDC host compiler uses 
double-precision reals too, which isn't the case for Linux 
x86(_64), but for Windows. My LDC PR would make it work with a 
non-Windows x86(_64) host too, but only if the target (not the 
host) uses at most double-precision reals.


Thank you, in future I create new question about ldc in special 
forum. Yes, my target arch is ARMv7 (rpi2 and beaglebone) and 
ARMv8 (rpi3). If I understand correctly with vanilla LDC I can't 
cross-compiling from host linux-x86_64, but with your patch I 
can. Right? Maximum precision for ARMv7(8) is 64bit doubles, for 
x86_64 is 80bit reals. If I use your patch must I use in my 
programs only double or I can stay real in existing code?


Cross-compile with LDC

2017-02-08 Thread Oleg B via Digitalmars-d-learn
Hello all! I want to build ldc cross compiller. I found this 
instruction  
https://wiki.dlang.org/LDC_cross-compilation_for_ARM_GNU/Linux, 
but I have some doubts: will it works with ldc-1.1.0? 
Particularly interested in the patch 
https://gist.githubusercontent.com/claudemr/3367c13095b15d449b1591eb38d098d9/raw/3517a5db2228e57da9dd8880a82d6bfe6f0e38f1/ldc_1.0.0_gnu_arm. It's for ldc-1.0.0 and sources can be changed.

Maybe somewhere I found patch for ldc-1.1.0?
Maybe someone already build cross ldc for linux x86_64?))


Re: Array operation with overlapping

2016-11-08 Thread Oleg Gorbunov via Digitalmars-d
On Tuesday, 8 November 2016 at 14:52:41 UTC, Steven Schveighoffer 
wrote:

On 11/8/16 3:29 AM, Oleg Gorbunov wrote:

I am new in D, but saw some strage behavour.

Overlapping is detected for + and * array operation, but not 
for - and /.





I would say this is a bug. The behavior should be consistent.

-Steve


OK, I'll report this bug at https://issues.dlang.org


Array operation with overlapping

2016-11-08 Thread Oleg Gorbunov via Digitalmars-d

I am new in D, but saw some strage behavour.

Overlapping is detected for + and * array operation, but not for 
- and /.



import std.stdio;

void main()
{
int[] slice = [2, 2, 2, 2];
int[] slice2 = slice[0 .. $ - 1];
int[] slice3 = slice[1 .. $];

writeln("slice  before: ", slice);
writeln("slice2 before: ", slice2);
writeln("slice3 before: ", slice3);

const auto cmd = "slice3[] = slice2[] + slice3[];";

writeln( "cmd: ", cmd );

mixin( cmd );

writeln("slice  after : ", slice);
writeln("slice2 after : ", slice2);
writeln("slice3 after : ", slice3);
}

When this code is run at 'dlang.org'

slice  before: [2, 2, 2, 2]
slice2 before: [2, 2, 2]
slice3 before: [2, 2, 2]
cmd: slice3[] = slice2[] + slice3[];
object.Error@(0): Overlapping arrays in vector operation: 8 
byte(s) overlap of 12


??:? nothrow @safe void 
rt.util.array._enforceNoOverlap(const(char[]), ulong, ulong, 
const(ulong)) [0x44f7f3]

??:? _arraySliceSliceAddSliceAssign_i [0x44c1b6]
??:? _Dmain [0x4408bb]
??:? 
_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 
[0x44c8a6]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x44c7f0]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() [0x44c862]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x44c7f0]

??:? _d_run_main [0x44c761]
??:? main [0x44a389]
??:? __libc_start_main [0x40d80a14]



If change + to -

const auto cmd = "slice3[] = slice2[] - slice3[];";

When it is run at 'dlang.org'

slice  before: [2, 2, 2, 2]
slice2 before: [2, 2, 2]
slice3 before: [2, 2, 2]
cmd: slice3[] = slice2[] - slice3[];
slice  after : [2, 0, -2, -4]
slice2 after : [2, 0, -2]
slice3 after : [0, -2, -4]



new XML and JSON libs and replacement of std.net.curl

2016-08-15 Thread Oleg B via Digitalmars-d-learn

Hello.
In std.xml docs I read that is deprecated, and std.net.curl can 
be deprecated too (not remember here I read about std.net.curl). 
About std.json I read what it's has slow (de)serialization.


What I must use at this time?
vibe.data.json has evolution 
https://github.com/s-ludwig/std_data_json, but, if I correctly 
understood, they are not compatible and I can't use 
stdx.data.json in vibe.


For XML I found this project 
https://github.com/lodo1995/experimental.xml. Is this really 
candidate to std, or author just called it as he want?


As replacement of std.net.curl I found 
https://github.com/ikod/dlang-requests. Who know's about this 
lib? Is this good replacement of std.net.curl?


Maybe if I need json and http requests I must fully use vibe for 
these things? Vibe not resolve xml question =(

I want to use minimal count of dependencies...


Re: DLang users telegram group

2016-06-21 Thread Oleg B via Digitalmars-d-announce

On Tuesday, 8 December 2015 at 17:51:01 UTC, Kingsley wrote:
On Monday, 30 November 2015 at 10:58:34 UTC, Quentin Ladeveze 
wrote:

Hi everybody,

I just created a Telegram group for dlang users : 
https://telegram.me/joinchat/BeLaugMz35ZxQUq2fks4YQ


Feel free to join !


says the link has expired


yet another english group https://telegram.me/dlangTelegram


const and mutable opApply's

2016-06-19 Thread Oleg B via Digitalmars-d-learn

Hello

struct WTable
{
...
private enum opApply_body = q{
if( smt )
{
foreach( f; 0 .. size-1 )
foreach( t; f+1 .. size )
if( auto r = dlg(f,t,data[getIndex(f,t)]) ) 
return r;

}
else
{
foreach( f; 0 .. size )
foreach( t; 0 .. size )
{
if( f == t ) continue;
if( auto r = dlg(f,t,data[getIndex(f,t)]) )
return r;
}
}
return 0;
};

int opApply( int delegate(size_t,size_t,T val) dlg ) const { 
mixin( opApply_body ); }
int opApply( int delegate(size_t,size_t,ref T val) dlg ) { 
mixin( opApply_body ); }

}

How I can rewrite this code without mixin's and with one (maybe 
inout) opApply?


Re: LDC+Dub+Vibe.d work on SmartOS 64bit now

2016-06-10 Thread Oleg Nykytenko via Digitalmars-d-announce

On Friday, 10 June 2016 at 21:40:22 UTC, flamencofantasy wrote:

In another one I get the following;
]# dub
Performing "debug" build using ldc2 for x86_64.
vibe-d:utils 0.7.28: target for configuration "library" is up 
to date.
vibe-d:data 0.7.28: target for configuration "library" is up to 
date.

vibe-d:core 0.7.28: building configuration "libevent"...
../../../.dub/packages/vibe-d-0.7.28/vibe-d/source/vibe/core/core.d(570): Error: static 
assert  "Unsupported OS!"
ldc2 failed with exit code 1.



My pull request with fix this issue merged to version 0.7.29. Use 
please version 0.7.29 or higher.


Re: LDC+Dub+Vibe.d work on SmartOS 64bit now

2016-06-10 Thread Oleg Nykytenko via Digitalmars-d-announce

On Friday, 10 June 2016 at 21:40:22 UTC, flamencofantasy wrote:

ld: fatal: library -levent: not found



I think need install libevent.

In howto on 
https://wiki.dlang.org/LDC%2BDub%2BVibe.d_on_SmartOS_64bit.

I think misprint in line:
# pkgin in binutils gmake cmake scmgit python35 autoconf gcc49 
gcc49-libs unzip libconfig livevent


change "livevent" -> "libevent".


Re: LDC+Dub+Vibe.d work on SmartOS 64bit now

2016-06-09 Thread Oleg Nykytenko via Digitalmars-d-announce

On Wednesday, 8 June 2016 at 15:35:32 UTC, Johan Engelen wrote:
Are you interested in running a buildbot for LDC on your 
platform to detect issues early?


Yes, interested. But our servers can't to use for this purpose. 
They use for data acquisition from electrical substation's 
automation system and do not have access from Internet for 
sequrity reasons.




Re: LDC+Dub+Vibe.d work on SmartOS 64bit now

2016-06-08 Thread Oleg Nykytenko via Digitalmars-d-announce

On Wednesday, 8 June 2016 at 08:43:59 UTC, Joakim wrote:
Have you run the standard library's tests?  There was a thread 
last summer about this:


http://forum.dlang.org/thread/zhcduibirwprgbzqk...@forum.dlang.org


We haven't run library's tests.
What right way to run this tests?

But:
We ported our sufficiently big server application from Linux to 
SmartOS x64.
All application tests is OK. Application working now on testing 
server in production like regime under full load.
And it's working fine. We're planning to use it in production in 
future.


Vibe.d simple http/https/web test applications work fine too.


Pointer to std.container.Array data for C library

2015-08-28 Thread Oleg via Digitalmars-d-learn

Hello!
Is it possible to get pointer to a data in std.container.Array 
like .ptr from an array? I need to pass a pointer to some C 
function (from DerelictGL3 binding) and avoid GC allocation.

Thank you!


Re: Pointer to std.container.Array data for C library

2015-08-28 Thread Oleg via Digitalmars-d-learn

On Friday, 28 August 2015 at 18:21:04 UTC, John Colvin wrote:

On Friday, 28 August 2015 at 17:45:21 UTC, Oleg wrote:

Hello!
Is it possible to get pointer to a data in std.container.Array 
like .ptr from an array? I need to pass a pointer to some C 
function (from DerelictGL3 binding) and avoid GC allocation.

Thank you!


I'm pretty sure you can just take the address of the first 
element, e.g. a[0] or a.front


I've tried, it throws
core.exception.RangeError@/usr/include/dmd/phobos/std/container/array.d(571): 
Range violation

If I make an array from the Array container with foreach ad pass 
it's .ptr - it works


Re: Pointer to std.container.Array data for C library

2015-08-28 Thread Oleg via Digitalmars-d-learn

On Friday, 28 August 2015 at 18:46:23 UTC, Oleg wrote:

I found solution. I call length instead of reserve. It calls 
ensureInitialized and everything works fine. By default, Array 
won't initialize store.


Oh, reserve calls it too. My mistake.
I found the problem, that's because I passed an empty Array (like 
Array!int.init).






Re: Pointer to std.container.Array data for C library

2015-08-28 Thread Oleg via Digitalmars-d-learn

On Friday, 28 August 2015 at 18:40:33 UTC, John Colvin wrote:

On Friday, 28 August 2015 at 18:31:00 UTC, Oleg wrote:

On Friday, 28 August 2015 at 18:21:04 UTC, John Colvin wrote:

On Friday, 28 August 2015 at 17:45:21 UTC, Oleg wrote:

Hello!
Is it possible to get pointer to a data in 
std.container.Array like .ptr from an array? I need to pass 
a pointer to some C function (from DerelictGL3 binding) and 
avoid GC allocation.

Thank you!


I'm pretty sure you can just take the address of the first 
element, e.g. a[0] or a.front


I've tried, it throws
core.exception.RangeError@/usr/include/dmd/phobos/std/container/array.d(571): 
Range violation


That's unexpected. Could you provide a full example that does 
this?


I found solution. I call length instead of reserve. It calls 
ensureInitialized and everything works fine. By default, Array 
won't initialize store.


rt_finalize question

2015-06-09 Thread Oleg B via Digitalmars-d-learn
Hello. In object.di rt_finalize calls for class objects in 
destroy func.
I not found it in dmd source on github and not found in druntime 
sources.
I think rt_finalize must call dtors for object and base classes, 
but I think that's not all. Or if it all has it code logic 
problems?


void myDestroy(T)( T obj ) if( is( T == class ) )
{
mixin( callDtor!( obj.stringof, 
TypeTuple!(T,BaseClassesTuple!T) ) );

}

string callDtor( string name, BCT... )() @property
{
import std.string;
static if( BCT.length == 1 ) return ; // Object has no dtor
else
return format( %s.%s.__dtor();\n, name, 
BCT[0].stringof.split(.)[$-1] ) ~

   callDtor!(name, BCT[1..$]);
}

function callDtor generate string like this

obj.C.__dtor();
obj.B.__dtor();
obj.A.__dtor();

for class model

class A{}
class B : A {}
class C : B {}

I want understand why destroy for class objects call extern(C) 
function rt_finalize (not pure, with gc, can except), and how it 
works (rt_finalize gets void*).


Re: rt_finalize question

2015-06-09 Thread Oleg B via Digitalmars-d-learn

I found it

https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L1350

Creates new questions.
Why it's extern(C)?
What must do collectHandler function?
If I understand correctly monitor relates to multithreading 
control (Mutex?).


Re: using D without GC

2015-06-08 Thread Oleg B via Digitalmars-d-learn

On Monday, 8 June 2015 at 13:37:40 UTC, Marc Schütz wrote:

On Monday, 8 June 2015 at 12:24:56 UTC, Oleg B wrote:

I guess you should follow andrei's post about new allocators!


Can you get link to this post?


These are some of his posts:

http://forum.dlang.org/thread/mku0n4$s35$1...@digitalmars.com
http://forum.dlang.org/thread/mkl1eh$1mdl$2...@digitalmars.com
http://forum.dlang.org/thread/mjig8h$2rgi$1...@digitalmars.com
http://forum.dlang.org/thread/mjdcep$11ri$1...@digitalmars.com
http://forum.dlang.org/thread/mj3p2j$2qva$1...@digitalmars.com
http://forum.dlang.org/thread/mir0lg$2l74$1...@digitalmars.com
http://forum.dlang.org/thread/min9k8$9r9$1...@digitalmars.com


Thank! Can you say how long wait (on average) to experimental 
modules will cease be an experimental and will be part of phobos? 
At next release or it unknown?


Re: pure format

2015-06-04 Thread Oleg B via Digitalmars-d

On Thursday, 4 June 2015 at 16:21:54 UTC, Jonathan M Davis wrote:

On Thursday, 4 June 2015 at 14:33:39 UTC, Oleg B wrote:
Hello. I not found realization of pure format function (in 
phobos it not pure) and write minimal custom realization.

https://github.com/dexset/desstdx/blob/master/source/des/stdx/pformat.d#L472
Now it works with numbers and strings, but in future I improve 
it.

Maybe my realization can help someone =)
Contained in the dub package 
http://code.dlang.org/packages/desstdx


If pure format exists tell about it, please.


std.format.format should be pure if its arguments have pure 
toString methods or are built-in types. There may be 
implementation issues preventing it for one reason or another 
(I don't know), but if so, then that's a bug that needs to be 
fixed. Regardless, there should be no need for a separate 
format function which is pure.


- Jonathan M Davis


I think toString for float must be pure, but in practice it's not.

import std.stdio;
import std.string;
string test( float abc ) pure { return format( abc: % 6.3f, abc 
); }

void main() { writeln( test( 13.3 ) ); }

$ rdmd purefmtfloating.d
purefmtfloating.d(3): Error: pure function 'purefmtfloating.test' 
cannot call impure function 'std.format.format!(char, 
float).format'

Failed: [dmd, -v, -o-, purefmtfloating.d, -I.]

DMD64 v2.067.1

It's a bug? I read what std.format.format using libc sprintf 
http://www.digitalmars.com/d/archives/digitalmars/D/learn/std.conv.to_purity_68957.html 
and if it try it's not a bug...


pure format

2015-06-04 Thread Oleg B via Digitalmars-d
Hello. I not found realization of pure format function (in phobos 
it not pure) and write minimal custom realization.

https://github.com/dexset/desstdx/blob/master/source/des/stdx/pformat.d#L472
Now it works with numbers and strings, but in future I improve it.
Maybe my realization can help someone =)
Contained in the dub package 
http://code.dlang.org/packages/desstdx


If pure format exists tell about it, please.


wrong rounding

2015-06-01 Thread Oleg B via Digitalmars-d
Hello. I found unexpected (for me) behavior of rounding double 
values at casting to ulong:


$ cat roundtest.d
import std.stdio;

void main()
{
double a = 10, b = 0.01;

writeln( int:   , cast(int)(a/b) );
writeln( uint:  , cast(uint)(a/b) );
writeln( long:  , cast(long)(a/b) );
writeln( ulong: , cast(ulong)(a/b) );
}

$ rdmd roundtest.d
int:   1000
uint:  1000
long:  1000
ulong: 999   - WTF?? ---

$ dmd --version
DMD64 D Compiler v2.067.1
Copyright (c) 1999-2014 by Digital Mars written by Walter Bright

$ ldc2 roundtest.d  ./roundtest
int:   1000
uint:  1000
long:  1000
ulong: 1000  --- Ok 

$ ldc2 --version
LDC - the LLVM D compiler (0.15.2-beta1):
  based on DMD v2.066.1 and LLVM 3.6.0
  Default target: x86_64-unknown-linux-gnu
  Host CPU: core-avx-i
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
x86- 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64

$ uname -a
Linux lenovo 4.0.4-201.fc21.x86_64 #1 SMP Thu May 21 15:58:47 UTC 
2015 x86_64 x86_64 x86_64 GNU/Linux


have it behavior explain? can I use casting in dmd for rounding 
values or it not safe?


Re: Set null as function array parameter

2015-01-12 Thread Oleg via Digitalmars-d-learn

On Monday, 12 January 2015 at 15:59:43 UTC, Adam D. Ruppe wrote:
Why are you using ref? Take that off and you can pass any 
array, including null, with ease.


Because dynamic arrays are passed by value to functions. Will it 
make another copy of array, if I'll pass array by value?


Looks like it won't (I've checked pointers), but I read in wiki 
(http://en.wikibooks.org/wiki/D_%28The_Programming_Language%29/d2/Strings_and_Dynamic_Arrays#Passing_Dynamic_Arrays_to_Functions) 
that it will copy structure that contains the -pointer to the 
first element- and the length is copied and passed. Does it mean 
something else? maybe i don't understand it correctly.






Set null as function array parameter

2015-01-12 Thread Oleg via Digitalmars-d-learn
Hello. How can I call a function with null as parameter, which I 
don't want to set. For example:

void foo(ref int[] param1) {}
I can't call this function like:
foo(null);
Is it possible to set default value for an array parameter or 
pass null/empty array? I can create empty array and pass it, but 
it looks ugly:

int[] x;
foo(x);

Thanks.


Re: Set null as function array parameter

2015-01-12 Thread Oleg via Digitalmars-d-learn
On Monday, 12 January 2015 at 16:44:42 UTC, ketmar via 
Digitalmars-d-learn wrote:
nope, it means exactly what is written there. except that 
dynamic array

is represented by struct like this:

  struct {
void *dataptr;
size_t itemCount;
  }

this is what D calls dynamic array, and this is what passed 
by value:
struct with two members. dynamic array contents are *not* a 
part of

dynamic array type.

yes, this is confusing.


Thank you.


Contract programming

2014-12-17 Thread Oleg via Digitalmars-d-learn

Is this behavior normal or it's bug?

[code]

import std.stdio;

class A
{
float func( float x )
in
{
assert( x  0 );
stderr.writeln( A.func in block );
}
body
{
stderr.writeln( A.func body block );
return x / 3;
}
}

class B : A
{
override float func( float x )
in
{
assert( x  10 );
stderr.writeln( B.func in block );
}
body
{
stderr.writeln( B.func body block );
return x * 3;
}
}

void main()
{
auto a = new B;
auto v = a.func( 3.14 );
}

[output]

A.func in block
B.func body block

In class B 'in' block not called, but if add 'out' block it 
called both for A and B classes.


Re: UDA and mixins

2014-12-16 Thread Oleg via Digitalmars-d-learn

struct FooPasted(Args...){}

class A
{
mixin foo;

void func1() @mark { ... }
void func2( int x, string a ) @mark { ... }
}

must change to:

class A
{
void func1() @mark { ... }
void func2( int x, string a ) @mark { ... }

FooPasted!() func1_mark;
FooPasted!(int,string) func2_mark;
}


Re: release building problem

2014-12-04 Thread Oleg via Digitalmars-d-learn

renaming struct from 'Client' to 'MClient' resolve question


release building problem

2014-12-03 Thread Oleg via Digitalmars-d-learn
When I build my program with release flag I get an errors, in 
debug build all works


.dub/build/application-profile-linux.posix-x86_64-dmd-AD20DEA65FEE410217932549C1D262EF/ftree.o: 
In function 
`_D3des4flow5event5Event27__T6__ctorTS6client6ClientZ6__ctorMFNcmKxS6client6ClientZS3des4flow5event5Event':
/home/deviator/workspace/cdsd/fractaltree/descore/import/des/flow/event.d:62: 
undefined reference to 
`_D6object43__T4_dupTxS6client6ClientTyS6client6ClientZ4_dupFNaNbAxS6client6ClientZAyS6client6Client'
.dub/build/application-profile-linux.posix-x86_64-dmd-AD20DEA65FEE410217932549C1D262EF/ftree.o: 
In function 
`_D3des4util5pdata5PData27__T6__ctorTS6client6ClientZ6__ctorMFNaNbNcNfKxS6client6ClientZS3des4util5pdata5PData':
/home/deviator/workspace/cdsd/fractaltree/descore/import/des/util/pdata.d:40: 
undefined reference to 
`_D6object43__T4_dupTxS6client6ClientTyS6client6ClientZ4_dupFNaNbAxS6client6ClientZAyS6client6Client'
.dub/build/application-profile-linux.posix-x86_64-dmd-AD20DEA65FEE410217932549C1D262EF/ftree.o: 
In function `_D4sock2we6SockWE10emitEventsMFZv':
/home/deviator/workspace/cdsd/fractaltree/src/sock/we.d:134: 
undefined reference to 
`_D6object43__T4_dupTxS6client6ClientTyS6client6ClientZ4_dupFNaNbAxS6client6ClientZAyS6client6Client'


It may be a compiler bug, but now I must find workaround.

From mangle 
`_D6object43__T4_dupTxS6client6ClientTyS6client6ClientZ4_dupFNaNbAxS6client6ClientZAyS6client6Client' 
I can understood what no 'dup(Client)' function. But I dont 
understand where it calls. Ctors flow.event.Event and 
des.util.pdata.PData
looks like 'this(T)( ref const(T) val )' and dont use 'dup' 
function. Whey use 'idup' function for 'T[]'.


struct Client
{
size_t id;
vec3 orient; // struct vec3 { float[3] data; }
vec3 motion;
float p1;
}

Where I must find solution?


Re: release building problem

2014-12-03 Thread Oleg via Digitalmars-d-learn

the same result of building release or profile


const class

2014-11-26 Thread Oleg via Digitalmars-d-learn

Hello. I can't find siple way to realization this behavior:

[code]
class A
{
  A parent;

  void someFunc() const { }

  void parentCall() const
  {
 const(A) cur = this;
 while( cur )
 {
   cur.someFunc();
   cur = cur.parent;
 }
  }
}
[/code]

error: cannot modify const expression cur

how create variable that store const object and can be changed to 
other const object?


unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn

[code]
void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { }
struct vec(size_t N, T, string AS) { T[N] data; }
void main() { doSome( vec!(3,float,xyz)([1,2,3]) ); }
[/code]

compile with new dmd v2.066.0 and get error:

Error: template opbin.doSome(ulong N, T, string AS)(vec!(N, T, 
AS) v) specialization not allowed for deduced parameter AS


what does it mean?

on dmd v2.065 it worked well

code without string template parameter work well on dmd v2.066.0

[code]
void doSome(size_t N, T)( vec!(N,T) v ) { }
struct vec(size_t N, T) { T[N] data; }
void main() { doSome( vec!(3,float)([1,2,3]) ); }
[/code]


Re: unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn

On Monday, 25 August 2014 at 11:41:28 UTC, bearophile wrote:

Oleg B:


[code]
void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { }
struct vec(size_t N, T, string AS) { T[N] data; }
void main() { doSome( vec!(3,float,xyz)([1,2,3]) ); }
[/code]

compile with new dmd v2.066.0 and get error:

Error: template opbin.doSome(ulong N, T, string AS)(vec!(N, T, 
AS) v) specialization not allowed for deduced parameter AS


what does it mean?


See also:


struct Vec(size_t N, T, alias string AS) {
T[N] data;
}

void doSome(size_t N, T, alias string AS)(Vec!(N, T, AS) v) {}

void main() {
auto v = Vec!(3, float, xyz)([1, 2, 3]);
doSome(v);
}


(Note that in D the names of types and structs start with an 
upper case).


Bye,
bearophile


Does it mean that I need write alias for all arrays in template 
parameters or only strings?


Re: unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn
and when I minimal fix my libs with this issue compiler fails 
without any output... =(


% gdb dmd
(gdb) run -unittest matrix.d vector.d
Starting program: /usr/bin/dmd -unittest matrix.d vector.d
[Thread debugging using libthread_db enabled]
Using host libthread_db library /lib64/libthread_db.so.1.
[New Thread 0x77ec9700 (LWP 29224)]
[Thread 0x77ec9700 (LWP 29224) exited]

Program received signal SIGSEGV, Segmentation fault.
0x0046c39a in ctfeInterpret(Expression*) ()
(gdb) bt
#0  0x0046c39a in ctfeInterpret(Expression*) ()
#1  0x00457012 in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long)::DeduceType::visit(TypeInstance*) ()
#2  0x0044e304 in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long) ()
#3  0x0045224f in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long)::DeduceType::visit(TypeStruct*) ()
#4  0x00455e80 in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long)::DeduceType::visit(Expression*) ()
#5  0x0044e32c in deduceType(RootObject*, Scope*, Type*, 
ArrayTemplateParameter**, ArrayRootObject**, unsigned int*, 
unsigned long) ()
#6  0x00458251 in 
TemplateDeclaration::deduceFunctionTemplateMatch(TemplateInstance*, 
Scope*, FuncDeclaration*, Type*, ArrayExpression**) ()
#7  0x0045caf1 in functionResolve(Match*, Dsymbol*, Loc, 
Scope*, ArrayRootObject**, Type*, 
ArrayExpression**)::ParamDeduce::fp(void*, Dsymbol*) ()
#8  0x004dd577 in overloadApply(Dsymbol*, void*, int 
(*)(void*, Dsymbol*)) ()
#9  0x0045c401 in functionResolve(Match*, Dsymbol*, Loc, 
Scope*, ArrayRootObject**, Type*, ArrayExpression**) ()
#10 0x004e0343 in resolveFuncCall(Loc, Scope*, Dsymbol*, 
ArrayRootObject**, Type*, ArrayExpression**, int) ()

#11 0x004d9522 in CallExp::semantic(Scope*) ()
#12 0x004eef56 in ExpInitializer::inferType(Scope*) ()
#13 0x004b08ad in VarDeclaration::semantic(Scope*) ()
#14 0x004c1f7a in DeclarationExp::semantic(Scope*) ()
#15 0x0043cd3b in ExpStatement::semantic(Scope*) ()
#16 0x004479a6 in CompoundStatement::semantic(Scope*) ()
#17 0x004e5e2a in FuncDeclaration::semantic3(Scope*) ()
#18 0x00407b28 in Module::semantic3() ()
#19 0x004051bc in tryMain(unsigned long, char const**) ()
#20 0x00338be21b45 in __libc_start_main (main=0x406e60 
main, argc=4, ubp_av=0x7fffdc28, init=optimized out, 
fini=optimized out, rtld_fini=optimized out,

stack_end=0x7fffdc18) at libc-start.c:274
#21 0x00402739 in _start ()


Re: SQLite3

2014-05-07 Thread Oleg via Digitalmars-d-learn

On Wednesday, 7 May 2014 at 06:21:10 UTC, Jack wrote:


void* NotUsedAtAll, // Null variable
int argc, // What?
char** results, // Results?
char** columnNames //Column Names?


You can read about this agruments on
http://www.sqlite.org/c3ref/exec.html



ctor for shared and immutable structs

2014-03-04 Thread Oleg B

why this code get errors?

[code]
/*  1 */struct PData
/*  2 */{
/*  3 */immutable(ubyte)[] data; // ???
/*  4 */pure this(T)( in T val ) { }
/*  5 */}
/*  6 */
/*  7 */unittest
/*  8 */{
/*  9 */immutable(ubyte)[] data_a = [1,2,3];
/* 10 */ubyte[] data_b = [1,2,3];
/* 11 */auto a = PData( data_a );
/* 12 */auto ca = const PData( data_a );
/* 13 */auto ia = immutable PData( data_a );
/* 14 */auto sa = shared PData( data_a );
/* 15 */auto sca = shared const PData( data_a );
/* 16 */
/* 17 */auto b = PData( data_b.idup );
/* 18 */auto cb = const PData( data_b.idup );
/* 19 */auto ib = immutable PData( data_b );
/* 20 */auto sb = shared PData( data_b );
/* 21 */auto scb = shared const PData( data_b );
/* 22 */}
[/code]

$ dmd -unittest -main -run purector.d
purector.d(13): Error: template purector.PData.__ctor cannot 
deduce function from argument types !()(immutable(ubyte)[]) 
immutable, candidates are:

purector.d(4):purector.PData.__ctor(T)(in T val)
purector.d(14): Error: template purector.PData.__ctor cannot 
deduce function from argument types !()(immutable(ubyte)[]) 
shared, candidates are:

purector.d(4):purector.PData.__ctor(T)(in T val)
purector.d(15): Error: template purector.PData.__ctor cannot 
deduce function from argument types !()(immutable(ubyte)[]) 
shared const, candidates are:

purector.d(4):purector.PData.__ctor(T)(in T val)

why cannot deduce pure ctor?

if i change line 3
/*  3 */immutable(ubyte)[] data; // ???
to
/*  3 */ubyte[] data; // ???
all works

why i can't use immutable data in this case?


const ref type as return value

2013-11-29 Thread Oleg B

[code]
import std.stdio;

struct A { int val; }

A a;

class X { const ref A func() { return a; } }

void main()
{
auto x = new X;
x.func().val = 5;
writeln( a );
}
[/code]

in this case 'const' mean 'const method' and variable 'a' changed.

if write
[code]
class X { const(ref A) func() { return a; } }
[/code]

$ dmd -run crtr.d
crtr.d(7): Error: basic type expected, not ref
crtr.d(7): Error: found 'ref' when expecting ')'
crtr.d(7): Error: semicolon expected, not ')'
crtr.d(7): Error: Declaration expected, not ')'
crtr.d(7): Error: unrecognized declaration

Only one way I find for workaround this
[code]
alias const ref A crA;
class X { crA func() { return a; } }
[/code]

But I think should exist more elegant solution.


interface and class inheritance

2013-11-14 Thread Oleg B

[code]
import std.stdio;

interface A { void funcA(); }
class B { final void funcA() { writeln( B.funcA() ); } }

class C: B, A { }

void main()
{
auto c = new C;
c.funcA();
}
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C interface function 'void 
funcA()' is not implemented


if swap A and B
[code]
class C: A, B { }
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C base type must be 
interface, not interface.B


how to workaround this without change in class B and interface A?


Re: interface and class inheritance

2013-11-14 Thread Oleg B

On Thursday, 14 November 2013 at 21:45:11 UTC, Agustin wrote:

On Thursday, 14 November 2013 at 21:42:38 UTC, Agustin wrote:

On Thursday, 14 November 2013 at 21:20:57 UTC, Oleg B wrote:

[code]
import std.stdio;

interface A { void funcA(); }
class B { final void funcA() { writeln( B.funcA() ); } }

class C: B, A { }

void main()
{
  auto c = new C;
  c.funcA();
}
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C interface function 
'void funcA()' is not implemented


if swap A and B
[code]
class C: A, B { }
[code/]

$ dmd -run interface.d
interface.d(6): Error: class interface.C base type must be 
interface, not interface.B


how to workaround this without change in class B and 
interface A?


Try

interface A {
 final void funcA();
}
class B {
 final void funcA() { writeln( B.funcA() ); }
}

class C: B, A { }


Oh sorry i mean

interface A {
  void funcA();
}

class B : A {
  final void funcA() { writeln( B.funcA() ); }
}

class C : B {
}


we can't change anything in class B


C/C++ struct interfacing

2013-10-27 Thread Oleg B

Hello.
I want use one struct in two language.
How to declare the same structure in different languages​​?

D code: calling C++ function with my struct
code
extern(C++)
{
struct vec(size_t N, T=float)
{ //  line 6
alias vec!(N,T) thistype;
T[N] data;

auto opBinary(string op)( in thistype rhs ) const
{
thistype ret;
foreach( i; 0 .. N ) ret.data[i] = data[i] + 
rhs.data[i];

return ret;
}
}

void cppcall( vec!(3,float) d );
}

void main()
{
vec!3 a, b;
a.data[0] = 10;
a.data[1] = 7;
a.data[2] = 3;

b.data[0] = 13;
b.data[1] = 9;
b.data[2] = 4;

cppcall( a + b );
}
/code

C++ code: use struct data
code
#include cstdio

struct vec
{
float data[3];
};

void cppcall( vec d )
{
printf( %f %f %f\n, d.data[0], d.data[1], d.data[2] );
}
/code

compilation failed with unclear error

$ g++ -c ctypestest.cpp -o ctypestest.o
$ dmd ctypestest.d ctypestest.o -ofctypestest
ctypestest.d(6): Error: struct ctypestest.vec!(3, float).vec C++ 
static variables not supported


Re: [OT] Why mobile web apps are slow

2013-07-10 Thread Oleg Kuporosov

 Thanks for the link.  In my experience, mobile networking is
slow in general.  When I run Speedtest on my phone vs. a laptop 
sitting right next to it, the phone has a fraction of the 
bandwidth of the laptop.  So there's even more at issue than 
raw JS performance.


Sean is right, this is only one side of problem and very often 
not a major, another side is mobile network bandwidth and 
infrastructure load.
It is usual for corporate offices/cities (sharing), weak signal 
conditions and
movement you will have quite limited bandwidth even for LTE/3G 
cases.


Re: Why UTF-8/16 character encodings?

2013-05-29 Thread Oleg Kuporosov

On Wednesday, 29 May 2013 at 22:44:17 UTC, Walter Bright wrote:


I still think it's a bad idea, but it's obvious people want it 
in D, so it'll stay.


(Also note that I meant using ASCII, not necessarily english.)


Good, thanks, restrictions definetelly can and should be applied 
per project, like for druntime/Phobos.


Re: Why UTF-8/16 character encodings?

2013-05-28 Thread Oleg Kuporosov

On Tuesday, 28 May 2013 at 01:34:47 UTC, Walter Bright wrote:

Why? You said previously that you'd love to support extended 
operators ;)


Extended operators, yes. Non-ascii identifiers, no.


BTW, this is one of big D advantage, take into account
some day D could be used for teaching in schools where pupils
still doesn't know English somewhere outside US/GB.
It is much easy to start with localized Ids.

Please keep unicode in language.



Re: Vote for std.uni

2013-05-24 Thread Oleg Kuporosov


Yes

Thanks,
Oleg.


Re: Stable D version?

2013-04-28 Thread Oleg Kuporosov

On Sunday, 28 April 2013 at 23:11:30 UTC, Mehrdad wrote:

On Sunday, 28 April 2013 at 12:01:58 UTC, Paulo Pinto wrote:

Which vendors have switched to C++ for systems programming?


Paolo probably had MS in mind which didn't release WinRT for C.



Re: [OT] Information about Access to site You requested denied by Federal Law

2013-03-24 Thread Oleg Kuporosov
2013/3/24 thedeemon dl...@thedeemon.com

 On Saturday, 23 March 2013 at 12:40:37 UTC, Denis Shelomovskij wrote:

 I get this message instead of some sites content:
 Access to site You requested denied by Federal Law

 E.g. see this IT blog by Felipe Contreras:
 http://felipec.wordpress.com/



 For those not speaking Russian.
 The story is: for the last few months there's been a Russian analog of
 Chinese Great Firewall building, it filters some sites, and recently many
 sites on wordpress.com got banned just by coincidence having same IPs as
 some really banned sites. Availability of those sites is ISP-dependent, as
 different ISPs may implement filtering a bit differently.


It is complete OT. In many countries there are some limitations.
BTW, site to which Denis pointed works perfectly for me (Russia, NN,
Beeline).


Oleg.


Re: Migrating dmd to D?

2013-03-01 Thread Oleg Kuporosov
On Thursday, 28 February 2013 at 00:37:50 UTC, Andrei 
Alexandrescu wrote:

Hello,


Walter and I have had a long conversation about the next 
radical thing to do to improve D's standing. Like others in 
this community, we believe it's a good time to consider 
bootstrapping the compiler. Having the D compiler written in D 
has quite a few advantages, among which taking advantages of 
D's features and having a large codebase that would be its own 
test harness.

..

Strategically it is great idea, but tactically there are probably 
more

attractive (for new users also) areas to improve toolchain:

- GC. Current solution is just like java's from 90th. Hit all OS 
and mostly everybody. Makes so hard to develop solutions with 
soft-RT requirements, like

games and multimedia processing.
- Linker for Windows. optlink is far away from current industry 
requirements/standarts. Using coff for Win64 is good but we have 
now dependency on external toolchain. Unfortunatelly C++/CLI was 
excluded from SDK'12, it probably shows new trend. How long 
SDK'10 will be available for download and compatible with next 
Windows? Big risk.


Good article on what can replace C from Damien, including D -
http://damienkatz.net/2013/01/follow_up_to_the_unreasonable.html


Re: Another opportunity for a major design win has presented itself

2013-02-07 Thread Oleg Kuporosov

On Thursday, 7 February 2013 at 20:16:03 UTC, Walter Bright wrote:
No, I can't say who it is at this time. Sorry. But it is a huge 
opportunity for us.


To get the design win, we need to:

(a) get dynamic linking and loading to work

(b) improve language safety without degrading efficiency

(c) improve quality as always

Of course, these things benefit pretty much all D users anyway. 
Initially, (a) is the most important.


That is cool, but what is the target platform - Win/Lin, 32/64?

Oleg.


Re: D Language, chained null checks and the Maybe monad - article

2013-02-06 Thread Oleg Kuporosov

On Tuesday, 5 February 2013 at 20:13:51 UTC, Michael wrote:

Inspired by. It's noted at top)

 Yep, but not in English.

  Michael, it is good code, may be it make sense to add it into 
std.functional

after some refactoring?




Re: Incorporating D

2013-01-26 Thread Oleg Kuporosov
On Friday, 25 January 2013 at 23:24:54 UTC, Andrei Alexandrescu 
wrote:


Thank you for asking. We have been strongly focused on quality 
improvement since last year but judging from this thread we 
need to work more on it (and the derived community sentiment).


Andrei


And that is true, during 2012 and by now 1495 bug fixed and 
closed:


http://d.puremagic.com/issues/buglist.cgi?chfieldto=Nowquery_format=advancedchfield=bug_statuschfieldfrom=2012-01-01bug_status=RESOLVEDbug_status=VERIFIEDbug_status=CLOSEDcomponent=DMDproduct=D

That is just so Awesome! Great thanks to everybody involved!

The bad news is there are still some TDPL bugs:

http://d.puremagic.com/issues/buglist.cgi?keywords=tdplquery_format=advancedkeywords_type=allwordsbug_status=NEWbug_status=ASSIGNEDbug_status=REOPENEDcomponent=DMDproduct=D

These probably would require more attention because TDPL is the 
_only_ printed

source of the language.
Not so big amount although, so using D per TDPL looks pretty safe.

Oleg.


Re: Trust about D programming.

2013-01-23 Thread Oleg Kuporosov

On Wednesday, 23 January 2013 at 21:14:26 UTC, Paulo Pinto wrote:

Many developers have no idea that modern CPUs do lots of things 
that invalidate the concept of C as a high level assembler.




Paolo, the most important features of C makes it high-level 
assembler
it are pointer and its arithmetics. What hell modern CPUs doing 
wrong with it?


Thanks,
Oleg.


recursive function call at compile time

2012-12-16 Thread Oleg

Hello.
I want use recursion, but in my situation compiler doesn't 
correct work.


import std.stdio;

struct MyStruct(uint K)
{
real[K] data;

auto getSmaller()
{
MyStruct!(K-1) ret;
foreach( no, ref d; ret.data )
d = data[no];
return ret;
}

real recursionAlgo()
{
static if( K == 1 ) return data[0];
else
{
real sum = 0;
foreach( i; 1 .. K )
sum += getSmaller().recursionAlgo();
return sum;
}
}
}

void main()
{
MyStruct!(5) a;
a.data = [ 1, 2, 3, 4, 5 ];
writeln( a.recursionAlgo() );
}

at compile time i have errors
./recursion.d(7): Error: index 4294967295 overflow for static 
array
./recursion.d(7): Error: index 4294967294 overflow for static 
array

 etc

i think it's happens because compiler call 'recursionAlgo()' 
where it should not be ( K == 1 )


how to turn off compile time calculation in this part of code?


Re: D vs C++11

2012-11-03 Thread Oleg Kuporosov

On Saturday, 3 November 2012 at 12:46:18 UTC, Erèbe wrote:

Nearly no support in vim (my editor of choice), a Plugin for 
eclipse wich force you to stick with an older version, a Visual 
studio plugin where you need to buy a liscence in order to have 
the IDE. The only viable choice for me is the plugin for 
monodevelop which is really great but no debugger (assert is 
enough for now).


Hi Erèbe,
you can use free Visual Studio Shell with VisualD..
http://www.microsoft.com/en-us/download/details.aspx?id=30670

Thanks,
Oleg.


Re: Unexpected OPTLINK Termination while building dwt helloworld

2012-11-02 Thread Oleg Kuporosov


Optlink can be very fragile sometime with these details, it's a 
known problem. There's already an alpha available of DMD that 
uses the Microsoft linker.


Jacob, it is 64-bit only, not sure DWT is ready for 64.

Oleg.


overriding private interface methods

2012-10-23 Thread Oleg

Hello. How to override private methods?

import std.stdio, std.conv;

interface abcInterface
{
private double private_func();
public final double func() { return private_func(); }
}

class abcImpl: abcInterface
{
override private double private_func() { return 3.14; } //#1
}

void main()
{
auto abc = new abcImpl;
writeln( abc.func() );
}

This code generate error
#1 Error: function inter.abcImpl.private_func cannot override a 
non-virtual function


This private method (private_func) is 'private' because it must 
call only in final interface methods (func)


  1   2   >