On Saturday, 17 December 2022 at 00:23:32 UTC, thebluepandabear
wrote:
I am reading the fantastic book about D by Ali Çehreli, and he
gives the following example when he talks about variadic
functions:
```D
int[] numbersForLaterUse;
void foo(int[] numbers...) {
numbersForLaterUse = numbers
On Saturday, 17 December 2022 at 02:42:22 UTC, Paul wrote:
I see code like this from time to time. Are the leading
underscores significant, in general, in the D language? Is it
just programmer preference? Is it a coding practice, in
general, that is common...even outside of D? Thanks for any
On Wednesday, 14 December 2022 at 11:30:07 UTC, Vitaliy Fadeev
wrote:
Hi! I open a device under Windows:
```
HANDLE h = CreateFileW( ... );
```
in procedure:
```
HANDLE open_keyboard_device2( LPCWSTR path, int* error_number )
{
...
HANDLE dev_handle =
CreateFileW(
On Monday, 12 December 2022 at 17:23:36 UTC, lili wrote:
```
int[string] aa = ["ok":1, "aaa":2, "ccc":3, "ddd":4];
foreach (k ; aa.byKey)
{
if (k == "aaa") {
aa.remove(k);
aa["ww"] = 33;
}
if (k == "w
On Saturday, 3 December 2022 at 18:59:58 UTC, zoujiaqing wrote:
```
dub build --compiler=ldc2 --arch=arm64-apple-macos
Starting Performing "debug" build using ldc2 for aarch64,
arm_hardfloat.
Building taggedalgebraic 0.11.22: building configuration
[library]
Building eventcore 0.9.2
On Sunday, 18 December 2022 at 16:17:40 UTC, Salih Dincer wrote:
On Saturday, 10 December 2022 at 11:13:57 UTC, Nick Treleaven
wrote:
It was bizarre and confusing that assignment syntax was
implemented for functions and methods not explicitly marked
with @property.
Hi Nick, do you think this
On Sunday, 18 December 2022 at 17:05:45 UTC, Sergey wrote:
On Friday, 16 December 2022 at 20:57:30 UTC, Dariu Drew wrote:
Hi! i need help in can i create a serve API, what library i
should use? what documentation i should read?
Check the bench: https://github.com/tchaloupka/httpbench
there are
On Sunday, 18 December 2022 at 16:21:05 UTC, Salih Dincer wrote:
Don't you think it's interesting that it doesn't need unary
operator overloading?
```d
import std.stdio;
struct S
{
int value;
alias opCall this;
this(int i) {
value = i;
}
alias opAssign = opCall;
@property opC
On Saturday, 19 November 2022 at 14:07:59 UTC, Nick Treleaven
wrote:
Hi,
The following seems like a bug to me (reduced code, FILE*
changed to int*):
```d
@safe:
struct LockedFile
{
private int* fps;
auto fp() return scope => fps;
}
void main()
{
int* p;
{
auto lf = Lo
On Friday, 16 December 2022 at 12:17:40 UTC, Nick Treleaven wrote:
This code segfaults when the GC calls the dtor after the
unittest succeeds:
```d
unittest
{
int i;
struct S
{
~this() { i++; }
}
(*new S).destroy;
}
```
It seems destroy clears the context pointer. I
On Tuesday, 13 December 2022 at 19:28:44 UTC, Leonardo A wrote:
Hello. How to use version in dub?
https://dlang.org/spec/version.html
"The version level and version identifier can be set on the
command line by the -version"
I tried everything but noting.
Look for a file called dub.json.
On Thursday, 15 December 2022 at 21:43:07 UTC, TheZipCreator
wrote:
is there a compiled binary of GDC anywhere? I looked at
https://www.gdcproject.org/downloads, and the link there goes
to winlibs, but after downloading the archive I couldn't find
gdc anywhere in it. I did some research and [it
On Saturday, 10 December 2022 at 05:46:26 UTC, thebluepandabear
wrote:
In most languages there is some sort of `List` type, is that
the same for D?
What you're probably talking about is called a union in the C
world. There is a nice (free) book by Ali that every Dlang
beginner should probab
On Thursday, 8 December 2022 at 16:55:34 UTC, johannes wrote:
/we-/we/sqlite3/package.d(121): Error: semicolon expected
following auto declaration, not `32`
/we-/we/sqlite3/package.d(121): Error: declaration expected,
not `32`
/we-/we/sqlite3/package.d(122): Error: semicolon expected
following
On Monday, 19 December 2022 at 03:31:05 UTC, thebluepandabear
wrote:
On Sunday, 18 December 2022 at 22:17:04 UTC, j wrote:
On Saturday, 10 December 2022 at 05:46:26 UTC,
thebluepandabear wrote:
In most languages there is some sort of `List` type, is
that the same for D?
What you're probably
On Monday, 19 December 2022 at 04:26:39 UTC, Salih Dincer wrote:
On Sunday, 18 December 2022 at 21:17:02 UTC, j wrote:
Why are you using `@property` everywhere?
You are right but if I don't use it for `opCall()` the output
will be like `S(9)`. Likewise, if I don't use `inout`, the
program i
On Monday, 19 December 2022 at 04:26:39 UTC, Salih Dincer wrote:
On Sunday, 18 December 2022 at 21:17:02 UTC, j wrote:
Why are you using `@property` everywhere?
You are right but if I don't use it for `opCall()` the output
will be like `S(9)`. Likewise, if I don't use `inout`, the
program i
I am trying to use Tango in a dub project because I need a
HashSet. I added Tango as a dependency to the dub.json, but now
dub gives me a bunch of depreciation warnings and a few errors,
like
../../../.dub/packages/tango-1.0.3_2.068/tango/tango/util/log/Log.d(349,51):
Error: undefined identif
Since I just do "dub build", I assume it invokes dmd? I have
v2.072.0.
I thought Tango was obsolete a long time ago.
Is there a specific reason you need to use Tango and can't use
Phobos?
I need a Set implementation and from what I understand there
isn't one in Phobos right now?
Try an older version.
Before resorting to that, I am also trying to "dub build
--compiler=gdc". Getting different types of errors:
../../../.dub/packages/tango-1.0.3_2.068/tango/tango/math/IEEE.d:614:17: error:
instead of C-style syntax, use D-style syntax 'real[3][] vals' [-Werror]
sta
Have you seen https://github.com/economicmodeling/containers it
has a HashSet
http://economicmodeling.github.io/containers/containers/hashset.HashSet.html
Just curious, how is it different from Tango's implementation?
Is it possible to refer to an array element by a descriptive
name, just for code clarity, without performance overhead? E.g.
void aFunction(double[] arr) {
double importantElement = arr[3];
... use importantElement ...
}
But the above, I suppose, introduces an extra copy operation?
Thank you for all your answers. I was concerned because I'm
dealing with a small function that is called many times and where
the bulk of the calculations in the simulation takes place. So
even 5% performance difference would be significant for me. But
it is good to know that compilers are smar
Let's say I want to create an array of random numbers and do some
operations on them:
void main() {
import std.random;
//Generate array of random numbers
int arrSize = 1;
double[] arr = new double[](arrSize);
foreach (i; 0..arrSize)
arr[i] = uniform01();
I'm not sure if it's what happening in this case but, in code
as simple as this, function calls can sometimes be the
bottleneck. You should see how compiling with/without -O
affects performance, and adding `pragma(inline)` to funcB.
When compiled with -inline, the profiler does not report the
In anycase, what is the correct notation for indexing?
x = new int[][](width, height)
and x[height][width] or x[width][height]?
It's x[width][height], but because indexing is 0-based, largest
valid indexes are
x[width-1][height-1].
I'm not sure if it's what happening in this case but, in code
as simple as this, function calls can sometimes be the
bottleneck. You should see how compiling with/without -O
affects performance, and adding `pragma(inline)` to funcB.
I guess my question is whether it is possible to have meaning
I have translated some simulation code from Java into D (a few
classes, mostly manipulation of double arrays in small methods).
D version runs 10-30% slower than Java (ldc2, dub release build).
Profiling did not show any obvious bottlenecks. I am wondering
whether I missed something, or such pe
Without seeing the source there is nothing we can do.
Usually performant d-code looks quite diffrent from java code.
For example to avoid the gc :)
Well it is actually ODE solver from Numerical recipes (originally
in C++) that I am trying to do in D. Code translation seems very
straightforward
What is the D idiom for removing array elements that are present
in another array?
Is this the right/fastest way?
int[] a = [1, 2, 3, 4, 5, 6, 7, 4];
int[] b = [3, 4, 6];
auto c = a.remove!(x => b.canFind(x));
assert(c == [1, 2, 5, 7]);
On Thursday, 26 January 2017 at 13:21:38 UTC, Dukc wrote:
import std.stdio, std.algorithm, std.range, std.array;
int[] a = [1, 2, 3, 4, 5, 6, 7, 4];
int[] b = [3, 4, 6];
auto sortedB = sort(b.dup);
auto c = a
. filter!(i => !sortedB.contains(i))
. array
;
assert(c == [1, 2, 5, 7]);
If array
On Friday, 27 January 2017 at 08:15:56 UTC, Dukc wrote:
TickDuration(28085)
TickDuration(42868)
TickDuration(1509)
Thank you, this is very helpful. I am also wondering why the
standard library doesn't have convenience functions for this,
e.g. like Java's removeAll? Now there's more typing t
On Friday, 27 January 2017 at 08:15:56 UTC, Dukc wrote:
void main()
{ import std.stdio, std.algorithm, std.range, std.array,
std.datetime;
int[] a = [1, 2, 3, 4, 5, 6, 7, 4].cycle.take(2000).array;
int[] b = [3, 4, 6].cycle.take(2000).array;
void originalMethod()
{ auto c
On Saturday, 28 January 2017 at 11:54:58 UTC, cym13 wrote:
I am trying to wrap my head around lazy evaluation during
filtering/mapping, but there's something I don't understand.
I want to create an array, square some elements, remove some
elements from original array and add the squared ones
On Sunday, 29 January 2017 at 23:48:40 UTC, Jordan Wilson wrote:
You need to do something like this:
auto arrMap = arr.filter!(x => x > 5).map!(x => x^^2).array;
It's because arrMap is lazy evaluated.
So does it mean that I cannot assign FilterResult and MapResult
to a variable and safely u
On Monday, 30 January 2017 at 00:17:51 UTC, ag0aep6g wrote:
[...]
Great explanation, thank you!
On Monday, 30 January 2017 at 00:17:51 UTC, ag0aep6g wrote:
Removing works by overwriting the array with only the wanted
values and discarding the rest.
But then why do I get this:
import std.stdio, std.algorithm, std.array;
int[] arr;
foreach (i; 0..10) arr ~= i; // [0, 1, 2, 3,
On Monday, 30 January 2017 at 10:45:03 UTC, cym13 wrote:
Meh.
Forget that, bad memory. remove isn't working in-place. However
slapping ".array" is still asking explicitely for reallocation,
so just forget it. Here is a code that works:
import std.conv;
import std.stdio;
import std.format;
i
On Monday, 30 January 2017 at 12:31:33 UTC, albert-j wrote:
OK, got it. Can you do removal without reallocation with
std.container.array?
Array!int arr;
foreach (i; 0..10) arr ~= i;
Sorry, sent too early.
arr = arr[].remove!(x=> x > 5); //Doesn't work withouth
calling .Array!
40 matches
Mail list logo