Re: needing to change the order of things at module level = compiler bug, right?
On Sunday, 8 December 2019 at 18:13:59 UTC, DanielG wrote: On Sunday, 8 December 2019 at 18:01:03 UTC, Steven Schveighoffer wrote: Yes, if it can compile when you move things around, and the result is *correct* (very important characteristic) Indeed, everything's working as intended when rearranged. Thanks! Still worth opening an issue. https://issues.dlang.org/show_bug.cgi?id=20443
Re: Using map result type
On Wednesday, 11 December 2019 at 20:08:37 UTC, Meta wrote: import std.algorithm; import std.range; void mapAccepter(E)(InputRange!E r) { import std.array: array; import std.stdio: writeln; auto collected = r.array; writeln(collected); } void main() { int[] nums = [1, 2, 3]; auto evenness = inputRangeObject(map!(n => n % 2 == 0)(nums)); mapAccepter(evenness); } I guess I should mention, that if you are expecting a range of booleans, you can of course write mapAccepter as a non-templated function: void mapAccepter(InputRange!bool r); But if you want to support any type of input range, the function needs to at least be templated on the element type of the range.
Re: Using map result type
On Sunday, 8 December 2019 at 01:10:21 UTC, AA wrote: I'd like to accept the return type of map. From some previous questions that I should accept a template? So for something like: ``` void mapAccepter(Range)(Range r) { import std.array : array; import std.stdio : writeln; auto collected = r.array; writeln(collected); } void main() { import std.algorithm.iteration : map; int[] nums = [1, 2, 3]; auto evenness = map!(n => n % 2 == 0)(nums); mapAccepter(evenness); } ``` 1) Is there any way I can make `mapAccepter` not a templated function? Yes (mostly, anyway), using the interfaces in std.range.interfaces: https://dlang.org/phobos/std_range_interfaces.html import std.algorithm; import std.range; void mapAccepter(E)(InputRange!E r) { import std.array: array; import std.stdio: writeln; auto collected = r.array; writeln(collected); } void main() { int[] nums = [1, 2, 3]; auto evenness = inputRangeObject(map!(n => n % 2 == 0)(nums)); mapAccepter(evenness); } `mapAccepter` still needs to be templated on the element type of the range, but there are ways to avoid that as well, if desired. I wouldn't recommend it, however, as it wouldn't be that useful in this case. 2) Is there any way if I need to make `mapAccepter` templated to constrain Range to be a range of booleans. Yup, there are two ways that you you primarily do that. Either constraining E in the template declaration, or adding a constraint on the template. Generally option 2 is the more idiomatic D way. Option 1: constrain E to be of type bool: void mapAccepter(E: bool)(InputRange!E r); OR void mapAccepter(E)(InputRange!E r) if (is(E == bool)); There's not much difference between these two, but the latter is probably preferred. Option 2: use std.traits and a template constraint: void mapAccepter(E)(InputRange!E r) if (is(ElementType!r == bool));
d programs conversion to c
Greetings! I am trying to see if there are any converters out there from d code to c. Anyone knows? Thanks. josé
Re: How to organize a project with local scripts in subdirectories using dub?
On Wednesday, 11 December 2019 at 16:06:30 UTC, drug wrote: Add to dub.json: "targetType": "executable" and it will build executable. Or rename evaluator.d to app.d It is confused that there is no app.d so it thinks that you build a library. I added "targetType" and now everything works without renaming to the script to "app.d". Thank you!
Re: How to organize a project with local scripts in subdirectories using dub?
On 12/11/19 6:52 PM, Pavel Shkadzko wrote: It works like this, yes. However, by default it builds a "library" while I want to run "evaluator" as a script which uses other scripts by calling their functions. Doing: dub --compiler=ldc2 --single evaluator.d // throws an error source\evaluator.d(93,12): Error: module runme_1 is in file 'runme_1.d' which cannot be read Add to dub.json: "targetType": "executable" and it will build executable. Or rename evaluator.d to app.d It is confused that there is no app.d so it thinks that you build a library.
Re: How to organize a project with local scripts in subdirectories using dub?
On Wednesday, 11 December 2019 at 13:00:32 UTC, drug wrote: I would restructure your folders this way: my_proj/ source/ script_1/runme_1.d script_2/runme_2.d evaluator.d then using `dub --compiler=ldc2` It works like this, yes. However, by default it builds a "library" while I want to run "evaluator" as a script which uses other scripts by calling their functions. Doing: dub --compiler=ldc2 --single evaluator.d // throws an error source\evaluator.d(93,12): Error: module runme_1 is in file 'runme_1.d' which cannot be read
Re: How to organize a project with local scripts in subdirectories using dub?
On 12/11/19 2:18 PM, Pavel Shkadzko wrote: I have the following project structure. my_proj/ script_1/runme_1.d script_2/runme_2.d evaluator.d The project has a library dependency: "dependencies": { "mir": "~>3.2.0", }, The "evaluator.d" script contains some general functions that convert dataset and pass it to "runme_1.d" and "runme_2.d" scripts the following way: import mir.ndslice; void main() { import script_1.runme_1 : runTask1; import script_2.runme_2 : runTask2; mir_slice!(real*, 1LU, cast(mir_slice_kind)2)[]) dataset = convertDataset("data.txt"); runTask1(dataset); //runTask2(dataset); //disable for now } So, basically what I need is to be able to run "./evaluator" and get the results by running the corresponding scripts. I am trying to build the project the following way: dub build --compiler=ldc2 --single evaluator.d I get the following error: Performing "debug" build using ldc2 for x86_64. mir-core 1.0.2: target for configuration "library" is up to date. mir-algorithm 3.7.2: target for configuration "default" is up to date. mir-linux-kernel 1.0.1: target for configuration "library" is up to date. mir-random 2.2.8: target for configuration "extended" is up to date. survey ~master: building configuration "application"... lld-link: error: undefined symbol: _D5runme_114runTask1FS3mir7ndslice5slice__T9mir_sliceTPeVmi2VEQBoQBnQBi14mir_slice_kindi2ZQBvZv referenced by C:\Users\user\my_proj\evaluator.d:89 .dub\obj\evaluator.obj:(_Dmain) Error: linking with LLD failed ldc2 failed with exit code 1. How should I organize my project for this kind of setup? (I am sorry for the absence of code formatting. I could not find any quick howto here) I would restructure your folders this way: my_proj/ source/ script_1/runme_1.d script_2/runme_2.d evaluator.d then using `dub --compiler=ldc2`
How to organize a project with local scripts in subdirectories using dub?
I have the following project structure. my_proj/ script_1/runme_1.d script_2/runme_2.d evaluator.d The project has a library dependency: "dependencies": { "mir": "~>3.2.0", }, The "evaluator.d" script contains some general functions that convert dataset and pass it to "runme_1.d" and "runme_2.d" scripts the following way: import mir.ndslice; void main() { import script_1.runme_1 : runTask1; import script_2.runme_2 : runTask2; mir_slice!(real*, 1LU, cast(mir_slice_kind)2)[]) dataset = convertDataset("data.txt"); runTask1(dataset); //runTask2(dataset); //disable for now } So, basically what I need is to be able to run "./evaluator" and get the results by running the corresponding scripts. I am trying to build the project the following way: dub build --compiler=ldc2 --single evaluator.d I get the following error: Performing "debug" build using ldc2 for x86_64. mir-core 1.0.2: target for configuration "library" is up to date. mir-algorithm 3.7.2: target for configuration "default" is up to date. mir-linux-kernel 1.0.1: target for configuration "library" is up to date. mir-random 2.2.8: target for configuration "extended" is up to date. survey ~master: building configuration "application"... lld-link: error: undefined symbol: _D5runme_114runTask1FS3mir7ndslice5slice__T9mir_sliceTPeVmi2VEQBoQBnQBi14mir_slice_kindi2ZQBvZv referenced by C:\Users\user\my_proj\evaluator.d:89 .dub\obj\evaluator.obj:(_Dmain) Error: linking with LLD failed ldc2 failed with exit code 1. How should I organize my project for this kind of setup? (I am sorry for the absence of code formatting. I could not find any quick howto here)