Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread rikki cattermole via Digitalmars-d-learn

Okay you have misunderstand a lot here.

We have two types of arrays:

- Static, fixed sized stored on stack.
- Dynamic, variable sized, stored on the heap.

However dynamic arrays are not actually a distinct type in the type 
system, its a language extension to use runtime hooks using the GC.


What dynamic arrays are in the language is just slices.

A slice is a length + pointer pair. This is where almost all of the 
syntax for dynamic arrays come from.


```d
int[] slice;
```

That is a slice.

```d
slice ~= 32;
```

Now it is a dynamic array as it was allocated via the GC.

```d
int[4] staticArray;
slice = staticArray[];
```

The slice is now able to modify the staticArray!


Re: Is defining get/set methods for every field overkill?

2022-11-16 Thread rikki cattermole via Digitalmars-d-learn

I wouldn't bother.

They are const, they can't change.

Nothing to protect, nothing to synchronize.


Re: Actual lifetime of static array slices?

2022-11-14 Thread rikki cattermole via Digitalmars-d-learn

On 15/11/2022 5:10 PM, Elfstone wrote:
I just checked the DIP list and #1000 is marked superseded. Any idea 
what supersedes it?


The implementation.


Re: Drawing a line code

2022-11-07 Thread rikki cattermole via Digitalmars-d-learn

On 07/11/2022 10:29 PM, Joel wrote:

Ok, this is working:


I'm glad to hear it!

Pathing algorithms can be quite fun to mess around with.


Re: Drawing a line code

2022-11-06 Thread rikki cattermole via Digitalmars-d-learn

On 07/11/2022 5:48 AM, Joel wrote:
The algorithm is too hard for me to work out and dg2d doesn't help 
either. I want my code fixed up so that works from any two points.


Its not as complex as that page initially looks.

```
plotLine(x0, y0, x1, y1)
dx = abs(x1 - x0)
sx = x0 < x1 ? 1 : -1
dy = -abs(y1 - y0)
sy = y0 < y1 ? 1 : -1
error = dx + dy

while true
plot(x0, y0)
if x0 == x1 && y0 == y1 break
e2 = 2 * error
if e2 >= dy
if x0 == x1 break
error = error + dy
x0 = x0 + sx
end if
if e2 <= dx
if y0 == y1 break
error = error + dx
y0 = y0 + sy
end if
end while
```

That is the pseudo code you want.

Its just a matter of typing the variables to something like int.

I can recommend:

https://www.amazon.com/Computer-Graphics-Principles-Practice-3rd/dp/0321399528

and

https://www.amazon.com/Computer-Graphics-C-Version-2nd/dp/0135309247

(The updated version should be fine too)

If you wish to understand it.


Re: Linking not working properly Windows 11

2022-11-05 Thread rikki cattermole via Digitalmars-d-learn

I've looked up three of those names, they are all deprecated.

I'm wondering if Microsoft have removed them.


Re: Linking not working properly Windows 11

2022-11-05 Thread rikki cattermole via Digitalmars-d-learn
Try ldc, if that works then its just a missing library that needs to be 
linked against regarding MS CRT.


Re: Makefiles and dub

2022-11-05 Thread rikki cattermole via Digitalmars-d-learn

On 06/11/2022 1:16 AM, Imperatorn wrote:

On Saturday, 5 November 2022 at 11:38:09 UTC, rikki cattermole wrote:

We have a few build formats that dub can generate for you automatically:

```
visuald - VisualD project files
sublimetext - SublimeText project file
cmake - CMake build scripts
build - Builds the package directly
```

Unfortunately none of them are make, it would be nice to have that if 
you are looking to contribute!


Wait, dub can generate all those? I only knew about visuald


build is just dub and doesn't emit any project files.

But yes, it has two others (although idk how much they get used, or how 
complete).


Re: Makefiles and dub

2022-11-05 Thread rikki cattermole via Digitalmars-d-learn

We have a few build formats that dub can generate for you automatically:

```
visuald - VisualD project files
sublimetext - SublimeText project file
cmake - CMake build scripts
build - Builds the package directly
```

Unfortunately none of them are make, it would be nice to have that if 
you are looking to contribute!


Re: Unit testing a function returning void

2022-11-03 Thread rikki cattermole via Digitalmars-d-learn

You could redirect stdout to a file of your choosing and test against that.

Although ideally you would instead take as an argument to print some 
sort of output range or Appender. Then you could test against that instead.


Re: Make IN Dlang

2022-11-01 Thread rikki cattermole via Digitalmars-d-learn

Something to consider:

dub can be used as a library.

You can add your own logic in main to allow using your build 
specification to generate a dub file (either in memory or in file system).


Re: Replacing tango.text.Ascii.isearch

2022-10-28 Thread rikki cattermole via Digitalmars-d-learn

On 29/10/2022 11:05 AM, Siarhei Siamashka wrote:
And as for the D language and Phobos, should "ß" still uppercase to 
"SS"? Or can we change it to uppercase "ẞ" and remove German from the 
list of tricky languages at 
https://dlang.org/library/std/uni/to_upper.html ? Should Turkish be 
listed there?


That particular function, is based upon the simple mappings provided by 
UnicodeData.txt and (should be) in compliance of the Unicode standard.


The only thing we need to do is regenerate the tables backing it 
whenever Unicode updates.


Note the behavior you are asking for is defined in the Unicode database 
file SpecialCasing.txt which have not been implemented.


```
# The German es-zed is special--the normal mapping is to SS.
# Note: the titlecase should never occur in practice. It is equal to 
titlecase(uppercase())


00DF; 00DF; 0053 0073; 0053 0053; # LATIN SMALL LETTER SHARP S
```

That file is how you support languages like Turkish. We currently don't 
have it implemented. It requires operating on a whole string and to pass 
in what language rules to apply (i.e. Turkish, Azeri).


Re: Importing modules under DUB on Windows

2022-10-28 Thread rikki cattermole via Digitalmars-d-learn

On 29/10/2022 4:15 AM, DLearner wrote:

However, going forward, I don't want copies of OM anywhere other than UD.


If you want your own private library on your system (that will get used 
a lot), you can create a package and use ``$ dub add-local .`` to add it 
to the available packages for lookup, without needing a version control 
system.


Then you just add it as a dependency on an as needed basis (use ``*`` 
for version should work fine).


Re: Importing modules under DUB on Windows

2022-10-27 Thread rikki cattermole via Digitalmars-d-learn

On 28/10/2022 5:40 AM, DLearner wrote:
Maybe fewer people use it under Windows, so Windows constructs don't get 
exercised so much.


I have actively contributed to dub specifically for Windows in the last 
year :)


There is enough of us.

Also UNC paths (those with drives and then the slash) are actually 
absolute, not relative.


There are relative ones, but the path processing in dub is pretty 
simplified.


You have to stick to completely relative, POSIX style.

https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats

You should be working with relatives paths in respect to the 
$PACKAGE_DIR, not the compiler or any root location of your file system 
(such as the drive would indicate).


https://dub.pm/package-format-json.html#environment-variables


Re: Replacing tango.text.Ascii.isearch

2022-10-26 Thread rikki cattermole via Digitalmars-d-learn

On 26/10/2022 6:49 PM, Siarhei Siamashka wrote:

On Wednesday, 26 October 2022 at 05:17:06 UTC, rikki cattermole wrote:
if you are able to ignore that Unicode is a thing, I'd recommend it. 
It is complicated, as we humans are very complicated ;)


I can't ignore Unicode, because I frequently have to deal with Cyrillic 
alphabet ;) Also Unicode is significantly simpler than a set of various 
incompatible 8-bit encodings (such as 
[CP1251](https://en.wikipedia.org/wiki/Windows-1251) vs. variants of 
[KOI-8](https://en.wikipedia.org/wiki/KOI-8) vs. [ISO/IEC 
8859-5](https://en.wikipedia.org/wiki/ISO/IEC_8859-5)) that were 
simultaneously in use earlier and caused a lot of pain. But I'm surely 
able to ignore the peculiarities of modern Turkish Unicode and wait for 
the other people to come up with a solution for D language if they 
really care.


Cyrillic isn't an issue.

Lithuanian, Turkish and Azeri are the ones with the biggest issues.

There is a bunch of non-simple mappings for Latin, Armenian and Greek, 
but they are not language dependent. There is six conditional ones which 
are all Greek.


So if you are not dealing with these languages (even if you are, a 
simple replace should be easy to do for most), you should be fine with 
the simple mappings supported by std.uni.


Re: Replacing tango.text.Ascii.isearch

2022-10-25 Thread rikki cattermole via Digitalmars-d-learn

On 26/10/2022 6:06 PM, Siarhei Siamashka wrote:
Should we ignore the `"D should strive to be correct, rather than fast"` 
comment from bauss for now? Or some actions can be taken to improve the 
current situation?


Bauss is correct.

It should be implemented but it does not need to be fast.

But yeah, if you are able to ignore that Unicode is a thing, I'd 
recommend it. It is complicated, as we humans are very complicated ;)


Re: Replacing tango.text.Ascii.isearch

2022-10-25 Thread rikki cattermole via Digitalmars-d-learn

On 25/10/2022 5:17 PM, Siarhei Siamashka wrote:
Wow, I didn't expect anything like this and just thought that the 
nightmares of handling 8-bit codepages for non-English languages ceased 
to exist nowadays. Too bad. What are the best practices to deal with 
Turkish text in D language?


std.uni doesn't support it.

For casing it only supports the simple mappings which are 1:1 and not 
language dependent.


I haven't got to it yet for my own string handling library, so I can't 
point you to that (even if it was not ready).


I'm sure somebody has got it but you may end up wanting to use ICU 
unfortunately.


Re: Supporting foreach (k, v; T.init) for a user-defined (container) type

2022-10-24 Thread rikki cattermole via Digitalmars-d-learn

From there down:

https://dlang.org/spec/statement.html#foreach_over_struct_and_classes


Re: How to use dub with ldc

2022-10-22 Thread rikki cattermole via Digitalmars-d-learn
If you only have one compiler available, dub will use it (doesn't matter 
if its dmd/ldc/gdc).


rdmd is a tool that wraps dmd/ldc/gdc.

https://github.com/dlang/tools/blob/master/rdmd.d

If you only have ldc in your PATH variable, rdmd just "just work".


Re: Can someone tell me what the compiler thought I was trying to do?

2022-10-18 Thread rikki cattermole via Digitalmars-d-learn

On 19/10/2022 2:30 PM, H. S. Teoh wrote:

On Wed, Oct 19, 2022 at 01:15:37AM +, Adam D Ruppe via Digitalmars-d-learn 
wrote:

On Wednesday, 19 October 2022 at 00:57:31 UTC, H. S. Teoh wrote:

Has it really been implemented?  I tested the latest git master, the
following code doesn't compile:


it only applies to types, not to functions.


Wat... so what's the use of it then?  So it's not possible to mark the
return value of an int function @mustUse without making, in theory,
*all* ints @mustUse?

I must confess I'm baffled as to the purpose of this strange design.


Oh but it gets better:

From C23 draft:

The nodiscard attribute shall be applied to the identifier in a function 
declaration or to the definition
of a structure, union, or enumeration type. If an attribute argument 
clause is present, it shall have

the form:
( string-literal )


Re: Can someone tell me what the compiler thought I was trying to do?

2022-10-18 Thread rikki cattermole via Digitalmars-d-learn

https://github.com/dlang/dmd/blob/master/druntime/src/core/attribute.d#L292


Re: Find out what type my class is being converted to for comparisons

2022-10-18 Thread rikki cattermole via Digitalmars-d-learn

Well its not a type system issue.

Making u = n, that'll returns true.

So the problem almost certainly lies with IEEE-754.
They are horrible to compare (float/double).

Unfortunately you are stuck calling functions like isClose to compare.

https://dlang.org/phobos/std_math_operations.html#.isClose

Full code extracted from above:

```d
import std;

void main()
{
auto m = new Matrix!(2)();
m.data = [1.0, 0.0, 0.0, 1.0].dup;
auto n = new Matrix!(2)();
n.data = [2.0, 3.0, 4.0, 5.0].dup;

auto u = mult(m, n);
writeln("u.data vs n.data:");
for (int i = 0; i < u.data.length; ++i)
writeln(u.data[i], "\t", n.data[i]);

// using opEquals() directly is working, but it doesn't seem to be 
being used
//assert(opEquals(u,n),"\"opEquals(u, n)\" is failing."); // this 
works fine

assert(u == n, "\"u == n\" is failing."); // this fails. Why?
}

class Matrix(size_t X, size_t Y = X)
{
const size_t x_length = X;
const size_t y_length = Y;

double[X * Y] data;

/// both matrices have to have an identical shape to compare
/// each element must be identical to match
bool opEquals(size_t X, size_t Y)(const Matrix!(X, Y) m1, const 
Matrix!(X, Y) m2)

{
for (int i = 0; i < m1.data.length; ++i)
if (m1.data[i] != m2.data[i])
return false;
return true;
}
}
```


Re: library to solve the system of linear equations

2022-10-17 Thread rikki cattermole via Digitalmars-d-learn

On 18/10/2022 9:37 AM, mw wrote:
Maybe Mir should add static check for supported complier versions, 
rather than let user try and error.


Dub has dependency checks for compiler/dub in it.

It doesn't need to be in code.


Re: Is it possible? branching on debug info

2022-10-16 Thread rikki cattermole via Digitalmars-d-learn

There is: D_Optimized

https://dlang.org/spec/version.html#predefined-versions

But nothing for debug info.

I'm afraid I think you'll just have to use a version (unless you want to 
add it).


Re: How do I correctly install packages for use with Visual Studio?

2022-10-16 Thread rikki cattermole via Digitalmars-d-learn

On 17/10/2022 12:09 AM, Decabytes wrote:
I'm trying to set up Visual Studio 2022 with Visual D, and I'm running 
into issues trying to get my project to build correctly. It's a double 
whammy because I've never used Visual Studio before (Just an Emacs Guy), 
but I need to debug my D programming and according to the 
[documentation](https://wiki.dlang.org/Debuggers) this is my only option 
on Windows.


You don't need to develop with Visual Studio for native executables to 
debug using it.


Build your program with debug symbols (-g) and open the executable as a 
project. You can then debug it with source code support.


Re: Replacing tango.text.Ascii.isearch

2022-10-13 Thread rikki cattermole via Digitalmars-d-learn

On 13/10/2022 9:55 PM, bauss wrote:

Yeah, text isn't easy :D


Indeed!

It has me a bit concerned actually, I'm wondering if my string stuff 
will even work correctly for UI's due to performance issues.


My string builder for instance allocates like crazy just to do slicing. 
But hey, at least I can feel confident that my general purpose allocator 
& infrastructure is working correctly!


Re: Replacing tango.text.Ascii.isearch

2022-10-13 Thread rikki cattermole via Digitalmars-d-learn

On 13/10/2022 9:42 PM, bauss wrote:
Oh and to add onto this, IFF you have to do it the hacky way, then 
converting to uppercase instead of lowercase should be preferred, 
because not all lowercase characters can perform round trip, although a 
small group of characters, then using uppercase fixes it, so that's a 
relatively easy fix. A round trip is basically converting characters 
from one culture to another and then back. It's impossible with some 
characters when converting to lowercase, but should always be possible 
when converting to uppercase.


You will want to repeat this process with normalize to NFKC and 
normalize to NFD before transforming. Otherwise there is a possibility 
that you will miss some transformations as the simplified mappings are 
1:1 for characters and not everything is representable as a single 
character.




Re: Replacing tango.text.Ascii.isearch

2022-10-13 Thread rikki cattermole via Digitalmars-d-learn

On 13/10/2022 9:27 PM, bauss wrote:
This doesn't actually work properly in all languages. It will probably 
work in most, but it's not entirely correct.


Ex. Turkish will not work with it properly.

Very interesting article: 
http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html


Yes turkic languages, they require a state machine and quite a bit of 
LUTs to work correctly.


You also need to provide a language and it has to operate on the whole 
string, not individual characters.


I didn't think it was relevant since Ascii was in the original post ;)


Re: Visual D doesn't work, now Visual Studio Code / D doesn't work!!!! ....

2022-10-02 Thread rikki cattermole via Digitalmars-d-learn
Visual Studio with its c++ components can debug D code, it should not 
require Visual D to do so.


Open executable as project.

If this does not work, you have a serious issue in your system/VS install.

This may help to narrow down what is going on.



Re: Is there a way to mark a dub package as linux only?

2022-09-27 Thread rikki cattermole via Digitalmars-d-learn

On 28/09/2022 7:18 AM, Alain De Vos wrote:

Don't forget there is also BSD


Should already be supported.

Platform specific settings are supported through the use of field name 
suffixes. Suffixes are dash separated list of operating 
system/architecture/compiler identifiers, as defined in the D language 
reference, but converted to lower case. The order of these suffixes is 
os-architecture-compiler, where any of these parts can be left off. 
Additionally on Windows the architectures x86_omf and x86_mscoff can be 
used with dmd to differentiate between 32 bit object formats used with 
the --arch switch. Examples:


https://dub.pm/package-format-json.html#build-settings



Re: Is there a way to mark a dub package as linux only?

2022-09-27 Thread rikki cattermole via Digitalmars-d-learn
Alternatively we could just extend platforms to work in places other 
than configurations.


https://dub.pm/package-format-json.html#configuration-settings



Re: Detect uninitialized class var access

2022-09-26 Thread rikki cattermole via Digitalmars-d-learn

Currently in D you would be forced to create a vtable struct manually.

But if we had something like signatures you could do this:

```d
struct Foo {
//...
}

struct Bar {
InputRange input;
}

void doIt() {
Bar bar;
Foo* foo = new Foo;
bar.input = foo;
}
```

Classes are not the only way to do OOP :)



Re: Is this a new bug ?

2022-09-24 Thread rikki cattermole via Digitalmars-d-learn

```d
version(all) {
__gshared:
uint test2;
}

uint test;
```

Output with -vtls:

```
Up to  2.079.1: Success with output: onlineapp.d(9): test is thread 
local
Since  2.080.1: Success with output: onlineapp.d(9): `test` is 
thread local

```

Looks fine to me.



Re: dub lint

2022-09-15 Thread rikki cattermole via Digitalmars-d-learn



https://github.com/dlang/dub/issues/2483


Re: OpenXR library bindings etc

2022-09-09 Thread rikki cattermole via Digitalmars-d-learn
Apart from not linking against OpenXR, I'm not seeing anything obviously 
wrong in that binding.


Re: Error "Unexpected '\n' when converting from type LockingTextReader to type int"

2022-09-07 Thread rikki cattermole via Digitalmars-d-learn

On 08/09/2022 11:24 AM, Synopsis wrote:

On Wednesday, 7 September 2022 at 23:06:44 UTC, rikki cattermole wrote:

Text in buffer: "123\n"

Read: "123"
Text in buffer: "\n"

Read: exception, expecting number for "\n"

Changing your readf format specifier to include the new line should work.

https://dlang.org/phobos/std_stdio.html#.File.readf



Thank you!
Adding the \n seems to solve my problem: ```readf("%s\n", )```

I have two further questions about this!

a- What is the difference with this syntax with the exclamation mark? 
```readf!"%s\n"(f1.num);```


That is a template.

It'll type check that the format specifier matches your arguments.

https://tour.dlang.org/tour/en/basics/templates

b- Do I need to put ```/n``` in every readf statement? I mean, 
considering that every input gets entered after pressing intro key (and 
I guess this is what introduce the \n)


Yes.



Re: Error "Unexpected '\n' when converting from type LockingTextReader to type int"

2022-09-07 Thread rikki cattermole via Digitalmars-d-learn

Text in buffer: "123\n"

Read: "123"
Text in buffer: "\n"

Read: exception, expecting number for "\n"

Changing your readf format specifier to include the new line should work.

https://dlang.org/phobos/std_stdio.html#.File.readf


Re: Reference to an unresolved external symbol

2022-09-07 Thread rikki cattermole via Digitalmars-d-learn



On 07/09/2022 10:14 PM, Injeckt wrote:

On Wednesday, 7 September 2022 at 10:01:11 UTC, rikki cattermole wrote:


You have probably forgotten to link against user32.


I guess you right. But I don't know how i gonna link libs when I'm using 
"dmd main.d". Tell me please.


I think it is as simple as adding user32.lib to dmd (directly).


Re: Reference to an unresolved external symbol

2022-09-07 Thread rikki cattermole via Digitalmars-d-learn



You have probably forgotten to link against user32.


Re: How to link a msvcr120.dll in an inverse recursive way after a Windows .exe binary deployment

2022-09-04 Thread rikki cattermole via Digitalmars-d-learn
I've been reading up fairly recently on RPATH for *nix which does what 
you want. Unfortunately as far as I've found there is no way to do this 
on Windows without an extra executable.


Re: Best practice for dub registry package and module names

2022-09-03 Thread rikki cattermole via Digitalmars-d-learn



I cannot recommend looking at how Adam has done it.

I've been trying to get him to change it since he originally did it.

It has known issues and yes it will still pull in all modules thanks to 
-I behavior except you get fun things like linker errors.


Keep in mind, you are trying to optimize development & maintenance time 
associated with build & package management. Not optimize for quickest 
build times. So it isn't wasteful, you're just focusing on a different 
metric.


Re: Best practice for dub registry package and module names

2022-09-03 Thread rikki cattermole via Digitalmars-d-learn



Yeah you're over thinking this.

It is a single dub package with a namespacing package directory.


Re: Best practice for dub registry package and module names

2022-09-03 Thread rikki cattermole via Digitalmars-d-learn

This slightly smells, single module dub packages.

What does each module do?


Re: Constructors not working

2022-09-02 Thread rikki cattermole via Digitalmars-d-learn

I think you are wanting opAssign not opBinary.

Also you made a mistake, since its a struct you don't want to new it 
when you construct and return it.


```d
return new Time(secos / 3600, (secos % 3600) / 60, secos % 60);
```

Would be a ``Time*`` not ``Time`` which is what you returned.


Re: Disk write in a "for" loop with RwMutex never happens

2022-08-29 Thread rikki cattermole via Digitalmars-d-learn



On 30/08/2022 8:16 AM, Gavin Ray wrote:

It must have been the "writing at end of file" bit?


I don't know.

It read like it should work.

The offsets were correct, it just didn't work *shrug*.


Re: Disk write in a "for" loop with RwMutex never happens

2022-08-29 Thread rikki cattermole via Digitalmars-d-learn
After a bunch of playing around I managed to determine that it is as 
simple as the mode.


exists(dbFileName) ? "r+" : "w+"



Will fix it.

Of course you shouldn't delete the file like that method is doing. It 
should probably reinitialize the FILE* descriptor.


Re: How to build DMD/Phobos on Windows

2022-08-24 Thread rikki cattermole via Digitalmars-d-learn

For dmd you use build.d that is in the repository.

For phobos win64.mak (used for 32bit by default as well):

"# Makefile to build D runtime library phobos{64,32mscoff}.lib for 
Windows MSVC"


So MSVC make.

Beyond that idk, but its starting point (oh and druntime is now in dmd 
repo, so ugh... yeah)


Re: Programs in D are huge

2022-08-18 Thread rikki cattermole via Digitalmars-d-learn



On 19/08/2022 4:56 AM, IGotD- wrote:
BetterC means no arrays or strings library and usually in terminal tools 
you need to process text. Full D is wonderful for such task but betterC 
would be limited unless you want to write your own array and string 
functionality.


Unicode support in Full D isn't complete.

There is nothing in phobos to even change case correctly!

Both are limited if you care about certain stuff like non-latin based 
languages like Turkic.


Re: My programs issues

2022-08-10 Thread rikki cattermole via Digitalmars-d-learn



On 11/08/2022 12:36 AM, pascal111 wrote:
2) I used "goto", I heard from someone before that using "goto" isn't 
good programming feature.


This is mostly a historical debate at this point.

Back 40 years ago, goto wasn't typically limited within a procedure and 
doesn't have any checks in place to prevent you doing bad things.


These days languages will implement such checks (including D).

Some of the historical papers which debate this can be read from the 
book Literate Programming by Donald Knuth. If you do get the chance to 
read it, its a good read for cover to cover and teaches you a lot of the 
historical context that you may not get elsewhere.


https://www.amazon.com/Literate-Programming-Lecture-Notes-Donald/dp/0937073806


Re: dirEntries() does not do source files *.d

2022-08-09 Thread rikki cattermole via Digitalmars-d-learn

Its working for me.

lpha@DESKTOP-RB97SA4 
[/cygdrive/p/ProjectSidero/basic_memory/source/sidero/base/text/unicode$ 
rdmd --eval=$'import std; writeln(dirEntries(`.`, `*.d`, 
SpanMode.shallow));' 
[".\\casefold.d", ".\\casing.d", ".\\comparison.d", 
".\\composing.d", ".\\defs.d", ".\\normalization.d", ".\\readonly.d", 
".\\wordbreak."]


Check what directory it is running in by called getcwd.

https://dlang.org/phobos/std_file.html#getcwd


Re: Obsecure problem 1

2022-07-30 Thread rikki cattermole via Digitalmars-d-learn

It is a pretty straight forward.

You tried to access memory out of bounds of the slice.

https://github.com/pascal111-fra/D/blob/main/dcollect.d#L34

That for loop is problematic in a number of ways.

You should not use int, or uint to index into memory, only size_t should 
be used. It is an alias to either uint or ulong based upon the size of a 
pointer.


```d
for(size_t i = ch.length - 1; i >= 0; i--)
```

Would be the corrected line.

However, it is still not correct, what happens when ch.length is zero? 
It'll wrap around and become a very large number. That is most likely 
what happened here.


To do this safely in D, use the foreach_reverse statement instead. There 
are very few reasons to use for loops in D.


https://dlang.org/spec/statement.html#foreach-range-statement

Adjusted:

```d
foreach_reverse(i; 0 .. ch.length)
```

However this is not efficient as you are reallocating constantly.

```d
char[] ch_rev;
ch_rev.length = ch.length;

size_t offset;
foreach_reverse(c; ch)
ch_rev[offset++] = c;
```


Re: "strtok" D equivalent

2022-07-28 Thread rikki cattermole via Digitalmars-d-learn
I don't know of a D version, although it should be pretty easy to write 
up yourself.


But you can always use strtok itself.

https://github.com/dlang/dmd/blob/09d04945bdbc0cba36f7bb1e19d5bd009d4b0ff2/druntime/src/core/stdc/string.d#L97

Very similar to example given on the docs:

```d
void main()
{
import std.stdio, std.algorithm;
string input = "one + two * (three - four)!";
string delimiters = "!+-(*)";

foreach(value; input.splitWhen!((a, b) => delimiters.canFind(b))) {
writeln(value);
}
}
```


Re: "string" data type with readln

2022-07-25 Thread rikki cattermole via Digitalmars-d-learn



The version of readln you are using is[0]. This works by taking in a 
buffer of memory to write out, and returns how many codepoints were stored.


Because you are not reusing memory, not using this form you can of 
course use string[1] instead, rather than ``char[]``.


```d
string s = readln();
```

The definition of string is[2]:

```d
alias string  = immutable(char)[];
```

Note the immutable there, which means that each value in the slice 
cannot be modified. Hence why it can't be used as a buffer.


[0] https://dlang.org/phobos/std_stdio.html#.readln.2
[1] https://dlang.org/phobos/std_stdio.html#.readln
[2] https://github.com/dlang/dmd/blob/master/druntime/src/object.d#L69


Re: please help me to reverse a function call order

2022-07-23 Thread rikki cattermole via Digitalmars-d-learn
A bit more d-ified and uses foreach + foreach_reverse without allocating 
an array.


```d
import std.stdio;

void main()
{
doRepetition(4, 3);
writeln("==");
doRepetitionReversed(4, 3);
}

void doRepetition(const int n, const int m)
{
// combination total number is m,  element is repeatable.
assert(n >= 1 && n < 10);
assert(m >= 1 && m < 10);
enum N = 10;
ubyte[10] a;
void inc(int index, int r, int start, int end)
{
if (index == r)
{
// get one unique combination result, not repeatable
foreach (j; 0 .. r)
{
writef!"%d "(a[j]);
}
writeln;
return;
}

foreach (i; start .. end)
{
a[index] = cast(ubyte) i;
inc(index + 1, r, i, end);
}
}

inc(0, m, 0, n);
}

void doRepetitionReversed(const int n, const int m)
{
// combination total number is m,  element is repeatable.
assert(n >= 1 && n < 10);
assert(m >= 1 && m < 10);
enum N = 10;
ubyte[10] a;
void inc(int index, int r, int start, int end)
{
if (index == r)
{
// get one unique combination result, not repeatable
foreach_reverse (j; 0 .. r)
{
writef!"%d "(a[j]);
}
writeln;
return;
}

foreach_reverse (i; start .. end)
{
a[index] = cast(ubyte) i;
inc(index + 1, r, i, end);
}
}

inc(0, m, 0, n);
}
```

Output:

```
0 0 0
0 0 1
0 0 2
0 0 3
0 1 1
0 1 2
0 1 3
0 2 2
0 2 3
0 3 3
1 1 1
1 1 2
1 1 3
1 2 2
1 2 3
1 3 3
2 2 2
2 2 3
2 3 3
3 3 3
==
3 3 3
3 3 2
3 2 2
2 2 2
3 3 1
3 2 1
2 2 1
3 1 1
2 1 1
1 1 1
3 3 0
3 2 0
2 2 0
3 1 0
2 1 0
1 1 0
3 0 0
2 0 0
1 0 0
0 0 0
```


Re: Window created with Windows API is not visible

2022-06-18 Thread rikki cattermole via Digitalmars-d-learn



A white content area, means that you didn't draw something.

As long as the border ext. is showing up, you're ok.


Re: Window created with Windows API is not visible

2022-06-18 Thread rikki cattermole via Digitalmars-d-learn

registeredClass.style = 32_769;

Don't use an integer like that, stick with bit wise ors.



LPCWSTR classname = toUTF16z(name);

GC owned memory, that could result in surprises.



const LPWSTR windowname = toUTF16z(title);

Ditto



I'm not sure your window callback procedure is right.

For instance you are not calling DefWindowProc, and you are not handling 
WM_PAINT in any form.




But one other thing, your approach to the event loop is going to come 
back to bite you at some point. Windows is based around a push event 
loop model, not a pull like other system Windowing libraries (such as 
X11). It can get recursive. I learned this one the hard way.


Re: How to call a GDI+ function from D ?

2022-06-05 Thread rikki cattermole via Digitalmars-d-learn

Bitmap is a class, not a namespace.

The function you want is actually a constructor.

https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/include/gdiplus/gdiplusheaders.h#L179


Re: What are (were) the most difficult parts of D?

2022-05-22 Thread rikki cattermole via Digitalmars-d-learn



On 23/05/2022 8:22 AM, Chris Piker wrote:
Hey thanks!  I bet LDC is pretty cool, have to look into it sometime.  
For now at my site just introducing D is a bit radical, don't want to 
capsize the boat by leaving the gcc toolchain altogether.  I'm willing 
to help out with GDC work were I can, at least by being a bleeding-edge 
tester if nothing else.


Iain is usually pretty talkative, but right now he isn't.

Right now my list of things I want to talk to him at next BeerConf (the 
next will start at the end of this week roughly) that we are both at is 
LTS releases, and I'll see where he is at with testing. I know he has 
got a lot of test hardware for all the different targets.


He is in Germany, so if you are able to get on during his timezone you 
might catch him.


Re: What are (were) the most difficult parts of D?

2022-05-22 Thread rikki cattermole via Digitalmars-d-learn



On 23/05/2022 8:05 AM, Chris Piker wrote:

Vibe.d is well tested against the frontend.

Its part of dmd's test suite.

See: https://buildkite.com/dlang/dmd/builds/26775
Thanks, that's handy.  Do you know where the equivalent test suite is 
for gdc?


No idea.

I've pinged Iain, because you are certainly at that point that is well 
past my knowledge of GDC. Not something I use, as it isn't exactly easy 
to use on Windows, plus LDC has some pretty awesome features.


Re: What are (were) the most difficult parts of D?

2022-05-22 Thread rikki cattermole via Digitalmars-d-learn



On 23/05/2022 7:24 AM, Chris Piker wrote:

   2. Testing common packages against gdc


Why?


Mostly because I've put in about 15 hours effort so far trying to get a 
vibe.d based project to build using gdc, with no success. I'm about to 
give up and declare either gdc or vibe.d unsuitable for use in a large 
upcoming project.  That's too bad really because D only has any 
credibility at all in my work group due to the existence of gdc, and 
vibe.d is a nice platform to build on.


If going by your other post, there was nothing wrong with GDC.

DMD and LDC would have produced the same set of issues, because its the 
same frontend.


Vibe.d is well tested against the frontend.

Its part of dmd's test suite.

See: https://buildkite.com/dlang/dmd/builds/26775


Re: What are (were) the most difficult parts of D?

2022-05-22 Thread rikki cattermole via Digitalmars-d-learn



On 23/05/2022 6:06 AM, Chris Piker wrote:

   1. Supporting gdc development and distribution.


Iain's workload should be decreasing now that it is using the up to date 
frontend. Rather than the older C++ version with backports that he has 
been maintaining.


My understanding is that he is fine as-is, and there isn't anything 
pressing on that front he needs help with.



   2. Testing common packages against gdc


Why?

The few things specific to GDC is stuff like inline assembly or targets 
that are either unsupported or not well supported.


   3. Updating dub so that it could assist with creating deb and yum 
packages


Packaging is something dub doesn't do right now, it is something that 
would be very nice to have.



   4. Having a standard GUI library (maybe).


If you have the many tens of millions to build it, sure.

There is a big difference between acceptable as third-party and good 
enough for standard library.


Re: Install DCD language server on Raspberrry PI4 (aarch64) requires rdmd , command not found.

2022-05-21 Thread rikki cattermole via Digitalmars-d-learn



On 22/05/2022 10:44 AM, Alain De Vos wrote:

I want to install the DCD language server on Raspberry PI4.
But the dub build for DCD requires rdmd which is not available.
Can I compile rdmd from source ? Or install a binary ?
[PS: I have ldc 1:1.24.0-2 installed ]


I grabbed a copy of ldc2-1.24.0-linux-aarch64, it has rdmd.

Something is messed up with that package if it does not include it 
(assuming it hasn't be split out into a tools package).


Re: Installing DMD on linux via snap

2022-05-18 Thread rikki cattermole via Digitalmars-d-learn

Snap package source: https://github.com/dlang-snaps/dmd.snap/

Hasn't been updated in 3 years.


Re: undefined reference to `const const(char)[] object.Throwable.message()

2022-05-17 Thread rikki cattermole via Digitalmars-d-learn
As far as I know, no D compiler guarantees compatibility between objects 
built on different version of itself.


The change would have been[0].

[0] 
https://github.com/dlang/druntime/commit/c6762914682d4fa894e2b746bf4bd9ce3ec9f7cb


Re: What are (were) the most difficult parts of D?

2022-05-14 Thread rikki cattermole via Digitalmars-d-learn



On 15/05/2022 4:00 AM, eugene wrote:

The more I have studied memory allocators & management strategies


memory allocators and GC are different things
i've had at some point 'free list' based allocator
and it worked ~3 times faster than malloc/free
when used for classical linked list implementation.


GC's are deeply entwined with their memory allocators.

They have their own dedicated one tuned to their characteristics (say 
thread handling). Even if they still call out to malloc to map blocks.


Re: What are (were) the most difficult parts of D?

2022-05-14 Thread rikki cattermole via Digitalmars-d-learn



On 15/05/2022 2:51 AM, eugene wrote:

On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote:
What are you stuck at? What was the most difficult features to 
understand? etc.


Garbage collection.

I am not programming languages theorist at at, but my imression is:

* GC came from purely functional languages where everything is immutable
* GC in Haskel (for ex.) seems very natural and even absolutely necessary
* GC is some kind of fashion and languages inventors try to put it to 
everywhere (golang)


Garbage Collectors solve some really hard problems in regards to memory 
management.


Some high performance data structures require it for memory reclamation 
and there is no alternative to it.


It is a very good base line for memory management when you do not care 
about its life time.


The more I have studied memory allocators & management strategies the 
more I wish I could go back to just relying on the GC and being naive. 
They really are amazing for most programs.


And in case anyone is interested, a book recommendation:

https://www.amazon.com/Garbage-Collection-Handbook-Management-Algorithms/dp/1420082795


Re: FTP LS

2022-05-14 Thread rikki cattermole via Digitalmars-d-learn



Phobos curl wrapper may be an option:

https://dlang.org/phobos/std_net_curl.html#.FTP


Re: Help, in vibe.d, how to get configure var of mongodb in heroku?

2022-05-13 Thread rikki cattermole via Digitalmars-d-learn



On 13/05/2022 7:03 PM, MichaelBi wrote:

On Friday, 13 May 2022 at 06:43:30 UTC, rikki cattermole wrote:


On 13/05/2022 6:23 PM, MichaelBi wrote:

 render!("index.dt", showData());


There ya go, template arguments are run at compile time.


Unh, then how to dynamically generate pages by using vibe.d


Its been a while since I used vibe.d but I think just storing it in a 
variable first would be enough.


https://vibed.org/api/vibe.http.server/render


Re: Help, in vibe.d, how to get configure var of mongodb in heroku?

2022-05-13 Thread rikki cattermole via Digitalmars-d-learn



On 13/05/2022 6:23 PM, MichaelBi wrote:

     render!("index.dt", showData());


There ya go, template arguments are run at compile time.


Re: Help, in vibe.d, how to get configure var of mongodb in heroku?

2022-05-13 Thread rikki cattermole via Digitalmars-d-learn



Okay that is fine, now we need to see where showData is being called.


Re: Help, in vibe.d, how to get configure var of mongodb in heroku?

2022-05-13 Thread rikki cattermole via Digitalmars-d-learn



On 13/05/2022 5:52 PM, MichaelBi wrote:

struct Camera{
 @name("_id") BsonObjectID id; // represented as "_id" in the database
 string brand;
 string model;
}

the structure is mapping of database field structure. how to resolve?


That code isn't the cause of your issue (its fine, no CTFE needed).

We would need see more of your code surrounding:

auto uri = environment.get("MONGODB_URI");
MongoClient conn = connectMongoDB(uri);
MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku");


Re: Help, in vibe.d, how to get configure var of mongodb in heroku?

2022-05-12 Thread rikki cattermole via Digitalmars-d-learn

On 13/05/2022 5:18 PM, MichaelBi wrote:

     i have code here:
     auto uri = environment.get("MONGODB_URI");
     MongoClient conn = connectMongoDB(uri);
     MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku");

the "MONGODB_URI" showed above already put into heroku's app config as 
the 'key' and there is a paired 'value'. so the uri is to extract the 
value which is to use for app to establish mongodb connection.


and above code with error msg here: Error: `getenv` cannot be 
interpreted at compile time, because it has no available source code


That part of the code is probably fine.

Basically you have to be careful that:

auto uri = environment.get("MONGODB_URI");

Isn't being executed during compilation.

Stuff that typically cause this is anything that initializes a variable.

Globals:

shared Foo foo = Foo(...);

Class fields:

class Foo {
Bar bar = Bar(...);
}



Re: While loop on global variable optimised away?

2022-05-11 Thread rikki cattermole via Digitalmars-d-learn
Compiler optimizations should not be defined by a programming language 
specification.


This will be on LLVM.


Re: range result in Tuple! and how to convert into assocArray by sort?

2022-05-09 Thread rikki cattermole via Digitalmars-d-learn
If I am understanding the problem correctly, this is a super expensive 
method for doing something pretty simple. Even if it is a bit more code, 
this won't require memory allocation which in this case wouldn't be 
cheap (given how big DNA tends to be).


string s = "ACGTACGT";

uint[4] counts;

foreach(char c; s) {
switch(c) {
case 'A':
case 'a':
counts[0]++;
break;
case 'C':
case 'c':
counts[1]++;
break;
case 'G':
case 'g':
counts[2]++;
break;
case 'T':
case 't':
counts[3]++;
break;
default:
assert(0, "Unknown compound");
}
}

writeln(counts);


Re: CTFE and BetterC compatibility

2022-04-27 Thread rikki cattermole via Digitalmars-d-learn

This works:

```d
struct Data
{
int[] digits;
}

int parseDigit(char c) pure
{
return c - '0';
}

Data parse(string str) pure
{
Data data;

if (__ctfe) {
size_t used;
data.digits.length = str.length;

while (str.length != 0)
{
// Skip spaces
while (str[0] == ' ')
str = str[1 .. $];

// Parse single digit integer
data.digits[used++] = parseDigit(str[0]);

// Consume digit
str = str[1 .. $];
}

data.digits = data.digits[0 .. used];
}

return data;
}

enum Data parsedData = parse("5 4 2 6 9");

extern(C) int main()
{
pragma(msg, "First digit=", parsedData.digits[0]);
return 0;
}
```


Re: Library for image editing and text insertion

2022-04-26 Thread rikki cattermole via Digitalmars-d-learn



On 27/04/2022 10:05 AM, Guillaume Piolat wrote:

On Tuesday, 26 April 2022 at 21:59:39 UTC, rikki cattermole wrote:


Putting an int into a ubyte absolutely should error, that is a lossy 
conversion and should not be automatic.


It's just VRP, here it works in 2.094
https://d.godbolt.org/z/vjq7xsMdn

because the compiler wasn't complaining I wouldn't know it was reliant 
on VRP (which is certainly an issue to be fixed).


Okay further testing locally, I cannot reproduce.

Of course I still don't think that code is right and should have the casts.

Either way whatever the dmd is, it must not be as recent as thought to be.


Re: Library for image editing and text insertion

2022-04-26 Thread rikki cattermole via Digitalmars-d-learn



On 27/04/2022 9:55 AM, Guillaume Piolat wrote:

On Tuesday, 26 April 2022 at 21:44:56 UTC, rikki cattermole wrote:


On 27/04/2022 9:39 AM, Guillaume Piolat wrote:

On Tuesday, 26 April 2022 at 21:13:38 UTC, Alexander Zhirov wrote:

more build errors


If you "dub upgrade" it should work a bit better.
No success in reproducing the bug here.


It definitely on your end.

void main() {
    int scale;
    int* in_ = new int;
    ubyte b = cast(int)scale * (cast(int)*in_ >> 7);
}

onlineapp.d(5): Error: cannot implicitly convert expression `scale * 
(*in_ >> 7)` of type `int` to `ubyte`


No.
Obviously VRP works differently for me and for him, for an unknown reason.


I copied and pasted the same code that is failing from the file in 
question and put it into that test code.


Putting an int into a ubyte absolutely should error, that is a lossy 
conversion and should not be automatic.


Re: Library for image editing and text insertion

2022-04-26 Thread rikki cattermole via Digitalmars-d-learn



On 27/04/2022 9:39 AM, Guillaume Piolat wrote:

On Tuesday, 26 April 2022 at 21:13:38 UTC, Alexander Zhirov wrote:

more build errors


If you "dub upgrade" it should work a bit better.
No success in reproducing the bug here.


It definitely on your end.

void main() {
int scale;
int* in_ = new int;
ubyte b = cast(int)scale * (cast(int)*in_ >> 7);
}

onlineapp.d(5): Error: cannot implicitly convert expression `scale * 
(*in_ >> 7)` of type `int` to `ubyte`


Re: Library for image editing and text insertion

2022-04-26 Thread rikki cattermole via Digitalmars-d-learn

No args added there.

https://github.com/AuburnSounds/Dplug/blob/master/graphics/dplug/graphics/pngload.d#L1972

Yup that code certainly looks wrong.

Note the casts above it in around:
https://github.com/AuburnSounds/Dplug/blob/master/graphics/dplug/graphics/pngload.d#L1956

So yeah upstream issue.


Re: Library for image editing and text insertion

2022-04-26 Thread rikki cattermole via Digitalmars-d-learn

To get the commands dub used, use -v.

$ dub build -v


Re: unexpected noreturn behavior

2022-04-21 Thread rikki cattermole via Digitalmars-d-learn

Could we add a check for this in DScanner?

Otherwise I'm not sure how else we are going to find all of these 
instances and fix them.


Re: unexpected noreturn behavior

2022-04-21 Thread rikki cattermole via Digitalmars-d-learn
noreturn is the bottom type which can implicitly convert to any type, 
including void. A value of type noreturn will never be produced and the 
compiler can optimize such code accordingly.


https://dlang.org/spec/type.html#noreturn


Re: Create an associative array with function pointers as the value

2022-04-20 Thread rikki cattermole via Digitalmars-d-learn



On 21/04/2022 2:15 AM, rempas wrote:
Unfortunately, this will not work for me as it uses "TypeInfo" and it is 
not available with "-betterC". Thank you for trying to help regardless!


You can't use AA's in -betterC.

The implementation is not templated and is in druntime.


Re: one liner to split a string into every n chars?

2022-04-13 Thread rikki cattermole via Digitalmars-d-learn

One way you can do it:

import std.range : chunks;
import std.algorithm : map;
import std.array : array;
import std.conv : text;

string[] split = "Hello D".chunks(2).map!(v => v.text).array;
writeln(split);

foreach(val; "Hello D".chunks(2)) {
writeln(val.text);
}



Re: Why do immutable variables need reference counting?

2022-04-10 Thread rikki cattermole via Digitalmars-d-learn
Storage classes like immutable/const/shared are not tied to any memory 
management strategy. Nor does it dictate memory lifetime.


It only dictates how it can be interacted with when you have a reference 
to it.


Re: Why do immutable variables need reference counting?

2022-04-10 Thread rikki cattermole via Digitalmars-d-learn



immutable isn't tied to lifetime semantics.

It only says that this memory will never be modified by anyone during 
its lifetime.


Anyway, the real problem is with const. Both mutable and immutable 
become it automatically.


Re: Where I download Digital Mars C Preprocessor sppn.exe?

2022-04-02 Thread rikki cattermole via Digitalmars-d-learn

What on earth are you talking about.

ImportC is highly experimental and was announced far too soon.

If you look at the last release a very large number of the bug fixes 
were for ImportC specifically.


https://dlang.org/changelog/2.099.0.html#bugfix-list


Re: I like dlang but i don't like dub

2022-03-21 Thread rikki cattermole via Digitalmars-d-learn



On 21/03/2022 11:19 PM, Tobias Pankrath wrote:
This would be much easier, if there were a `dub provide` (or whatever) 
that builds all deps for a project, installs them into a given 
prefix/path and makes them usable from `dub describe` afterwards, so 
that dub describe works more or less like pkg-config afterwards.


Sounds like a great addition if somebody were to add it.


Re: freebsd dub linker error

2022-03-17 Thread rikki cattermole via Digitalmars-d-learn



On 18/03/2022 5:56 PM, rikki cattermole wrote:

Are you trying to build dub on Android?

Android support for ldc is currently broken to due to removal of a 
linker that is currently required for TLS support.


https://github.com/ldc-developers/ldc/issues/3918


My bad I didn't see FreeBSD.

Similar issue, quite possibly related given the old version 2.069.0 
being referenced.


https://github.com/ldc-developers/ldc/pull/3106


Re: freebsd dub linker error

2022-03-17 Thread rikki cattermole via Digitalmars-d-learn

Are you trying to build dub on Android?

Android support for ldc is currently broken to due to removal of a 
linker that is currently required for TLS support.


https://github.com/ldc-developers/ldc/issues/3918


Re: Make shared static this() encoding table compilable

2022-03-14 Thread rikki cattermole via Digitalmars-d-learn



The recommended solution by Unicode is to use Trie tables for Look Up 
Tables (LUTs).


https://en.wikipedia.org/wiki/Trie

You can generate these as read only global arrays and are very fast for 
this.


Re: Offline D documentation/tutorial

2022-02-12 Thread rikki cattermole via Digitalmars-d-learn

There are some files available at https://d-apt.sourceforge.io/


Re: First time using Parallel

2021-12-26 Thread rikki cattermole via Digitalmars-d-learn



On 27/12/2021 12:10 AM, max haughton wrote:
I would start by removing the use of stdout in your loop kernel - I'm 
not familiar with what you are calculating, but if you can basically 
have the (parallel) loop operate from (say) one array directly into 
another then you can get extremely good parallel scaling with almost no 
effort.


Not using in the actual loop should make the code faster even without 
threads because having a function call in the hot code will mean 
compilers optimizer will give up on certain transformations - i.e. do 
all the work as compactly as possible then output the data in one step 
at the end.


It'll speed it up significantly.

Standard IO has locks in it. So you end up with all calculations 
grinding to a half waiting for another thread to finish doing something.


Re: Double bracket "{{" for scoping static foreach is no longer part of D

2021-12-22 Thread rikki cattermole via Digitalmars-d-learn

Seems to be working just fine as of 2.098.

```d
import std;
void main()
{
static foreach(Foo; ["Abc", "def"]) {{
string str = Foo;
writeln("Hello D ", str, __VERSION__);
}}
}
```

```
Hello D Abc2098
Hello D def2098
```

Anyway, AliasAssign has nothing to do with this. This "trick" creates a 
closure aka ``() { ... }``. Thats all its doing.


From the AST dump:

```
import object;
import std;
void main()
{
{
string str = "Abc";
writeln("Hello D ", str, 2098L);
}
{
string str = "def";
writeln("Hello D ", str, 2098L);
}
return 0;
}
```


Re: How to pass a class by (const) reference to C++

2021-12-15 Thread rikki cattermole via Digitalmars-d-learn



On 15/12/2021 11:54 PM, Jan wrote:

On Wednesday, 15 December 2021 at 09:36:54 UTC, Jan wrote:
Unfortunately it's the "annoying little details" that I immediately 
bumped into.


Just another example: I just learned that linking against C++ DLLs is 
quite limited. I ran into the issue that linking in an external variable 
doesn't work (even though the mangled name that D chooses is correct), 
because DLLs work differently than static linking does.
Someone with more in-depth knowledge told me, that Windows support in D 
and specifically DLL support is lacking quite a bit.


Having *only* link compatibility is totally fine, D currently just 
doesn't fulfill that promise, especially not on Windows and especially 
not with DLLs.


Are you sure that on the shared library side it was marked as exported?

If a symbol is not exported, there is no guarantee (nor reason to think) 
that it will be visible during runtime linking to said shared 
library/executable.


This isn't unique to D, its just how linkers work.


Re: d strings are the bane of my existance

2021-12-05 Thread rikki cattermole via Digitalmars-d-learn

The string is not the problem.

```d
string ip_address = "192.168.1.1";
auto x = new InternetAddress(ip_address, 8008);
```

That works.

A string in D is an alias for immutable(char)[]. This is defined in 
druntime (object.d).


Immutable does cast to const implicitly, so a string argument to the 
constructor works fine as it has the same meaning.


The port however, that needs to be a ubyte/ushort to pass in and not be 
a string like you had it.


Re: Dub says that there is an invalid semVer format, but I don't see how.

2021-11-19 Thread rikki cattermole via Digitalmars-d-learn



Don't use ~> for branches.

alpha@DESKTOP-RB97SA4 /tmp/dutils
$ dub build
Invalid SemVer format: stable.0.0

alpha@DESKTOP-RB97SA4 /tmp/dutils
$ nano dub.json

alpha@DESKTOP-RB97SA4 /tmp/dutils 

$ dub build 

Performing "debug" build using 
C:\Tools\D\dmd_2.097.2\windows\bin\dmd.exe for x86_64. 

dutils 0.1.2-beta.2+commit.9.g359c59d: building configuration 
"library"... 

Error: module `package` is in file 'package.d' which cannot be read 

import path[0] = source 

import path[1] = C:\Tools\D\dmd_2.097.2\windows\bin\..\..\src\phobos 

import path[2] = 
C:\Tools\D\dmd_2.097.2\windows\bin\..\..\src\druntime\import 

C:\Tools\D\dmd_2.097.2\windows\bin\dmd.exe failed with exit code 1. 




alpha@DESKTOP-RB97SA4 /tmp/dutils 

$ cat dub.json 

{ 

"authors": [ 

"Ruby The Roobster" 

], 

"copyright": "Copyright © 2021, Ruby The Roobster", 

"description": "A collection of modules in the D Programming 
Language that people may find useful.", 

"license": "GLP-3.0", 

"name": "dutils", 

"importPaths": ["./source"], 

"sourceFiles": ["package.d"], 

"targetType": "library", 

"subPackages": [ 

{ 

"name": "sprite", 

"description": ".spr file format for images 
because I'm to lazy to use a preexisting one for sprites.", 

"targetType": "library", 

"importPaths": ["./source"], 

"sourceFiles": ["sprite.d"], 

"dependencies": { 

"dutils:skeleton": "~stable" 

} 

}, 

{ 

"name": "binom", 

"description": "Module for doing some bionomial 
work in the D Programming Language(why did I make this).",
"targetType": "library", 

"importPaths": ["./source"], 

"sourceFiles": ["binom.d"] 

}, 

{ 

"name": "skeleton", 

"description": "Module for implementing 
skeletons, e.g. a cube with criss-crossing beams to better detect 
collision.",
"targetType": "library", 

"importPaths": ["./source"], 

"sourceFiles": ["skeleton.d"] 

}, 

{ 

"name": "physics", 

"description": "A very simple and basic physics 
library.",
"targetType": "library", 

"importPaths": ["./source"], 

"sourceFiles": ["physics.d"], 

"dependencies": { 

"dutils:skeleton": "~stable" 

} 

} 

] 

} 



Re: Dub says that there is an invalid semVer format, but I don't see how.

2021-11-10 Thread rikki cattermole via Digitalmars-d-learn



On 11/11/2021 2:13 PM, Ruby The Roobster wrote:

Branch ~master: Invalid SemVer format: testing.0.0
Branch ~testing: Invalid SemVer format: testing.0.0
Version 0.1.2: Invalid SemVer format: testing.0.0


testing is a branch.

You are using ~>testing for it.

To use a branch in the SEMVER is ~branch.

https://dub.pm/package-format-json.html#version-specs


Re: Crosscompile to Windows

2021-11-08 Thread rikki cattermole via Digitalmars-d-learn



On 09/11/2021 12:44 PM, Luis wrote:
It should work with the last version of DMD : 
https://dlang.org/changelog/2.098.0.html#target


It won't.

https://github.com/dlang/dub/blob/master/source/dub/compilers/dmd.d#L111


Re: Crosscompile to Windows

2021-11-07 Thread rikki cattermole via Digitalmars-d-learn



On 08/11/2021 11:34 AM, Imperatorn wrote:

On Sunday, 7 November 2021 at 22:19:08 UTC, russhy wrote:

If i remember correctly, all you have to do is:

    dub build --arch=x86_64-pc-windows-msvc --compiler=ldc2


Is this information on dub.pm? If not, we should add it. 


This is compiler specific.

The arch triple is only supported for ldc. If you tried that with gdc it 
would error out.


  1   2   3   4   5   6   7   8   9   10   >