Re: CTFE write message to console

2024-04-05 Thread Paolo Invernizzi via Digitalmars-d-learn

On Thursday, 4 April 2024 at 15:43:55 UTC, Carl Sturtivant wrote:
On Thursday, 4 April 2024 at 15:07:21 UTC, Richard (Rikki) 
Andrew Cattermole wrote:


Ah yes, I forgot about that particular thing, doesn't see much 
use as far as I'm aware.


It should be working though.


```D
enum X = computeX("A message");

string computeX(string msg) {
auto s = "CTFE msg: ";
auto x = imported!"std.format".format("%s%s\n", s, msg);
__ctfeWrite(x);
return x;
}

void main() {
import std.stdio;
writeln(X);
}
```
Produces no output on compilation, and writes out `CTFE msg: A 
message` when run.


pragma(msg, x) ?


Re: The std.file rename method fails in the docker environment.

2024-03-14 Thread Paolo Invernizzi via Digitalmars-d-learn

On Wednesday, 13 March 2024 at 23:59:24 UTC, zoujiaqing wrote:

On Wednesday, 13 March 2024 at 22:16:13 UTC, Sergey wrote:

On Wednesday, 13 March 2024 at 21:49:55 UTC, zoujiaqing wrote:

this is bug in D.


It seems like a bug in Hunt-framework.
And Hunt - is an abandoned project.


Hunt Framework call std.file rename function.
but this function can't move file from docker container to host 
machine.


As Jonathan said, it's NOT possible to move aka rename files 
across different filesystems.
You can NOT do that in D, in C, in Python, every language ... is 
a OS error.


Try to copy the file, and then delete the original one.

/P


Re: Would you recommend TDPL today?

2024-01-17 Thread Paolo Invernizzi via Digitalmars-d-learn

On Tuesday, 16 January 2024 at 02:25:32 UTC, matheus wrote:
Hi, I'm mostly a lurker in these Forums but sometimes I post 
here and there, my first language was C and I still use today 
together with my own library (A Helper) which is like a poor 
version of STB (https://github.com/nothings/stb).


[...]


I suggest also Ali book, Programming in D, is excellent [1]

[1] http://ddili.org/ders/d.en/index.html


Re: macOS Sonoma Linker Issue

2023-10-04 Thread Paolo Invernizzi via Digitalmars-d-learn

On Wednesday, 4 October 2023 at 07:43:29 UTC, Tuna Celik wrote:

On Tuesday, 3 October 2023 at 23:55:05 UTC, confuzzled wrote:

[...]


I'm also suffering from the same problem.


It seems to be an Xcode 15 issues, everything works fine with 14


Ideas to reduce error message size?

2023-08-30 Thread Paolo Invernizzi via Digitalmars-d-learn

Hello everybody,

If a compilation error is thrown with CTFE involved, the 'called 
from here' is like:


 ```
src/api3.d(2010): Error: uncaught CTFE exception 
`object.Exception("42703: column \"system_timestamp_ms\" does not 
exist. SQL: select coalesce(count(system_timestamp_ms),0) from 
dev_samples where device_id = $1")`

src/api3.d(39):thrown from here
src/api3.d(49):called from here: 
`checkSql(Schema("public",  
src/dget/db.d(276): Error: template instance 
`api3.forgeSqlCheckerForSchema!(Schema("public", **BAZILLIONS of lines**>  error instantiating

 ```

Simple question: there's a pattern to reduce the outputted stuff 
someway? Everything is related to a single struct, `Schema`, used 
during compile time stuff.


Thank you,
Paolo


Re: A Programmer's Dilema: juggling with C, BetterC, D, Macros and Cross Compiling, etc.

2023-05-06 Thread Paolo Invernizzi via Digitalmars-d-learn

On Monday, 1 May 2023 at 16:57:39 UTC, Dadoum wrote:

On Sunday, 30 April 2023 at 17:51:15 UTC, Eric P626 wrote:
But how is this possible in a cross-compiling context. I am 
not sure if I can do that with the D language either as pure D 
or better C. DMD does not seem to offer cross compiling. GDC 
can compile better C, but not sure mingw can compile D/betterC 
code.


I build programs for macOS, iOS, Windows with ldc2 
cross-compiling capabilities from my Linux computer, and the 
experience is okay, the executables are working fine but the 
set-up is a bit complicated, you need to copy files from the 
windows toolchain, copy your ldc config and edit it with some 
stuff, and do that at each ldc2 update.


If you just need cross-architecture, then gdc is a good option 
since it is compiled in a lot of cross compilation toolchains. 
However, I never managed to build a working gdc myself with 
ucrt or mingw cross-compilation capabilities, it always ends up 
with a compiler unable to link or executables that can't be 
executed on Windows.


Indeed, at DeepGlance we are cross-compiling and cross linking 
with LDC and LLVM ld.lld, from macOS to linux.


I'm interested in understanding if it's feasible to use importC 
with ffmpeg API and cross-compile and link them.





Re: toString best practices

2023-02-17 Thread Paolo Invernizzi via Digitalmars-d-learn
On Wednesday, 15 February 2023 at 12:15:18 UTC, Bastiaan Veelo 
wrote:
On Thursday, 9 February 2023 at 17:49:58 UTC, Paolo Invernizzi 
wrote:

```
import std.format, std.range.primitives;

struct Point(T)
{
T x, y;

void toString(W)(ref W writer, scope const ref 
FormatSpec!char f) const

if (isOutputRange!(W, char))
{
put(writer, "(");
formatValue(writer, x, f);
put(writer, ", ");
formatValue(writer, y, f);
put(writer, ")");
}
}

void main(){

import std.format : format;
assert( format("%s", Point!int(1,2)) == "(1, 2)");

import std.experimental.logger;
sharedLog.infof("%s", Point!int(1,2));
}
```


Pasting this into https://run.dlang.io/, it just works. That's 
for DMD 2.099, so it might be a regression -- or recent feature?


-- Bastiaan.


Hi Bastiaan,

I think the cause is in some change happened in the logger 
module, I'm recompiling some code with the latest dmd frontend.


I solved it simply using the 'logX' functions at module level 
instead of the sharedLog methods.


Thank you!


toString best practices

2023-02-09 Thread Paolo Invernizzi via Digitalmars-d-learn

Hello everybody,

Let's assume there's an implementation of a templated struct like 
this:


```
import std.format, std.range.primitives;

struct Point(T)
{
T x, y;

void toString(W)(ref W writer, scope const ref 
FormatSpec!char f) const

if (isOutputRange!(W, char))
{
put(writer, "(");
formatValue(writer, x, f);
put(writer, ", ");
formatValue(writer, y, f);
put(writer, ")");
}
}

void main(){

import std.format : format;
assert( format("%s", Point!int(1,2)) == "(1, 2)");

import std.experimental.logger;
sharedLog.infof("%s", Point!int(1,2));
/+
 Error: none of the overloads of template 
`std.logger.core.Logger.memLogFunctions!LogLevel.info.logImplf` 
are callable using argument types `!()(string, Point!int) shared`

/Users/pinver/dlang/dmd-2.102.0/osx/bin/../../src/phobos/std/logger/core.d(828,14):
Candidates are: `logImplf(int line = __LINE__, string file = __FILE__, 
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, 
string moduleName = __MODULE__, A...)(lazy bool condition, lazy string msg, 
lazy A args)`
/Users/pinver/dlang/dmd-2.102.0/osx/bin/../../src/phobos/std/logger/core.d(876,14):
`logImplf(int line = __LINE__, string file = __FILE__, 
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__, 
string moduleName = __MODULE__, A...)(lazy string msg, lazy A args)`
+/

}
```

What is the best way to handle also shared writers?

Thank you all,
Paolo






Re: Is @live attribute working yet?

2022-04-24 Thread Paolo Invernizzi via Digitalmars-d-learn

On Sunday, 24 April 2022 at 12:21:29 UTC, elfstone wrote:
On Sunday, 24 April 2022 at 11:36:29 UTC, Paolo Invernizzi 
wrote:

On Sunday, 24 April 2022 at 09:31:40 UTC, elfstone wrote:

[...]


You need to use the flag `-preview=dip1021`

  test.d(8,30): Error: variable `test.test.p` assigning to 
Owner without disposing of owned value


Weird, it's still not working here. I have tried the flag with 
dub, and dmd.


You are right with 2.099.1, it seems to be included in the 
2.100.0-beta.1 ...


  pinver@Moria test % /Users/pinver/dlang/dmd-2.099.1/osx/bin/dmd 
-preview=dip1021 -c -o- src/test.d
  pinver@Moria test % 
/Users/pinver/dlang/dmd-2.100.0-beta.1/osx/bin/dmd 
-preview=dip1021 -c -o- src/test.d
  src/test.d(8): Error: variable `test.test.p` assigning to Owner 
without disposing of owned value





Re: Is @live attribute working yet?

2022-04-24 Thread Paolo Invernizzi via Digitalmars-d-learn

On Sunday, 24 April 2022 at 09:31:40 UTC, elfstone wrote:
Dub(DMD 2.099.1) builds and runs the following code without a 
warning.


import std.stdio;
import core.stdc.stdlib;

@live
void test()
{
int* p = cast(int*) malloc(32);
p = cast(int*) malloc(32);
free(p);
}

void main()
{
test();
writeln("???");
}

Isn't it supposed to trigger an error according to the doc 
(https://dlang.org/spec/ob.html)?


@live void test()
{
auto p = allocate();
p = allocate(); // error: p was not disposed of
release(p);
}


You need to use the flag `-preview=dip1021`

  test.d(8,30): Error: variable `test.test.p` assigning to Owner 
without disposing of owned value


Re: Strong typing and physical units

2020-07-28 Thread Paolo Invernizzi via Digitalmars-d-learn

On Tuesday, 28 July 2020 at 11:04:00 UTC, Cecil Ward wrote:
Of course, in C I used to do something like strong typing with 
an opaque type achieved by using something like typedef struct 
_something {} * type1; and then I had to do casting to get back 
the real type, which was unchecked but it did prevent the user 
from mixing up the types type1 and type2 say as they weren’t 
assignment compatible.


I would really like strong typing to be a built in feature. 
Would anyone else support this?


Once upon a time, typedef was present and backed by the compiler, 
but nowadays you can find it in Phobos [1], but with some quirk 
...


[1] https://dlang.org/phobos/std_typecons.html#.Typedef



Re: D and Async I/O

2020-05-12 Thread Paolo Invernizzi via Digitalmars-d-learn

On Monday, 11 May 2020 at 15:02:59 UTC, bauss wrote:

On Monday, 11 May 2020 at 14:02:54 UTC, Russel Winder wrote:
OK, so I need to create an asynchronous TCP server (not HTTP 
or HTTPS, this is

a real server ;-) ).

I think the normal response is "Use Vibe.d". However, recently 
I see Hunt is an alternative. Has anyone any way of choosing 
between the two?




vibe.d is much more mature than Hunt, that would be my take on 
it.


Also Hunt lacks documentation etc.

I notice that Hunt uses it's own library eschewing all of 
Phobos. Is this an

indicator that Phobos is not suitable for networking activity?


std.socket is terrible, so yes that is an indicator.

You can't even wrap something up fast in it either.

Basically it's low-level while not being low-level at the same 
time. You have to handle __everything__ yourself pretty much.


Have a look also to Martin std.io [1] and Steven iopipes [2], if 
you need something simple.


[1] https://github.com/MartinNowak/io
[2] https://code.dlang.org/packages/iopipe






Re: Pattern matching via switch?

2020-03-17 Thread Paolo Invernizzi via Digitalmars-d-learn
On Sunday, 15 March 2020 at 18:52:01 UTC, Steven Schveighoffer 
wrote:


D doesn't support this natively. The closest you can get is 
something akin to what aliak wrote (you would need to write 
something, not sure if Phobos or some package has implemented 
the feature), or use cascaded if statements:


I've just given a fast look at the thread, so maybe I'm wrong, 
but this [1] should be ok for pattern matching using plain and 
simple Phobos ...


[1] https://dlang.org/phobos/std_variant.html#.visit




Re: Cool name for Dub packages?

2020-03-07 Thread Paolo Invernizzi via Digitalmars-d-learn

On Saturday, 7 March 2020 at 09:31:27 UTC, JN wrote:

Do we have any cool name for Dub packages?

Rust has 'crates'
Crystal has 'shards'
Python has 'wheels'
Ruby has 'gems'


Frankly, I simply hate all that shuffle around names ... it's so 
difficult to understand people when it's referring to them ...we 
already had to remember a gazillion on things, including horrible 
ubuntu names instead of simple numbers! :-)


Packages are ... well packages!

:-P

/P


Re: Meta question - what about moving the D - Learn Forum to a seperate StackExchange platform?

2019-10-18 Thread Paolo Invernizzi via Digitalmars-d-learn

On Friday, 18 October 2019 at 11:45:33 UTC, Seb wrote:
On Friday, 18 October 2019 at 10:55:59 UTC, Martin Tschierschke 
wrote:

[...]


In the state of the D survey, there were more people in favor 
of StackOverflow than D.learn, but to be fair the majority 
voted for "I don't care"


https://rawgit.com/wilzbach/state-of-d/master/report.html


Maybe it's possible to simply add an up/down vote functionality 
to the forum only, just keeping the compatibility with the 
newsgroup ...


It's a win/win solution!


Re: Vibe.d Error

2019-10-18 Thread Paolo Invernizzi via Digitalmars-d-learn

On Friday, 18 October 2019 at 08:06:30 UTC, Vino wrote:

On Thursday, 17 October 2019 at 19:02:14 UTC, Vino wrote:

[...]


Hi Andre,

  I tried install vibe.d in SUSE linux 12 SP2 and facing the 
below error, tried the options as per the link 
https://github.com/vibe-d/vibe.d/issues/1748, still no luck and 
the lib's are installed in the server


[...]


The same here on macOS Catilina ... I'm too interested in a 
solution for that


Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-14 Thread Paolo Invernizzi via Digitalmars-d-learn

On Monday, 14 October 2019 at 05:36:44 UTC, Joel wrote:
On Friday, 11 October 2019 at 11:38:27 UTC, Jacob Carlborg 
wrote:

[...]


I get this since Catalina:

Joel-Computer:VacSpace joelchristensen$ dub
Failed to invoke the compiler dmd to determine the build 
platform: dyld: lazy symbol binding failed: Symbol not found: 
_dyld_enumerate_tlv_storage

  Referenced from: /usr/local/bin/dmd
  Expected in: /usr/lib/libSystem.B.dylib

dyld: Symbol not found: _dyld_enumerate_tlv_storage
  Referenced from: /usr/local/bin/dmd
  Expected in: /usr/lib/libSystem.B.dylib


Joel-Computer:VacSpace joelchristensen$

I use Home Brew (brew upgrade dmd, and brew upgrade dub)
Brew is only up to 2.087.1 at the moment - John Colvin seems to 
be the man that mantains dmd with brew.


I confirm that DMD downloaded from the official script works like 
charms on Catilina. You can rely on that right now ...




Re: ld errors in osx Catalina

2019-10-09 Thread Paolo Invernizzi via Digitalmars-d-learn
On Wednesday, 9 October 2019 at 16:08:41 UTC, rikki cattermole 
wrote:

On 09/10/2019 11:33 PM, David Briant wrote:

[...]


D as a native language links against libc, so using the system 
c compiler as the linker is a viable method to prevent having 
to look things up.


Perhaps try ldc? That uses LLVM so may be better on OSX.

Related: https://issues.dlang.org/show_bug.cgi?id=20019

Also those versions on homebrew look to be at least one version 
out of date.


If ldc on homebrew doesn't work, you should try the versions on 
the main site (which has dmg's) https://dlang.org/download.html


I confirm that ldc-1.18.0-beta2 works fine on mine Catalina, 
downloaded and activated with the official install script.


/Paolo


Re: D on ARM laptops?

2019-07-04 Thread Paolo Invernizzi via Digitalmars-d-learn

On Thursday, 4 July 2019 at 01:01:03 UTC, Nicholas Wilson wrote:

On Wednesday, 3 July 2019 at 20:49:20 UTC, JN wrote:
Does anyone know if and how well D works on ARM laptops (such 
as Chromebooks and similar)?


For example this one https://www.pine64.org/pinebook/ . Can it 
compile D? Obviously DMD is out because it doesn't have ARM 
builds. Not sure about GDC. How about LDC?


Haven't tried on laptops, but I can't imagine it would be too 
different to RasPi which LDC worked fine on.


We are using LDC on Jetson boards and it's working fine ...


Re: I really don't understand DUB

2019-04-15 Thread Paolo Invernizzi via Digitalmars-d-learn

On Sunday, 14 April 2019 at 20:51:10 UTC, Andre Pany wrote:

On Sunday, 14 April 2019 at 19:46:41 UTC, Ron Tarrant wrote:

[...]


You are totally right, it should be more intuitive how to use 
dub.


As far as I know if you do not specify in dub.json/dub.sdl what 
type of package you have (executable/library) dub make a guess. 
Is there an app.d it will default the targetType "executable", 
if not it will default the targetType "library".


To solve your specify the targetType explicitly in your dub.sdl 
file.


https://dub.pm/package-format-json.html#target-types

Kind regards
Andre


The Zen of Python, rule number two: explicit is better than 
implicit ...


I guess that just killing all that educated dub guess will turn 
dub into a much easier tool to grasp.


- P


Error: non-shared method core.sync.condition.Condition.notify is not callable using a shared object

2018-10-18 Thread Paolo Invernizzi via Digitalmars-d-learn
There's a rational behind the fact that there's not a 'shared' 
version of notify/wait method in Condition?


Thanks,
Paolo


Re: Convert output range to input range

2018-03-18 Thread Paolo Invernizzi via Digitalmars-d-learn

On Saturday, 17 March 2018 at 17:51:50 UTC, John Chapman wrote:

I'm trying to replace the old std.streams in my app with 
ranges. I'm interfacing with a networking library to which I 
supply a callback that when invoked provides the requested 
data. I write that data to an output range, but later on I need 
to read that data from the range too - which of course you 
can't do.


So what I'm looking for is the range-based equivalent of a 
MemoryStream.


I suggest you to give a fast read to this [1], reactive streams.
The D implementation [2] uses as a base an output range.

They are pretty good in handling time based series event, it this 
is your usecase...


[1] http://reactivex.io
[2] https://github.com/lempiji/rx

/Paolo


Re: Error: out of memory

2018-01-10 Thread Paolo Invernizzi via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 19:21:21 UTC, Adam D. Ruppe 
wrote:

On Wednesday, 10 January 2018 at 19:15:00 UTC, Anonymouse wrote:

I don't see a 64 bit release though... might have to try to 
build it yourself from source using visual studio.


It's a long time I don't understand why there's not a 64bit 
distribution...

(along with a debug build of rt/phobos, btw)

/Paolo


Re: private keyword dont appear to do anything

2017-11-04 Thread Paolo Invernizzi via Digitalmars-d-learn

On Friday, 3 November 2017 at 23:32:52 UTC, H. S. Teoh wrote:

[...]


What's wrong with the introduction of another visibility 
attribute that behave like the C++ private?


Just curious...

---
Paolo



Re: Is it possible to specify the address returned by the address of operator?

2017-09-30 Thread Paolo Invernizzi via Digitalmars-d-learn

On Friday, 29 September 2017 at 22:15:44 UTC, Mengu wrote:

On Friday, 29 September 2017 at 02:34:08 UTC, DreadKyller wrote:

[...]


+1 for forum issue.


+1 please...


Re: Accessing part of a struct in an easy way

2017-07-03 Thread Paolo Invernizzi via Digitalmars-d-learn

On Monday, 3 July 2017 at 17:30:51 UTC, Ali Çehreli wrote:

hOn 07/03/2017 10:13 AM, Paolo Invernizzi wrote:

> [...]
struct with
> [...]

I had difficulty understanding the requirements. For example, 
it's not clear whether you want the literal "first" and 
"second" names.


[...]


Thanks Ali,

I'm doing something similar, with inout ref in the b function: 
I'll stick with that.

Thanks again to all!

/Paolo


Re: Accessing part of a struct in an easy way

2017-07-03 Thread Paolo Invernizzi via Digitalmars-d-learn

On Monday, 3 July 2017 at 16:41:51 UTC, vit wrote:

On Monday, 3 July 2017 at 13:53:45 UTC, Paolo Invernizzi wrote:

[...]


//https://dpaste.dzfl.pl/d59469c264b2

import std.algorithm : map, copy, equal;
import std.range : iota;

struct Foo {
int[3] a;
string[2] b;
}

ref T first(R : T[], T)(ref R x,){return x[0];}
ref T second(R : T[], T)(ref R x){return x[1];}

void worksOnA(R : int[N], size_t N)(ref R r) {
iota(1, N+1)
.map!(x => cast(int)x*2)
.copy(r[]);
}
void worksOnB(string[] r) { }


void main(){
auto foo = Foo();

foo.a.first = 1;
foo.a.second = 2;
assert(foo.a.first == 1);
assert(foo.a.second == 2);


foo.b.second = "test";
assert(foo.b.first == "");
assert(foo.b.second == "test");

foo.a.worksOnA();
assert(foo.a[].equal([2, 4, 6]));

}


Thanks for your solution, Vic!

It's not exactly the same, as first and second should be struct 
with partial fields from Foo, of different types.


/Paolo


Accessing part of a struct in an easy way

2017-07-03 Thread Paolo Invernizzi via Digitalmars-d-learn

I've struct like that:

struct Foo {
int a_1; float a_2; string a_3;
string b_1; double b_2;
}

I would like to transparently access that like:

foo.a.first
foo.b.second = "baz";

with an helper like:

auto a(...) { ... }
auto b(...) { ... }

that can be used also in functions that are expecting it:

void worksOnA(  ) { }
void worksOnB(  ) { }

auto foo = Foo( ... )
foo.a.worksOnA();
foo.b.worksOnB();

But I'm struggling in finding a good way to do it...
Suggestions?

Thanks!
/Paolo




Re: The reason for SIGSEGV function pointer problem

2017-06-07 Thread Paolo Invernizzi via Digitalmars-d-learn

On Wednesday, 7 June 2017 at 16:50:26 UTC, Russel Winder wrote:

In the constructor of an object to abstract the result of a 
call to the C library code, the parameter is:


check_frontend_t* cf



You should remove the pointer here...

/Paolo


Re: D and GDB

2017-06-04 Thread Paolo Invernizzi via Digitalmars-d-learn

On Sunday, 4 June 2017 at 19:24:17 UTC, Basile B. wrote:

On Sunday, 4 June 2017 at 18:13:41 UTC, Russel Winder wrote:

[...]


you have to pipe the output to ddemangle. Personally i don't 
know how to do this by hand since my IDE does the task 
automatically 
(http://bbasile.github.io/Coedit/widgets_gdb_commander).


Also i suppose you compiled with -g -gs ?


at `libdvbv5.d:140` you are calling the native 
`dvb_scan_transponder` in `libdvbv5.so` that's segfaulting...


Try to just log the arguments values you are using there...

/Paolo


Re: What is PostgreSQL driver is most stable?

2017-03-15 Thread Paolo Invernizzi via Digitalmars-d-learn

On Wednesday, 15 March 2017 at 09:18:16 UTC, Suliman wrote:

On Tuesday, 14 March 2017 at 13:36:04 UTC, Daniel Kozak wrote:

Dne 14.3.2017 v 14:21 Daniel Kozak napsal(a):

Dne 14.3.2017 v 14:13 Suliman via Digitalmars-d-learn 
napsal(a):


I need to develop App that should work on Linux and Windows. 
It need PostgreSQL driver. I tried Vadim's ddbc for 
PostgreSQL but it's fail on x64 version of PostgreSQL and 
possible will not on x64 PG on Linux (I can't test it now).


Could anybody advice me good driver without problems? I seen 
some pg-wrapers on code.dlang.ru, but do not have test all 
of them.

ddbc works fine for me

s/ddbc/ddb/


Am I rightn understand that DBRow! is allow to get only single 
row, and if I need array of rows I need to use foreach? If I am 
wrong could you provide an example please.


The retrieval of records is done via the execution of a 
(prepared) sql query, that returns a range object (PGResultSet), 
and the element of that range is the DBRow, in one of its form.


So, basically, the elements are retrieved on demand while you 
popFront that range, leveraging what the PostgreSQL stream 
protocol provide.


---
Paolo


Re: What is PostgreSQL driver is most stable?

2017-03-15 Thread Paolo Invernizzi via Digitalmars-d-learn

On Wednesday, 15 March 2017 at 08:50:11 UTC, Dsby wrote:
On Tuesday, 14 March 2017 at 16:24:31 UTC, Paolo Invernizzi 
wrote:

On Tuesday, 14 March 2017 at 13:32:31 UTC, Suliman wrote:
On Tuesday, 14 March 2017 at 13:21:39 UTC, Paolo Invernizzi 
wrote:

On Tuesday, 14 March 2017 at 13:13:31 UTC, Suliman wrote:

[...]


I'm using ddb [1], a full-D implementation of the PostgreSQL 
protocol. Not everything it's in place, but it does its 
works, and the codebase is pretty simple, so it's not 
difficult to contribute if you need to add some feature 
that's missing for your use case.


[1] https://github.com/pszturmaj/ddb

---
Paolo


Does it work fine on Linux with x64 Postgres?


Yes

---
Paolo


We used dpq.
http://code.dlang.org/packages/dpq


I'm curious: ddb does not support yet arbitrary precision numbers 
[1], does dpq support them?


Thanks,
Paolo

[1] 
https://www.postgresql.org/docs/9.5/static/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL


Re: What is PostgreSQL driver is most stable?

2017-03-14 Thread Paolo Invernizzi via Digitalmars-d-learn

On Tuesday, 14 March 2017 at 13:32:31 UTC, Suliman wrote:
On Tuesday, 14 March 2017 at 13:21:39 UTC, Paolo Invernizzi 
wrote:

On Tuesday, 14 March 2017 at 13:13:31 UTC, Suliman wrote:

[...]


I'm using ddb [1], a full-D implementation of the PostgreSQL 
protocol. Not everything it's in place, but it does its works, 
and the codebase is pretty simple, so it's not difficult to 
contribute if you need to add some feature that's missing for 
your use case.


[1] https://github.com/pszturmaj/ddb

---
Paolo


Does it work fine on Linux with x64 Postgres?


Yes

---
Paolo


Re: What is PostgreSQL driver is most stable?

2017-03-14 Thread Paolo Invernizzi via Digitalmars-d-learn

On Tuesday, 14 March 2017 at 13:13:31 UTC, Suliman wrote:
I need to develop App that should work on Linux and Windows. It 
need PostgreSQL driver. I tried Vadim's ddbc for PostgreSQL but 
it's fail on x64 version of PostgreSQL and possible will not on 
x64 PG on Linux (I can't test it now).


Could anybody advice me good driver without problems? I seen 
some pg-wrapers on code.dlang.ru, but do not have test all of 
them.


I'm using ddb [1], a full-D implementation of the PostgreSQL 
protocol. Not everything it's in place, but it does its works, 
and the codebase is pretty simple, so it's not difficult to 
contribute if you need to add some feature that's missing for 
your use case.


[1] https://github.com/pszturmaj/ddb

---
Paolo


Re: Natural sorted list of files

2017-02-06 Thread Paolo Invernizzi via Digitalmars-d-learn

On Monday, 6 February 2017 at 18:57:17 UTC, Ali Çehreli wrote:

On 02/06/2017 08:43 AM, Dmitry wrote:


Found this https://rosettacode.org/wiki/Natural_sorting#D
but there is error on ".groupBy!isDigit" (Error: no property 
'groupBy'

for type 'string').


I think  it's now std.algorithm.chunkBy. Please fix Rosetta 
Code as well. Thanks! :)


Ali


I'm missing Bearophile...
(and btw, Kenji)

/P


Re: [Semi-OT] I don't want to leave this language!

2016-12-08 Thread Paolo Invernizzi via Digitalmars-d-learn

On Thursday, 8 December 2016 at 11:09:12 UTC, ketmar wrote:

what can be done, tho, is article (or series of articles) 
describing what exactly druntime is, how it is compared to libc 
and libc++, why it doesn't hurt at all, how to do "bare metal" 
with custom runtime, why GC is handy (and how to limit GC 
impact if that is necessary), and so on. that is something D 
Foundation should do, i believe.


+1

/Paolo




Re: non-constant expression ["foo":5, "bar":10, "baz":2000]

2016-11-28 Thread Paolo Invernizzi via Digitalmars-d-learn

On Sunday, 27 November 2016 at 22:25:51 UTC, John Colvin wrote:
On Saturday, 26 November 2016 at 17:37:57 UTC, Paolo Invernizzi 
wrote:

This is stated in documentation [1]:

immutable long[string] aa = [
  "foo": 5,
  "bar": 10,
  "baz": 2000
];

unittest
{
assert(aa["foo"] == 5);
assert(aa["bar"] == 10);
assert(aa["baz"] == 2000);
}

But results to:

   Error: non-constant expression ["foo":5L, "bar":10L, 
"baz":2000L]


Known bug?
If yes, Is there the need to emend the documentation, till the 
bug is open?

---
/Paolo


Known bug.

If you need a workaround, initialising the variable at 
load-time with `static this` should help in some cases.


Thank Joan,

The point is that I was trying to avoid some cycle between 
modules, detected by 2.072.
This bug leads to pollution in the use of static this only to 
workaround the limitation...


--
Paolo



Re: non-constant expression ["foo":5, "bar":10, "baz":2000]

2016-11-27 Thread Paolo Invernizzi via Digitalmars-d-learn
On Saturday, 26 November 2016 at 19:57:21 UTC, Adam D. Ruppe 
wrote:
On Saturday, 26 November 2016 at 17:37:57 UTC, Paolo Invernizzi 
wrote:

This is stated in documentation [1]:


What's the link?

This is a known limitation, it has never worked. The docs 
should reflect that, though some day, it might start working.


Sorry, I forgot to past it in the previous post: here it is.

https://dlang.org/spec/hash-map.html#static_initialization

--
Paolo


non-constant expression ["foo":5, "bar":10, "baz":2000]

2016-11-26 Thread Paolo Invernizzi via Digitalmars-d-learn

This is stated in documentation [1]:

immutable long[string] aa = [
  "foo": 5,
  "bar": 10,
  "baz": 2000
];

unittest
{
assert(aa["foo"] == 5);
assert(aa["bar"] == 10);
assert(aa["baz"] == 2000);
}

But results to:

   Error: non-constant expression ["foo":5L, "bar":10L, 
"baz":2000L]


Known bug?
If yes, Is there the need to emend the documentation, till the 
bug is open?

---
/Paolo


Enumerate CTFE bug...

2016-11-21 Thread Paolo Invernizzi via Digitalmars-d-learn

I'm not sure if it's the same as #15064 bug:

import std.array, std.range, std.algorithm;

  immutable static foo = ["a", "b", "c"];
  auto bar(R)(R r)
  {
  string s = r[1];
  return s;
  }
  immutable static res = foo.enumerate.map!bar().array;

std/typecons.d(526): Error: reinterpreting cast from 
inout(ulong)* to inout(Tuple!(ulong, immutable(string)))* is not 
supported in CTFE

bug.d(9):called from here: r._Tuple_super()
std/algorithm/iteration.d(593):called from here: 
bar(this._input.front())

std/array.d(105):called from here: __r2091.front()
bug.d(15):called from here: array(map(enumerate(foo, 
0LU)))


---
Paolo


Re: test for equality of the content of two AA

2016-10-30 Thread Paolo Invernizzi via Digitalmars-d-learn

On Wednesday, 26 October 2016 at 19:03:45 UTC, Ali Çehreli wrote:

On 10/26/2016 08:03 AM, Paolo Invernizzi wrote:

[...]


If you mean D's AAs, then that is already implemented:

  void main() {
auto a = [ "hello" : 1, "world" : 2 ];
auto b = [ "world" : 2, "hello" : 1 ];
assert(a == b);
}

[...]


Thank you Ali, very exhaustive!


test for equality of the content of two AA

2016-10-26 Thread Paolo Invernizzi via Digitalmars-d-learn
As the subject states, what is the best idiomatic way for doing 
that?


Thanks in advance
/Paolo


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread Paolo Invernizzi via Digitalmars-d-learn

On Wednesday, 26 October 2016 at 08:42:02 UTC, dm wrote:

Hi. I tried code below:

import std.concurrency;
import std.stdio;

void func()
{
throw new Exception("I'm an exception");
}

void main()
{
auto tID = spawn();
foreach(line; stdin.byLine)
send(tID, "");
}

I expect my application will die immediatly, but main thread 
still running and I don't see any errors.

I want to kill all my threads if it is unhandled exception.
How can I do that?


You need to link the threads, and at least one receive after the 
child thread has implicitly sent the exception to the main thread:


import std.concurrency;
import std.stdio;

---
void func()
{
throw new Exception("I'm an exception");
}

void main()
{
auto tID = spawnLinked();
receive((int dummy){});
}

---
/Paolo


Re: Reinstalled Mac

2016-09-29 Thread Paolo Invernizzi via Digitalmars-d-learn
On Thursday, 29 September 2016 at 11:43:32 UTC, Jacob Carlborg 
wrote:


Cool, what if I want to use different versions in different 
sessions, i.e. I have two tabs open in my terminal?


Ummm...
All the installed stuff is pretty well organised inside 
`/usr/local`, so this works...


---
hw0062:~ pinver$ /usr/local/Cellar/dmd/2.071.2/bin/dmd --version
DMD64 D Compiler v2.071.2
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
hw0062:~ pinver$ /usr/local/Cellar/dmd/2.071./bin/dmd --version
2.071.0_1/ 2.071.1/   2.071.2/
hw0062:~ pinver$ /usr/local/Cellar/dmd/2.071.0_1/bin/dmd --version
DMD64 D Compiler v2.071.0
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
---

/Paolo



Re: Reinstalled Mac

2016-09-29 Thread Paolo Invernizzi via Digitalmars-d-learn
On Thursday, 29 September 2016 at 06:24:08 UTC, Jacob Carlborg 
wrote:

On 2016-09-29 03:43, David Nadlinger wrote:
I've had good experiences using Homebrew, although you 
sometimes have to wait

a day or three for a new release to appear. — David


DVM doesn't have that problem :). How easy is it to have 
multiple versions of DMD installed using Homebrew?


It seems simple:

---
hw0062:~ pinver$ brew info dmd
dmd: stable 2.071.2 (bottled), HEAD
D programming language compiler for OS X
https://dlang.org/
/usr/local/Cellar/dmd/2.071.0_1 (561 files, 65.0M)
  Poured from bottle on 2016-06-23 at 14:51:10
/usr/local/Cellar/dmd/2.071.1 (561 files, 65.0M)
  Poured from bottle on 2016-07-06 at 09:48:40
/usr/local/Cellar/dmd/2.071.2 (561 files, 65.0M) *
  Poured from bottle on 2016-09-26 at 11:50:45
From: 
https://github.com/Homebrew/homebrew-core/blob/master/Formula/dmd.rb


hw0062:~ pinver$ dmd --version
DMD64 D Compiler v2.071.2
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright

hw0062:~ pinver$ brew switch dmd 2.071.0_1
Cleaning /usr/local/Cellar/dmd/2.071.0_1
Cleaning /usr/local/Cellar/dmd/2.071.1
Cleaning /usr/local/Cellar/dmd/2.071.2
13 links created for /usr/local/Cellar/dmd/2.071.0_1

hw0062:~ pinver$ dmd --version
DMD64 D Compiler v2.071.0
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
---

/Paolo



Re: Experience report on installing dmd 2.066.1 on OSX

2014-11-13 Thread Paolo Invernizzi via Digitalmars-d-learn

On Thursday, 13 November 2014 at 05:57:49 UTC, Joakim wrote:
On Wednesday, 12 November 2014 at 22:38:56 UTC, Ali Çehreli 
wrote:
A friend of mine installed dmd on OSX and recorded his 
experiences:


 http://cap-lore.com/Languages/D/Install.html

I wonder why he had to do manual work like running xattr. Is 
that expected on OSX?


Looks like they're now requiring that apps be signed with the 
developer's account, which I'm guessing the dmd dmg isn't:


http://stackoverflow.com/questions/24176378/why-my-dmg-is-not-getting-opened-without-asking-security-popup



Downloading the zip is still the most simple and easy way, IMHO...
Not a single problem on 10.10...
---
Paolo


Re: Dart bindings for D?

2014-10-30 Thread Paolo Invernizzi via Digitalmars-d-learn
On Thursday, 30 October 2014 at 06:57:23 UTC, Ola Fosheim Grøstad 
wrote:
There are also scripting frameworks that let you write portable 
code for web and mobile platforms, but they tend to be geared 
towards a special type of application.


E.g.
http://www.tidesdk.org/
http://cordova.apache.org/
http://get.adobe.com/air/


At work we are using Meteor [1] for everything related to the web 
products, and it's a VERY successful experience: easy to use, 
easy to deploy, incredible fast development timings.


Right now you can also target Android/iOS, so actually you can 
manage everything with just plain JS.


It turned to 1.0 release just yesterday, it's well funded I've 
bet it should be a long-runner framework.

Warmly suggested.

---
/Paolo

[1] http://www.meteor.com



Re: Why do some language-defined attributes have @ and some not?

2014-10-24 Thread Paolo Invernizzi via Digitalmars-d-learn

On Friday, 24 October 2014 at 00:37:26 UTC, Mike Parker wrote:


There are people out there using D who do not participate in 
the newsgroups. Walter has told us before that he gets emails 
from companies using D in production. He has to deal with 
complaints about code breakage that we aren't going to see here 
in the NG. Just keep in mind that no matter how many of us here 
agree on a breaking change, we are not the entirety of the D 
user base. And it has nothing to do with Reddit.


I think that Walter talked about emails complaining about silent 
breakage or regressions, and that's a totally different matter.


To be honest, I only remember that he talked about one single 
case, but maybe I'm wrong.

And I don't remember any complain about code deprecations.
---
/Paolo




Re: Why do some language-defined attributes have @ and some not?

2014-10-22 Thread Paolo Invernizzi via Digitalmars-d-learn
On Thursday, 23 October 2014 at 02:22:41 UTC, Jonathan M Davis 
wrote:
On Thursday, 23 October 2014 at 00:59:26 UTC, Shriramana Sharma 
via Digitalmars-d-learn wrote:


LOL. I understand the sentiment, but it's a waste of time.


Jonathan,

I agree It's impossible to debate such thing with Walter / Andrej 
right now, but I don't think It's a waste of time: every explicit 
and accountable opinion about that is a little stone to weigh in 
the balance.


---
/Paolo


Re: Objective-C runtime: bindings are possible?

2014-03-12 Thread Paolo Invernizzi

On Tuesday, 11 March 2014 at 17:22:59 UTC, Jacob Carlborg wrote:

On 2014-03-11 16:12, Paolo Invernizzi wrote:

Hi all,

I'm wondering if it is possible to directly interface with the
objective-c runtime, as I've read [1] and I have some random 
crashes in

my code right now.


Yes, it's possible since the Objective-C runtime is plain C 
functions. You need to show us some code to be able to help you.



Someone can share some experience? I'm on 10.9...


To interface with Objective-C there are three options:

* Use the Objective-C runtime functions directly [1]
 + Works now, no language or library support is needed
 - Cumbersome
 - Verbose
 - Easy to make mistakes

* Use an Objective-C/D bridge [2]
 + Fairly simple to use
 - Bloat, both template and virtual method bloat. We're talking 
60MB Hello World


* Extend the language to be ABI compatible [3, 4]
 + The compiler outputs the same code as the Objective-C 
compiler would
 + Easy to use (or as easy as using Objective-C would be, 
sometimes easier)

 - Requires language support

I tried all of these options and personally I think the third 
options is the best. As of a coincident I just finished (except 
for exceptions) porting D/Objective-C to 64bit.


[1] 
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html


[2] http://www.dsource.org/projects/dstep
[3] http://wiki.dlang.org/DIP43
[4] https://github.com/jacob-carlborg/dmd/tree/d-objc


Hi Jacob,

Actually I'm using [1], that's why I was wandering about eventual 
problems related to objc_msgSend_stret.
But I think that now the plan is to tryout [3]: that's the most 
logical solution after all...


- Paolo



Objective-C runtime: bindings are possible?

2014-03-11 Thread Paolo Invernizzi

Hi all,

I'm wondering if it is possible to directly interface with the 
objective-c runtime, as I've read [1] and I have some random 
crashes in my code right now.


Someone can share some experience? I'm on 10.9...

Thanks,
Paolo

[1] http://d.puremagic.com/issues/show_bug.cgi?id=9931


Re: Pure

2014-01-08 Thread Paolo Invernizzi

On Wednesday, 8 January 2014 at 19:04:24 UTC, John Colvin wrote:
On Wednesday, 8 January 2014 at 18:40:46 UTC, Ola Fosheim 
Grøstad wrote:
Is pure meant to be a compiler hint so that it is up to the 
programmer to enforce it? It is sometimes useful to maintain 
hidden state for lazy evaluation, that does not affect purity 
optimizations:


pure is enforced by the compiler (bugs allowing...). However, D 
purity has more shades to it than the black and white concept 
that most are familiar with.


I'll leave it to someone who knows better to explain it.


This one is a good introduction, or at least the best one I can 
remember:


http://klickverbot.at/blog/2012/05/purity-in-d/

Very well written, a pleasure to read.

/Paolo


Re: -profile and nothrow

2013-10-29 Thread Paolo Invernizzi

On Monday, 28 October 2013 at 18:34:51 UTC, Dicebot wrote:
Any difference in semantics between -profile and normal flow is 
a

bug, so, yes, please report to bugzilla.


Done: http://d.puremagic.com/issues/show_bug.cgi?id=11375


Re: -profile and nothrow

2013-10-28 Thread Paolo Invernizzi

Reduced:

module b;
class B {
this() {}
}

module a;
import b;

class C : B {}
class D(X) : X {}
alias D!(C) HtmlPanel;

dmd -profile a.d
Error: 'a.C.this' is not no throw

Everything is ok without the profile... may I post a bug report 
for this?


/Paolo


On Monday, 28 October 2013 at 15:20:59 UTC, Paolo Invernizzi 
wrote:

Hi all,

Compiling my application with 2.064.beta.4 and 2.063.2 with the 
-profile switch, I have an error like:


  Error: 'foo.ui.Widgets.this' is not no throw

I've read something similar involving contracts, but this seems 
something different.
Of course everything compiles and run fine without the 
-profile switch.


Any clue, or may I try to reduce (it is a BIG codebase)?

Thanks,
Paolo


Adaptation

2013-10-09 Thread Paolo Invernizzi

Hi all,

I think this is not possible, but I'm using two different 
templated libraries, and I'm wondering if there's a way of 
adapting that:


module external.foo;
struct Foo { Foo[] foos }

module external.spam;
void spammer(T foolike){ foreach(s; foolike.spams){ ... } }

module mymain;
import external.foo, external.spam;

auto spams(ref Foo foo){ return foo.foos; }

void main(){
spammer(Foo()); // nope, the function is not visible in 
module external.spam

}

What I'm searching is something like:

alias Foo.spams = Foo.foos;

But I guess that this is against every golden rule of good 
programming...


Thanks,
---
Paolo



__FILE__ and __LINE__ again...

2013-09-10 Thread Paolo Invernizzi

Johannes Pfau wrote something like this, in the logger thread:


If you write code like this:

void log(string file = __FILE__)() //A template
{
  logImpl(file);
}
void logImpl(string file){} //Not a template

The compiler can always inline the log template. So there's no
template bloat as there will be effectively no instances of log.
Instead it will be inlined and logImpl will be called directly 
just as

if you manually called logImpl(__FILE__).


I'm trying something like that, but with __LINE__ in addition to 
put a little more pressure:


void log(string file = __FILE__, int line = __LINE__)(){ 
logImpl(file, line); }

void logImpl(string file, int line){}

I've then compiled a single file filled with 'log()', but I've 
found from 'nm' that the text section is still full of templated 
functions.


So the question is: is Johannes trick supposed to work, or 
there's something I don't understand well about template 
expansion and inlining?


Thanks, Paolo


Re: __FILE__ and __LINE__ again...

2013-09-10 Thread Paolo Invernizzi

On Tuesday, 10 September 2013 at 16:45:33 UTC, H. S. Teoh wrote:
On Tue, Sep 10, 2013 at 06:00:53PM +0200, Paolo Invernizzi 
wrote:

Johannes Pfau wrote something like this, in the logger thread:

If you write code like this:

void log(string file = __FILE__)() //A template
{
  logImpl(file);
}
void logImpl(string file){} //Not a template

The compiler can always inline the log template. So there's no
template bloat as there will be effectively no instances of 
log.

Instead it will be inlined and logImpl will be called directly
just as if you manually called logImpl(__FILE__).

I'm trying something like that, but with __LINE__ in addition 
to put

a little more pressure:

void log(string file = __FILE__, int line = __LINE__)(){
logImpl(file, line); }
void logImpl(string file, int line){}

I've then compiled a single file filled with 'log()', but I've 
found

from 'nm' that the text section is still full of templated
functions.

So the question is: is Johannes trick supposed to work, or 
there's

something I don't understand well about template expansion and
inlining?

[...]

Did you compile with dmd -inline?

Having said that, if you don't have variadic arguments, 
__FILE__ and

__LINE__ should be default arguments at the end of the *runtime*
argument list. Runtime arguments should be used to prevent 
template

bloat:

	void log(/* other arguments here */, string file=__FILE__, int 
line=__LINE__)

{
...
}

If you have variadic arguments, though, this wouldn't work.

In any case, if the template function is just a thin wrapper 
around
logImpl, and you're compiling with -inline, then there should 
be no
runtime overhead. The compiler will still emit template 
instantiations
for each call to log(), but you can get rid of this with 
link-time

optimization (on Posix, you'd add -L-gc-sections to your dmd
command-line: this will cause ld to delete code sections that 
are never
referenced, which includes the log() instantiations if indeed 
they have

been inlined).


T


Thank you to everybody,

As you can guess, I would like to have variadic arguments: I'll 
try to investigate if some mixin syntax is not too horrible to be 
use...


/Paolo


SysTime and std.array.array

2013-08-25 Thread Paolo Invernizzi

Hi all,

I really missing something here, because the following code is 
taking two different path based on the presence or not of a field 
with SysTime, where the field itself is not involved at all in 
the process.


It seems that I'm using something forbidden, or something that it 
is leading to an undefined behaviour, but I have not idea of what 
it is the source of the problem.


Note that I'm using array() as in the original code I was using 
it over a range, this is a reduction of the same problem.


Suggestions are welcome! http://dpaste.dzfl.pl/fc130984

Paolo Invernizzi

---
import std.datetime;
import std.math;

struct A
{
double i;
}


struct B
{
invariant()
{
if(j == 0)
assert(a.i.isNaN, why is 'j' zero?? and i is not 
NaN?);
else
assert( ! a.i.isNaN );
}

SysTime when; // comment this line avoid the breakage
int j;
A a;
}
void main()
{
B b1 = B.init;
assert(b1); // verify that default eyes invariants are ok;

auto b2 = B(
SysTime(0, UTC()),  // comment this line avoid the breakage
1, A(1));
assert(b2);
auto b3 = B(
SysTime(0, UTC()),  // comment this line avoid the breakage
1, A(1)
);
assert(b3);

import std.array;
auto arr = [b2, b3];

assert(arr[0].j == 1);
assert(arr[1].j == 1);
auto a2 = arr.array(); //  bang, invariant is raised, also 
if b2 and b3 are good

}
--


Re: SysTime and std.array.array

2013-08-25 Thread Paolo Invernizzi

On Sunday, 25 August 2013 at 19:01:14 UTC, monarch_dodra wrote:
On Sunday, 25 August 2013 at 14:50:16 UTC, Paolo Invernizzi 
wrote:

Hi all,

--


I didn't fully investigate, but my guess is that you are seeing 
emplace bugs. Basically, *array* first allocates an array 
containing noise, and then tries to emplace data onto there. 
Unfortunatly, emplace does it wrong, calling opAssign when it 
shouldn't.


Further, SysTime is implemented (AFAIK), as a rebindable, which 
has an elaborate opAssign. This means that when you call 
emplace, it calls opAssign, which triggers your invariant, 
which fails, since data is just noise. This is why commenting 
out that data member also avoids the bug.


I'd tell you I have an open pull request that fixes it, but its 
been stuck without review for *months*.


Thank you for the explanation, very appreciated: I've found your 
pull request, and I'm adding a comment pushing for an inclusion. 
(some bug number to vote up?)


It's not easy to get familiar with ranges and templates, and that 
kind of bugs turns sometimes using Phobos facilities like walking 
in a minefields!


I've another question: why the opAssign in SysTime is triggering 
the invariants in the enclosing struct? I mean, they nest also in 
this case?


Thank you

- Paolo Invernizzi


Re: ElementType!string

2013-08-25 Thread Paolo Invernizzi

On Sunday, 25 August 2013 at 19:25:08 UTC, qznc wrote:
Apparently, ElementType!string evaluates to dchar. I would have 
expected char. Why is that?


I think is because they are iterated by ranges as dchar, that's 
equivalent to iterating the unicode symbol.


If they were iterated by char, you would get during the iteration 
the singles pieces of the utf8 encoding, and usually that is not 
what an user is expecting.


Note on the other side that static assert( is(typeof( [0]) == 
immutable(char)) ), so you can iterate the string by chars using 
the index.


- Paolo Invernizzi


Re: pointers, null and Typedef...

2013-08-24 Thread Paolo Invernizzi

On Saturday, 24 August 2013 at 09:19:14 UTC, John Colvin wrote:
On Friday, 23 August 2013 at 18:58:49 UTC, Paolo Invernizzi 
wrote:

On Friday, 23 August 2013 at 12:17:08 UTC, John Colvin wrote:

so, here's the situation:


On 2.063.2 why not something like this:


It's const(void*) not just void*
Unfortunately that breaks it.


Sorry John, you are right, naturally.

- Paolo



templated isNaN

2013-08-24 Thread Paolo Invernizzi
Someone can suggest me a convenient way to declare an 'isNaN' 
templated function that plays well with the 'standard.math.isNaN'?


The target is to be able to define isNaN functions for my custom 
structures, and I want to keep the same name...


---
import std.math;

bool isNaN(T)(T t) if(is(T==string)){ return true; }

// that is really necessary? What if I have my isNaN in different 
modules? Must duplicate?

// bool isNaN(T)(T t) if(is(T:real)) { return std.math.isNaN(t); }

void foo(){
bool b = isNaN(0.0);
}

/d471/f783.d(9): Error: template f783.isNaN does not match any 
function template declaration. Candidates are:

/d471/f783.d(3):f783.isNaN(T)(T t) if (is(T == string))
/d471/f783.d(9): Error: template f783.isNaN(T)(T t) if (is(T == 
string)) cannot deduce template function from argument types 
!()(double)

---

Thanks in advance!

- Paolo Invernizzi


Re: Wrapping an arbitrary class/struct API

2013-08-24 Thread Paolo Invernizzi
On Saturday, 24 August 2013 at 12:12:29 UTC, Joseph Rushton 
Wakeling wrote:


Hi Joseph,

I'm not really a D guru like others, but...

... an I want to wrap it in another struct, B.  If I do this 
manually it would be something like,


struct B
{
private A a;
void foo(int n) { return a.foo(n); }
void foo(Range)(Range r) { return a.foo(r); }
// ... etc ...
}

But suppose that I don't a priori know the list of functions 
(and function arguments) that need to be wrapped.  How could I 
go about working this out, with a generic programming approach?


For this case I would use alias this, if you want to wrap every 
method...


struct B
{
private A a;
alias a this;
}

More specifically, how could I work this out limited to a 
specific function of A (say, foo) ... ?


I think that you have to explicitly wrap them, maybe with a 
template to alleviate the copy/past...

But maybe someone else can suggest a better solution!

- Paolo Invernizzi


Re: Using a range as a reference

2013-08-24 Thread Paolo Invernizzi

On Saturday, 24 August 2013 at 19:51:14 UTC, David wrote:

do you mean refRange?
http://dlang.org/phobos/std_range.html#.refRange


Exactly, thank you!
I've missed it as it is not listed in the tables of the range 
documentation, like the others, but only in the top-index...


- Paolo Invernizzi


Re: Using a range as a reference

2013-08-24 Thread Paolo Invernizzi

On Saturday, 24 August 2013 at 20:24:47 UTC, H. S. Teoh wrote:
On Sat, Aug 24, 2013 at 10:02:56PM +0200, Paolo Invernizzi 
wrote:


I've missed it as it is not listed in the tables of the range
documentation, like the others, but only in the top-index...


That would be a documentation bug. Please file a bug on
http://d.puremagic.com/issues.



Done: http://d.puremagic.com/issues/show_bug.cgi?id=10885

- Paolo Invernizzi


SysTime at compile time

2013-08-23 Thread Paolo Invernizzi
There's a way to use a SysTime at compile-time? It seems 
impossible right now for the presence of the TimeZone.


I want to insert some time-related fields in some structs, but I 
need to have some compile-time check with 'static assert' here 
and there...


Suggestions are welcome, thanks!
Paolo Invernizzi


Re: pointers, null and Typedef...

2013-08-23 Thread Paolo Invernizzi

On Friday, 23 August 2013 at 12:17:08 UTC, John Colvin wrote:

so, here's the situation:


On 2.063.2 why not something like this:

---
import std.typecons;
alias T0 = Typedef!(void*, null, T0);
alias T1 = Typedef!(void*, null, T1);
static assert( ! is(T0 == T1));
struct A
{
T0 t;
this(T0 init)
{
t = init;
}
}
void foo(){
auto a = A(T0(null));
// auto b = A(T1(null)); Error!
}
---

Paolo



Re: SysTime at compile time

2013-08-23 Thread Paolo Invernizzi

On Friday, 23 August 2013 at 19:07:06 UTC, Jonathan M Davis wrote:

On Friday, August 23, 2013 10:39:56 Paolo Invernizzi wrote:

There's a way to use a SysTime at compile-time? It seems
impossible right now for the presence of the TimeZone.

I want to insert some time-related fields in some structs, but 
I

need to have some compile-time check with 'static assert' here
and there...


Getting the system time would require calling C functions 
(which never works
in CTFE), so you can't do what you're trying to do with any 
CTFE solution, let
alone SysTime. Even if there were no TimeZone, it couldn't be 
done.


Thank you Jonathan, in reality I'm not interested in obtaining 
the current time ('Clock.currTIme' et similia), but only in 
checking some basic behaviour involving already forged times.


Something works, in a limited and constrained way, but it seems 
that there's a problem with 'Rebindable' in CTFE:


---
enum t = SysTime(0, UTC());
pragma(msg, t); // SysTime(0L, Rebindable(, (UTC(UTC, UTC, 
UTC
// enum t2 = t + msecs(1000); // typecons.d(956): Error: cannot 
read uninitialized variable this.original in ctfe

enum d = SysTime(1000, UTC()) - SysTime(10, UTC());
pragma(msg, d); // Duration(990L)
---

Paolo Invernizzi




hash for floating

2013-06-15 Thread Paolo Invernizzi

Hi all,

How to implement a proper hash method for a struct/class having 
as a base one or more floating point?


When I compile with the -w flags, dmd 2.063 tells me that the 
function must be size_t toHash() const nothrow @safe.


The point is that the nothrow doesn't permit the std.conv.to 
conversions, while the @safe does not permit the cast().


So how to perform a little math on the floating and then turning 
the result to a proper integer hash?


Suggestions welcome! Thank!

Paolo Invernizzi


Re: [OT] For Andrej Mitrovic, Cairo OpenGL and Windows...

2011-11-25 Thread Paolo Invernizzi
Thank you very much, Andrej

Paolo

On Nov 24, 2011, at 11:44 PM, Andrej Mitrovic wrote:

 OK, it's actually the same samples as the ones using the C API, except
 they've been modified to use the OOP CairoD based on a branch that
 added OpenGL support.
 
 In short, the link I gave you is the one you want.
 
 On 11/24/11, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
 Oh wait, I've just remembered I've had a branch in CairoD (the OOP
 wrapper) that *did* use GL, so I likely have samples for that as well.
 I'll take a look..
 



[OT] For Andrej Mitrovic, Cairo OpenGL and Windows...

2011-11-24 Thread Paolo Invernizzi
Hi all,

We are currently in the process of building cairo 1.10.2 for windows with the 
OpenGL support enabled, for using it in a D program.
This evening (europe time) we probably have succeeded in the build, and 
tomorrow we will try some basic test of functionality.

In the meantime, I've found some posts on Andrej in the cairo mailing list 
about the very same task: cairo, opengl, windows.

Andrej (or others!) have you succeeded in having some basic example of it 
working?

Thank you in advance,
Paolo

Re: std.container ranges

2011-11-02 Thread Paolo Invernizzi
On Nov 2, 2011, at 12:48 PM, Steven Schveighoffer wrote:

 Hello again.
 
 I've read all further replies in this thread, but it seems to me this is the 
 most appropriate place to respond.
 
 Simply put, all of those options are too verbose. If what you want to do is 
 simple, the syntax should also be simple, this is what I love about D. As a 
 side-note, I don't come from Java, but I still expect a container to be able 
 to remove an element by passing it to a method. The verbosity and the 
 details of this operation should be hidden in the implementation of the 
 method and I shouldn't need to know about the details. Otherwise, I could 
 just as well implement my own container.
 
 The basic response to this is, when dealing with containers generically (that 
 is, you know you have a container, but you don't know what type), the remove 
 this element operation is not necessarily a good primitive to have.
 
 Simply because from the myriad of containers, only some can implement this 
 operation efficiently.  Java embeds this operation in the interface, which 
 means any interface you have to a container could potentially use O(n) time 
 to remove that element.  Such an innocuous piece of syntax *should* have a 
 cost if it's not efficient IMO.
 
 BTW, the original question doesn't provide enough information to say remove 
 this element.  Even in Java, if you aren't using the default comparison, you 
 must use a comparator method to determine which one to remove.  If cell.x == 
 x  cell.y == y *is* the comparison operator for the type, then the syntax 
 gets much simpler, because you don't need to pass a specialized comparison 
 function.
 
 In dcollections, removing a specific element (using the default comparison 
 operator for that element) on a *fast lookup* container is as simple as:
 
 container.remove(container.find(x));
 
 Which removes the element x if it's found.  However, this is not defined for 
 containers which use O(n) time to search (such as linked list), you must use 
 std.algorithm.find for that:
 
 container.remove(find(container[], x).begin);
 
 Should work, and takes O(n) time.
 
 -Steve


I can't really understand what is wrong with an inefficient remove this 
element primitive if it's really what the user had to do...
Once it's in the documentation that the operation is inefficient, why the user 
must be forced to dig into the newsgroup to find out some code? 
Why can't that be furnished in a free function, for example?

Cheers, Paolo




contrary of std.utf.toUTFz!(const(wchar)*)

2011-10-07 Thread Paolo Invernizzi
Hi all,

I feel a little stupid, but how to convert  a wchar* zero terminated string 
into a wstring (DMD 2.055)?
I'm digging into Phobos, but right now I've found no way...

Thanks, Paolo

Re: Wrong const attribute?

2011-09-23 Thread Paolo Invernizzi
Thank you all very much.
Paolo

On Sep 22, 2011, at 7:12 PM, Jonathan M Davis wrote:

 On Thursday, September 22, 2011 04:12 Paolo Invernizzi wrote:
 
 The error is a bit confusing but essentially correct. Bar has an immutable 
 member variable. Once it's been initialized, that immutable member variable 
 can never be changed, so you can never assign to a variable of type Bar. 
 Naturally, that includes the member variable in Foo. So, when you constructed 
 your f variable, the bar member variable was initialized, and after that, it 
 can never be assigned to. So, when you try and do it, you get an error. The 
 error message could definitely use some improvement though.
 
 - Jonathan M Davis



Wrong const attribute?

2011-09-22 Thread Paolo Invernizzi
Hi all, 

I've found nothing on bugzilla for that, what I'm missing? Or it's a bug? (DMD 
2.055)

struct Bar {
immutable int i;
this(int j){ i = j; }
}

struct Foo {
Bar bar;
}

void main(){

auto b = Bar(1);

auto f = Foo();
f.bar = Bar(2); // Error: can only initialize const member bar inside 
constructor

}

Cheers, 
Paolo Invernizzi




Re: rdmd problems (OS X Leopard, DMD 2.052)

2011-02-22 Thread Paolo Invernizzi
Hi Magnus,

This is sligthly OT, but... How I loved AnyGui!
It's nice to see you here, in the D bandwagon...

Cheers, 
Paolo Invernizzi

Magnus Lie Hetland Wrote:

 Hi!
 
 When I installed DMD 2.051 on my OS X boxen, the rdmd executable didn't 
 work. I saw others have similar problems online, and concluded that it 
 must have been compiled for a more recent version of OS X (Snow 
 Leopard, I guess) without the necessary compatibility flags.
 
 I found the rdmd sources online [1] and compiled them myself. (Luckily, 
 the other binaries work just fine.) No problems.
 
 Now I'm trying to get DMD 2.052 to work. Same issue with the rdmd 
 executable. I tried to compile the same rdmd.d file with the new 
 compiler/stdlib, but that failed.
 
 $ dmd rdmd.d
 std.contracts has been scheduled for deprecation. Please use 
 std.exception instead.
 std.date and std.dateparse have been scheduled for deprecation. Please 
 use std.datetime instead.
 rdmd.d(34): Error: std.regexp.split at 
 ./../../src/phobos/std/regexp.d(498) conflicts with std.string.split at 
 ./../../src/phobos/std/string.d(69)
 rdmd.d(34): Error: function std.regexp.split (string s, RegExp pattern) 
 is not callable using argument types (string)
 rdmd.d(34): Error: expected 3 function arguments, not 1
 
 I'm sure I can fix this myself -- but I'm guessing there must be a more 
 recent version of the rdmd sources somewhere, assuming that the binary 
 in the distribution was compiled with dmd 2.052...? The version in the 
 trunk at dsource.org seems to be three months old...
 
 For now I just compiled the rdmd.d from dsource.org with dmd 2.051, and 
 use that with dmd 2.052. As rdmd is basically an independent entity, I 
 guess that should work well, but this isn't exactly user-friendly 
 (i.e., having to replace one of the binaries in the distro with one 
 compiled with an older compiler, using sources obtained elsewhere... 
 :-).
 
 Not sure if I'm missing The Way to Do It[tm], or if perhaps I should 
 submit an issue about this?
 
 [1] http://www.digitalmars.com/d/2.0/rdmd.html
 
 -- 
 Magnus Lie Hetland
 http://hetland.org
 



Pop an element from an array inplace?

2010-09-07 Thread Paolo Invernizzi
Hi all,

What's the best way to find an element into an array, drop it and shrink the 
array inplace, in D2?

Thanks in advance, Paolo


TDPL enum greet = Hello;

2010-08-08 Thread Paolo Invernizzi
Hi all,
On page 273 of TDPL, we have:

enum euler = 2.78;
euler = 2.73 // Error! Cannot modify enum value!

But with D 2.047 I can do:

enum greet = Hello;
greet = Ciao; // Ok?

So the question is, enumerated values are constant?
Cheers, Paolo