Re: dynamic linker flags with dub

2024-04-29 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 30/04/2024 10:20 AM, KytoDragon wrote: I want to use dll-style hot-reloading for a windows application which requires a different name for the PDB file for each compilation. (windows locks the pdb file when loading the dll and the compiler can't create a new pdb with the same name). How can

Re: Challenge Tuples

2024-04-27 Thread Julian Fondren via Digitalmars-d-learn
On Friday, 26 April 2024 at 13:25:34 UTC, Salih Dincer wrote: You have a 5-item data tuples as Tuple(1, 2, 3, [1, 3], 5) and implement the sum (total = 15) with the least codes using the sum() function of the language you are coding... Nim: ```nim import std/[math, typetraits, macros] macro

Re: Challenge Tuples

2024-04-27 Thread Sergey via Digitalmars-d-learn
On Friday, 26 April 2024 at 13:25:34 UTC, Salih Dincer wrote: You have a 5-item data tuples as Tuple(1, 2, 3, [1, 3], 5) and implement the sum (total = 15) with the least codes using the sum() function of the language you are coding... Let's start with D: ```d import std.typecons : tuple;

Re: Challenge Tuples

2024-04-27 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 27 April 2024 at 15:36:40 UTC, Nick Treleaven wrote: On Saturday, 27 April 2024 at 15:32:40 UTC, Nick Treleaven wrote: On Saturday, 27 April 2024 at 11:55:58 UTC, Basile B. wrote: foreach const e in u do if echo(is, e, T) do result += e;

Re: Challenge Tuples

2024-04-27 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 27 April 2024 at 15:32:40 UTC, Nick Treleaven wrote: On Saturday, 27 April 2024 at 11:55:58 UTC, Basile B. wrote: foreach const e in u do if echo(is, e, T) do result += e; static if (is(typeof(e) == int)) r += e; Actually

Re: Challenge Tuples

2024-04-27 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 27 April 2024 at 11:55:58 UTC, Basile B. wrote: Here's [STYX](https://gitlab.com/styx-lang/styx) solution: function sum[T,U](U u): u32 I think you meant `: T`. { var T result; foreach const e in u do if echo(is, e, T) do

Re: Challenge Tuples

2024-04-27 Thread Basile B. via Digitalmars-d-learn
On Friday, 26 April 2024 at 13:25:34 UTC, Salih Dincer wrote: You have a 5-item data tuples as Tuple(1, 2, 3, [1, 3], 5) and implement the sum (total = 15) with the least codes using the sum() function of the language you are coding... Let's start with D: Here's

Re: Challenge Tuples

2024-04-26 Thread Andy Valencia via Digitalmars-d-learn
On Friday, 26 April 2024 at 13:25:34 UTC, Salih Dincer wrote: You have a 5-item data tuples as Tuple(1, 2, 3, [1, 3], 5) and implement the sum (total = 15) with the least codes using the sum() function of the language you are coding... My Python solution (function named dosum to avoid

Re: Challenge Tuples

2024-04-26 Thread matheus via Digitalmars-d-learn
On Friday, 26 April 2024 at 13:25:34 UTC, Salih Dincer wrote: ... Very nice, for your first example I need to think a bit because I'm bit rusty in C#, but I think it will not be as easier as D version. For the bonus part: private static void Main(string[] args){ var a =

Challenge Tuples

2024-04-26 Thread Salih Dincer via Digitalmars-d-learn
You have a 5-item data tuples as Tuple(1, 2, 3, [1, 3], 5) and implement the sum (total = 15) with the least codes using the sum() function of the language you are coding... Let's start with D: ```d import std.typecons : tuple; import std.algorithm : sum; void main() { auto t = tuple(1,

Re: Recommendations on porting Python to D

2024-04-25 Thread max haughton via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 19:50:45 UTC, Chris Piker wrote: Hi D I have a somewhat extensive CGI based web service written in Python and I'd like to port it to D. I can do this manually of course, and maybe that's the best way, but for a rough start, is anyone aware of any tools that

Re: Recommendations on porting Python to D

2024-04-25 Thread mw via Digitalmars-d-learn
BTW, maybe you can also try Mojo: https://github.com/modularml/mojo

Re: Recommendations on porting Python to D

2024-04-25 Thread mw via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 22:07:41 UTC, Chris Piker wrote: Python-AST to D source converter may already exist? https://github.com/joortcom/eiffel_rename/tree/main/yi A rudimentary converter from (extended) Python to D. Maybe you can use it as a starting point. It uses: PEG parser

Re: Recommendations on porting Python to D

2024-04-25 Thread Chris Piker via Digitalmars-d-learn
On Thursday, 25 April 2024 at 07:04:13 UTC, Sergey wrote: On Wednesday, 24 April 2024 at 22:07:41 UTC, Chris Piker wrote: Python-AST to D source converter may already exist? Another possible way maybe is using C :) Python -> C -> D https://wiki.python.org/moin/PythonImplementations#Compilers

Re: How to make project with main application and cli application in the same folder?

2024-04-25 Thread alex via Digitalmars-d-learn
On Sunday, 21 April 2024 at 16:41:08 UTC, Mike Parker wrote: On Sunday, 21 April 2024 at 08:44:38 UTC, alex wrote: Hi guys. Trying to play with vibe-d and want to create separate web app, and cli app which can add admin users. When I just keep both files app.d and cli.d in source folder, I get

Re: Recommendations on porting Python to D

2024-04-25 Thread Sergey via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 22:07:41 UTC, Chris Piker wrote: Python-AST to D source converter may already exist? Another possible way maybe is using C :) Python -> C -> D https://wiki.python.org/moin/PythonImplementations#Compilers

Re: Adapting foreign iterators to D ranges

2024-04-24 Thread cc via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 05:08:25 UTC, Salih Dincer wrote: Yes, `opApply()` works! You just need to use `do while()` instead of `while()` because it skips the first item. It depends on the type of structure being consumed, if it provides "next" as a direct pointer then yeah you would

Re: Recommendations on porting Python to D

2024-04-24 Thread Chris Piker via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 20:13:26 UTC, Lance Bachmeier wrote: I haven't used Python much in recent years, but my recollection is that Python 2 had an ast module that would spit out the ast for you. Thanks for the pointer! So I ran one of my modules through and generated an AST, and get

Re: Recommendations on porting Python to D

2024-04-24 Thread Sergey via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 19:50:45 UTC, Chris Piker wrote: Hi D I have a somewhat extensive CGI based web service written in There is also https://code.dlang.org/packages/arsd-official%3Acgi

Re: Recommendations on porting Python to D

2024-04-24 Thread Lance Bachmeier via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 19:50:45 UTC, Chris Piker wrote: is anyone aware of any tools that generate an abstract syntax tree which could then be converted to somewhat equivalent D code? This might give me a jump-start on the manual conversion process. Then later I can work on removing

Re: Recommendations on porting Python to D

2024-04-24 Thread Tim via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 19:50:45 UTC, Chris Piker wrote: I have a somewhat extensive CGI based web service written in Python and I'd like to port it to D. I can do this manually of course, and maybe that's the best way, but for a rough start, is anyone aware of any tools that generate

Recommendations on porting Python to D

2024-04-24 Thread Chris Piker via Digitalmars-d-learn
Hi D I have a somewhat extensive CGI based web service written in Python and I'd like to port it to D. I can do this manually of course, and maybe that's the best way, but for a rough start, is anyone aware of any tools that generate an abstract syntax tree which could then be converted to

Re: Print debug data

2024-04-24 Thread mw via Digitalmars-d-learn
On Monday, 17 July 2023 at 03:43:04 UTC, Alain De Vos wrote: Is it possible to print runtime memory usage of: -The stack -The heap -The garbage collector ? And how to print the memory stats of each class / struct type? 

Re: Range handling difficulties

2024-04-24 Thread Menjanahary R. R. via Digitalmars-d-learn
On Wednesday, 24 April 2024 at 14:22:10 UTC, H. S. Teoh wrote: On Wed, Apr 24, 2024 at 08:08:06AM +, Menjanahary R. R. via Digitalmars-d-learn wrote: [...] evenfib.until!(n => n > 4_000_000).sum.writeln; T Thanks a lot! You've made my day 

Re: Range handling difficulties

2024-04-24 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 24, 2024 at 08:08:06AM +, Menjanahary R. R. via Digitalmars-d-learn wrote: > I tried to solve Project Euler [problem > #2](https://projecteuler.net/problem=2) using > [Recurrence/recurrence](https://dlang.org/library/std/range/recurrence.html). > > Assuming `g

Re: mmap file performance

2024-04-24 Thread Patrick Schluter via Digitalmars-d-learn
On Monday, 15 April 2024 at 16:13:41 UTC, Andy Valencia wrote: On Monday, 15 April 2024 at 08:05:25 UTC, Patrick Schluter wrote: The setup of a memory mapped file is relatively costly. For smaller files it is a net loss and read/write beats it hands down. Interestingly, this performance

Range handling difficulties

2024-04-24 Thread Menjanahary R. R. via Digitalmars-d-learn
I tried to solve Project Euler [problem #2](https://projecteuler.net/problem=2) using [Recurrence/recurrence](https://dlang.org/library/std/range/recurrence.html). Assuming `genEvenFibonacci` is the appropriate funtion in Explicit form, I got what I need like so: ``` auto evenfib =

Re: Adapting foreign iterators to D ranges

2024-04-23 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 23 April 2024 at 06:02:18 UTC, cc wrote: Just to offer an alternative solution (since it sometimes gets overlooked), there is also the `opApply` approach. You don't get full forward range status, and checking whether it's empty essentially requires doing something like

Re: Adapting foreign iterators to D ranges

2024-04-23 Thread cc via Digitalmars-d-learn
On Monday, 22 April 2024 at 11:36:43 UTC, Chloé wrote: I wish to adapt this interface to a forward range for use with foreach and Phobos' range utilities. This amounts to implementing empty, front, and popFront, in terms of next and some state. But there is a choice to be made regarding the

Re: Adapting foreign iterators to D ranges

2024-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 22 April 2024 at 11:36:43 UTC, Chloé wrote: The first implementation has the advantage is being simpler and empty being const, but has the downside that next is called even if the range ends up not being used. Is either approach used consistently across the D ecosystem? I always

Re: Adapting foreign iterators to D ranges

2024-04-22 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Monday, 22 April 2024 at 11:36:43 UTC, Chloé wrote: The first implementation has the advantage is being simpler and empty being const, but has the downside that next is called even if the range ends up not being used. Is either approach used consistently across the D ecosystem? You can

Adapting foreign iterators to D ranges

2024-04-22 Thread Chloé via Digitalmars-d-learn
Assume a third-party API of the following signature: T* next(I iter); which advances an iterator of sorts and returns the next element, or null when iteration is done. No other information about the state of the iterator is available. I wish to adapt this interface to a forward range

Re: How to make project with main application and cli application in the same folder?

2024-04-21 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 21 April 2024 at 08:44:38 UTC, alex wrote: Hi guys. Trying to play with vibe-d and want to create separate web app, and cli app which can add admin users. When I just keep both files app.d and cli.d in source folder, I get an error that I can't have more then 1 main function.

Re: Find homography in D?

2024-04-21 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Sunday, 21 April 2024 at 14:57:33 UTC, Paolo Invernizzi wrote: Hi, Someone can point me to a D implementation of the classical OpenCV find homography matrix? Thank you, Paolo Kinda some work but it should be doable using DCV and mir.lubeck in theory DCV can compute, not sift or surf

Re: How to make project with main application and cli application in the same folder?

2024-04-21 Thread Monkyyy via Digitalmars-d-learn
On Sunday, 21 April 2024 at 08:44:38 UTC, alex wrote: Hi guys. Trying to play with vibe-d and want to create separate web app, and cli app which can add admin users. When I just keep both files app.d and cli.d in source folder, I get an error that I can't have more then 1 main function.

How to make project with main application and cli application in the same folder?

2024-04-21 Thread alex via Digitalmars-d-learn
Hi guys. Trying to play with vibe-d and want to create separate web app, and cli app which can add admin users. When I just keep both files app.d and cli.d in source folder, I get an error that I can't have more then 1 main function. I already asked chatGPT, and it replied that I need to use

Re: Doing a `static foreach` or `foreach` through enum members in a template or CTFE function, while disabling deprecation warnings

2024-04-19 Thread Liam McGillivray via Digitalmars-d-learn
On Friday, 19 April 2024 at 22:24:17 UTC, Liam McGillivray wrote: ``` template enumMixin(alias Enum) { static foreach(m; __traits(allMembers, Enum)) static if (!__traits(isDeprecated, __traits(getMember, Enum, m))) { mixin("alias "~m~" = __traits(getMember, Enum, m);"); }

Re: Doing a `static foreach` or `foreach` through enum members in a template or CTFE function, while disabling deprecation warnings

2024-04-19 Thread Liam McGillivray via Digitalmars-d-learn
Well, someone on the Discord server has been helping me attempt this, but while I managed to get a solution that compiles without errors, I still get the deprecation warning. Here is what I ended up with: ``` template enumMixin(alias Enum) { static foreach(m; __traits(allMembers, Enum))

Doing a `static foreach` or `foreach` through enum members in a template or CTFE function, while disabling deprecation warnings

2024-04-19 Thread Liam McGillivray via Digitalmars-d-learn
I know that DStep generates CTFE functions to automatically make aliases for enum members so that the can be used without the enum name, as is done in C. DStep does it with a CTFE function, though it should also be possible with a mixin template. Here is my attempt so far, using a mixin

Re: Digger on Windows -- should it work?

2024-04-19 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 20/04/2024 9:28 AM, Ivan Kazmenko wrote: Hi. I'd like to test locally whether a commit (https://github.com/dlang/dmd/pull/16400) fixes an issue (https://issues.dlang.org/show_bug.cgi?id=24440).  The GitHub instructions in the PR tell to use Digger for a quick and easy check, but it fails

Re: Statically compiled binary with C interop crashes.

2024-04-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 18 April 2024 at 11:05:07 UTC, yabobay wrote: On Wednesday, 17 April 2024 at 15:24:07 UTC, Ferhat Kurtulmuş wrote: On Wednesday, 17 April 2024 at 11:03:22 UTC, yabobay wrote: I'm using [dray](https://code.dlang.org/packages/dray) in my project with dub, here's the relevant parts

Re: Statically compiled binary with C interop crashes.

2024-04-18 Thread yabobay via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 15:24:07 UTC, Ferhat Kurtulmuş wrote: On Wednesday, 17 April 2024 at 11:03:22 UTC, yabobay wrote: I'm using [dray](https://code.dlang.org/packages/dray) in my project with dub, here's the relevant parts of the dub.json: [...] İt seems your issue is related to

Re: mmap file performance

2024-04-17 Thread kdevel via Digitalmars-d-learn
On Thursday, 11 April 2024 at 16:23:44 UTC, Andy Valencia wrote: [...] void main(in string[] argv) ^^ What if you want to use bool memorymapped; getopt (argv, "m", ); inside main? [1] Have you tried using "rm" [2] instead of "r" as stdioOpenmode under Linux for a "no code"

Re: Making one struct work in place of another for function calls.

2024-04-17 Thread cc via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 03:13:46 UTC, Liam McGillivray wrote: On Wednesday, 17 April 2024 at 02:39:25 UTC, Paul Backus wrote: This is called [row polymorphism][1], and it does not exist in D. You could approximate it by making `someFunction` a template, and accepting any type `T` that

Re: Statically compiled binary with C interop crashes.

2024-04-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 11:03:22 UTC, yabobay wrote: I'm using [dray](https://code.dlang.org/packages/dray) in my project with dub, here's the relevant parts of the dub.json: [...] İt seems your issue is related to the raylib itself, neither the binding you use nor the d programming

Statically compiled binary with C interop crashes.

2024-04-17 Thread yabobay via Digitalmars-d-learn
I'm using [dray](https://code.dlang.org/packages/dray) in my project with dub, here's the relevant parts of the dub.json: ```json "dependencies" : {"dray": "~>4.2.0-r3"}, "dflags-ldc": ["--static"], "lflags": ["-static"] ``` In my regular setup with Debian, i can compile and run my

Re: How to set include paths of a c source in dub when using importc

2024-04-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 00:40:28 UTC, Alex Bryan wrote: If you're not using gdc exclusively, you'll want to take a look at this: https://github.com/dlang/dub/pull/2818 I knew there was something wrong there.

Re: Making one struct work in place of another for function calls.

2024-04-16 Thread Andy Valencia via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 03:13:46 UTC, Liam McGillivray wrote: Is there a way I can replace "`TypeB`" in the function parameters with another symbol, and then define that symbol to accept `TypeB` as an argument, but also accept `TypeA` which would get converted to `TypeB` using a

Re: Making one struct work in place of another for function calls.

2024-04-16 Thread Liam McGillivray via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 02:39:25 UTC, Paul Backus wrote: This is called [row polymorphism][1], and it does not exist in D. You could approximate it by making `someFunction` a template, and accepting any type `T` that has the necessary members instead of only accepting `typeB`. But

Re: Making one struct work in place of another for function calls.

2024-04-16 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 01:36:59 UTC, Liam McGillivray wrote: To better understand what I mean, take the following example, where I have a function, and two structs. ``` struct typeA { // Some member variables here } struct typeB { // Some similar member variables here, but in a

Making one struct work in place of another for function calls.

2024-04-16 Thread Liam McGillivray via Digitalmars-d-learn
I have two structs that serve roughly the same purpose, and I would like one to be accepted when the other is declared as a function parameter. To better understand what I mean, take the following example, where I have a function, and two structs. ``` struct typeA { // Some member

Re: How to set include paths of a c source in dub when using importc

2024-04-16 Thread Alex Bryan via Digitalmars-d-learn
If you're not using gdc exclusively, you'll want to take a look at this: https://github.com/dlang/dub/pull/2818

Re: mmap file performance

2024-04-15 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 15 April 2024 at 08:05:25 UTC, Patrick Schluter wrote: The setup of a memory mapped file is relatively costly. For smaller files it is a net loss and read/write beats it hands down. Interestingly, this performance deficit is present even when run against the largest conveniently

Re: mmap file performance

2024-04-15 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 11 April 2024 at 00:24:44 UTC, Andy Valencia wrote: I wrote a "count newlines" based on mapped files. It used about twice the CPU of the version which just read 1 meg at a time. I thought something was amiss (needless slice indirection or something), so I wrote the code in C.

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-14 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 15/04/2024 10:36 AM, Liam McGillivray wrote: Well, it did work when I tried it (using a string variable, not a literal of course). It displayed as it is supposed to. But from the information I can find on the web it looks like strings are sometimes but not |always| zero-terminated. Not a

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 14 April 2024 at 22:36:18 UTC, Liam McGillivray wrote: On Friday, 12 April 2024 at 15:24:38 UTC, Steven Schveighoffer wrote: ```d void InitWindow(int width, int height, ref string title) { InitWindow(width, height, cast(const(char)*)title); } ``` This is invalid, a string may

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-14 Thread Liam McGillivray via Digitalmars-d-learn
On Friday, 12 April 2024 at 15:24:38 UTC, Steven Schveighoffer wrote: ```d void InitWindow(int width, int height, ref string title) { InitWindow(width, height, cast(const(char)*)title); } ``` This is invalid, a string may not be zero-terminated. You can't just cast. Well, it did work

Re: How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 13 April 2024 at 22:00:16 UTC, Ferhat Kurtulmuş wrote: On Saturday, 13 April 2024 at 21:41:41 UTC, Ferhat Kurtulmuş wrote: On Saturday, 13 April 2024 at 21:39:10 UTC, Ferhat Kurtulmuş wrote: On Saturday, 13 April 2024 at 21:21:24 UTC, Richard (Rikki) Andrew Cattermole wrote:

Re: How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 13 April 2024 at 21:41:41 UTC, Ferhat Kurtulmuş wrote: On Saturday, 13 April 2024 at 21:39:10 UTC, Ferhat Kurtulmuş wrote: On Saturday, 13 April 2024 at 21:21:24 UTC, Richard (Rikki) Andrew Cattermole wrote: On 14/04/2024 8:59 AM, Ferhat Kurtulmuş wrote: These don't work for me:

Re: How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 13 April 2024 at 21:39:10 UTC, Ferhat Kurtulmuş wrote: On Saturday, 13 April 2024 at 21:21:24 UTC, Richard (Rikki) Andrew Cattermole wrote: On 14/04/2024 8:59 AM, Ferhat Kurtulmuş wrote: These don't work for me: "dflags": ["-Iinclude"] "importPaths": [     "include" ], The

Re: How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 13 April 2024 at 21:21:24 UTC, Richard (Rikki) Andrew Cattermole wrote: On 14/04/2024 8:59 AM, Ferhat Kurtulmuş wrote: These don't work for me: "dflags": ["-Iinclude"] "importPaths": [     "include" ], The importc docs do not help either. Appears it hasn't been documented in

Re: How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 13 April 2024 at 21:21:24 UTC, Richard (Rikki) Andrew Cattermole wrote: On 14/04/2024 8:59 AM, Ferhat Kurtulmuş wrote: These don't work for me: "dflags": ["-Iinclude"] "importPaths": [     "include" ], The importc docs do not help either. Appears it hasn't been documented in

Re: How to set include paths of a c source in dub when using importc

2024-04-13 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 14/04/2024 8:59 AM, Ferhat Kurtulmuş wrote: These don't work for me: "dflags": ["-Iinclude"] "importPaths": [     "include" ], The importc docs do not help either. Appears it hasn't been documented in new dub docs. It is ``cSourcePaths`` and ``cImportPaths``.

How to set include paths of a c source in dub when using importc

2024-04-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
These don't work for me: "dflags": ["-Iinclude"] "importPaths": [ "include" ], The importc docs do not help either.

Re: How can I tell D that function args are @nogc etc.

2024-04-13 Thread Monkyyy via Digitalmars-d-learn
On Friday, 12 April 2024 at 03:57:40 UTC, John Dougan wrote: Not every day you get to blame a compiler bug. D is uniquely: hacky, expressive and buggy. Having more metaprograming then c++ without the raw man power comes at a cost, in d you should distrust the spec and instead see what the

Re: How can I tell D that function args are @nogc etc.

2024-04-12 Thread John Dougan via Digitalmars-d-learn
On Friday, 12 April 2024 at 15:08:50 UTC, Steven Schveighoffer wrote: On Friday, 12 April 2024 at 03:57:40 UTC, John Dougan wrote: What is the procedure for bug reporting? I'm looking at the issues tracker and have no clue how to drive the search to see if this is already there.

Re: Best way to use large C library in D as of 2024

2024-04-12 Thread Lance Bachmeier via Digitalmars-d-learn
On Friday, 12 April 2024 at 18:36:13 UTC, Chris Piker wrote: On Saturday, 30 March 2024 at 07:11:49 UTC, Mike Parker wrote: Though I appreciate the sentiment, it's much more effective and efficient for people actually using the feature, and who appreciate it, to write up a blog post about it

Re: Best way to use large C library in D as of 2024

2024-04-12 Thread Lance Bachmeier via Digitalmars-d-learn
On Friday, 12 April 2024 at 18:45:21 UTC, Chris Piker wrote: Even though DMD can't compile some C code, that's pretty much a non-issue for me anyway. In my environment the servers are all Linux so "apt-get" (or equivalent) typically provides a pre-compiled dependency. Being able to list a

Re: Best way to use large C library in D as of 2024

2024-04-12 Thread Chris Piker via Digitalmars-d-learn
On Monday, 1 April 2024 at 02:08:20 UTC, Lance Bachmeier wrote: On Saturday, 30 March 2024 at 05:01:32 UTC, harakim wrote: It works well if you only need to work with a header. There are still a few rough edges that get in the way if you're compiling the full C sources (I filed bugs for all of

Re: Best way to use large C library in D as of 2024

2024-04-12 Thread Chris Piker via Digitalmars-d-learn
On Saturday, 30 March 2024 at 07:11:49 UTC, Mike Parker wrote: Though I appreciate the sentiment, it's much more effective and efficient for people actually using the feature, and who appreciate it, to write up a blog post about it somewhere and share that on Twitter/Reddit/HN, etc. I would,

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 12 April 2024 at 00:04:48 UTC, Liam McGillivray wrote: Here's what I wanted to do. In the library I'm working on, there are various declarations for functions defined in an external C library following the line `extern (C) @nogc nothrow:`. Here are some examples of such

Re: How can I tell D that function args are @nogc etc.

2024-04-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 12 April 2024 at 03:57:40 UTC, John Dougan wrote: What is the procedure for bug reporting? I'm looking at the issues tracker and have no clue how to drive the search to see if this is already there. https://issues.dlang.org While entering the bug title, it does a fuzzy search

Re: How can I tell D that function args are @nogc etc.

2024-04-11 Thread John Dougan via Digitalmars-d-learn
On Thursday, 11 April 2024 at 15:00:49 UTC, Steven Schveighoffer wrote: So D can provide a nice mechanism to show what is happening -- `pragma(msg, ...)` If I do that with the two types above I see something *very* interesting: ```d pragma(msg, FnPrefixT); pragma(msg, FnSuffixT); ``` ```

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-11 Thread Liam McGillivray via Digitalmars-d-learn
On Tuesday, 9 April 2024 at 12:45:55 UTC, Richard (Rikki) Andrew Cattermole wrote: On 09/04/2024 12:48 PM, Liam McGillivray wrote: I suppose this was a good new thing to learn, though I'm still quite far from being able to construct a function from another function using a template. I

Re: mmap file performance

2024-04-11 Thread Andy Valencia via Digitalmars-d-learn
On Thursday, 11 April 2024 at 14:54:36 UTC, Steven Schveighoffer wrote: For a repeatable comparison, you should provide the code which does 1MB reads. With pleasure: import std.stdio : writeln, File, stderr; const uint BUFSIZE = 1024*1024; private uint countnl(File f) { uint res = 0;

Re: How can I tell D that function args are @nogc etc.

2024-04-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 11 April 2024 at 03:17:36 UTC, John Dougan wrote: Interesting. Thank you to both of you. On Wednesday, 10 April 2024 at 17:38:21 UTC, Steven Schveighoffer wrote: On Wednesday, 10 April 2024 at 11:34:06 UTC, Richard (Rikki) Andrew Cattermole wrote: Place your attributes on the

Re: mmap file performance

2024-04-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 11 April 2024 at 00:24:44 UTC, Andy Valencia wrote: I wrote a "count newlines" based on mapped files. It used about twice the CPU of the version which just read 1 meg at a time. I thought something was amiss (needless slice indirection or something), so I wrote the code in C.

Re: How can I tell D that function args are @nogc etc.

2024-04-10 Thread John Dougan via Digitalmars-d-learn
Interesting. Thank you to both of you. On Wednesday, 10 April 2024 at 17:38:21 UTC, Steven Schveighoffer wrote: On Wednesday, 10 April 2024 at 11:34:06 UTC, Richard (Rikki) Andrew Cattermole wrote: Place your attributes on the right hand side of the function, not the left side. Use the left

Re: Why does Nullable implicitly casts when assigning a variable but not when returning from a function?

2024-04-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 10, 2024 2:41:56 PM MDT Lettever via Digitalmars-d-learn wrote: > ``` > import std; > > Nullable!int func() => 3; > void main() { > Nullable!int a = 3; > //works fine > Nullable!int b = func(); > //does not compile > } Te

mmap file performance

2024-04-10 Thread Andy Valencia via Digitalmars-d-learn
I wrote a "count newlines" based on mapped files. It used about twice the CPU of the version which just read 1 meg at a time. I thought something was amiss (needless slice indirection or something), so I wrote the code in C. It had the same CPU usage as the D version. So...mapped files,

Re: Why does Nullable implicitly casts when assigning a variable but not when returning from a function?

2024-04-10 Thread Lettever via Digitalmars-d-learn
On Wednesday, 10 April 2024 at 21:38:22 UTC, Andy Valencia wrote: On Wednesday, 10 April 2024 at 20:41:56 UTC, Lettever wrote: ``` import std; Nullable!int func() => 3; void main() { Nullable!int a = 3; //works fine Nullable!int b = func(); //does not compile } Why make

Re: Why does Nullable implicitly casts when assigning a variable but not when returning from a function?

2024-04-10 Thread Andy Valencia via Digitalmars-d-learn
On Wednesday, 10 April 2024 at 20:41:56 UTC, Lettever wrote: ``` import std; Nullable!int func() => 3; void main() { Nullable!int a = 3; //works fine Nullable!int b = func(); //does not compile } Why make func() Nullable? It just wants to give you an int, right? Making it a

Re: What I thought was straightforward blew up in my face..

2024-04-10 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
```c void SDL_GetVersion(SDL_version * ver); ``` It doesn't return anything. Its return type is void. See the argument list where it lists the types of the arguments: ``template writeln is not callable using argument types !()(string, void)`` Which aligns with the arguments you passed to

What I thought was straightforward blew up in my face..

2024-04-10 Thread WhatMeWorry via Digitalmars-d-learn
import bindbc.sdl; import bindbc.loader; SDL_version ver; SDL_GetVersion(); writeln("version = ", ver); // runs and displays: version = SDL_version(2, 30, 2) writeln("version = ", SDL_GetVersion()); // compile fails with // template `writeln`

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 9 April 2024 at 23:50:36 UTC, Richard (Rikki) Andrew Cattermole wrote: On 10/04/2024 11:21 AM, Liam McGillivray wrote: On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. So that

Re: How can I tell D that function args are @nogc etc.

2024-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 10 April 2024 at 11:34:06 UTC, Richard (Rikki) Andrew Cattermole wrote: Place your attributes on the right hand side of the function, not the left side. Use the left side for attributes/type qualifiers that go on the return type. Just a word of warning, this explanation

Re: How can I tell D that function args are @nogc etc.

2024-04-10 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Place your attributes on the right hand side of the function, not the left side. Use the left side for attributes/type qualifiers that go on the return type. ```d bool[7] stagesToProcess = false; bool shouldDoInStages(int index) @nogc nothrow @safe { return stagesToProcess[index]; }

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-10 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 10/04/2024 2:50 PM, Liam McGillivray wrote: On Tuesday, 9 April 2024 at 23:50:36 UTC, Richard (Rikki) Andrew Cattermole wrote: The string mixin triggers CTFE, if ``EnumPrefixes`` wasn't templated, that would cause codegen and hence error. If you called it in a context that wasn't CTFE only,

How can I tell D that function args are @nogc etc.

2024-04-09 Thread John Dougan via Digitalmars-d-learn
Below is a example program that illustrates my issue. When compiled at run.dlang I get: ``` onlineapp.d(18): Error: `@safe` function `onlineapp.processSafely!(1, 4).processSafely` cannot call `@system` function pointer `shouldDo` onlineapp.d(28): Error: template instance

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Liam McGillivray via Digitalmars-d-learn
On Tuesday, 9 April 2024 at 23:50:36 UTC, Richard (Rikki) Andrew Cattermole wrote: The string mixin triggers CTFE, if ``EnumPrefixes`` wasn't templated, that would cause codegen and hence error. If you called it in a context that wasn't CTFE only, it would codegen even with template and would

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 10/04/2024 11:21 AM, Liam McGillivray wrote: On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. So that function is being used for both, and hence uses GC (appending). Are you sure that

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Liam McGillivray via Digitalmars-d-learn
On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. So that function is being used for both, and hence uses GC (appending). Are you sure that string appending was really the problem that

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 09/04/2024 12:48 PM, Liam McGillivray wrote: On Tuesday, 9 April 2024 at 00:02:02 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d enum Value = (a, b) { return a + b; }(1, 2); ``` This alone should be a CTFE only function. But if we want template parameters, we'd need to wrap it

Compile-time list of imported modules

2024-04-09 Thread Vladimir Marchevsky via Digitalmars-d-learn
Practical example: some framework allows it's user to define types of some messages. It can be done by manual calls like `something.registerMessage!T1()`, `something.registerMessage!T2()`. Other way is to leave it to framework: just annotate `T1`, `T2` with `@Command` UDA and call some core

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Kagamin via Digitalmars-d-learn
On Sunday, 7 April 2024 at 06:46:39 UTC, Liam McGillivray wrote: instantiated from here: `front!char` Looks like autodecoding, try to comment `canFind`.

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-08 Thread Liam McGillivray via Digitalmars-d-learn
On Tuesday, 9 April 2024 at 00:02:02 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d enum Value = (a, b) { return a + b; }(1, 2); ``` This alone should be a CTFE only function. But if we want template parameters, we'd need to wrap it with the template. ```d template Value(int a,

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 09/04/2024 11:42 AM, Liam McGillivray wrote: On Monday, 8 April 2024 at 08:12:22 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d template Foo(Args) { enum Foo = () {     return Args.init; }(); } ``` Something like that should work instead. I'm sorry, but I can't

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-08 Thread Liam McGillivray via Digitalmars-d-learn
On Monday, 8 April 2024 at 08:12:22 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d template Foo(Args) { enum Foo = () {     return Args.init; }(); } ``` Something like that should work instead. I'm sorry, but I can't comprehend any of your example. What would be fed into

Re: Setting up CI for Dub project on Github

2024-04-08 Thread Dmitry Olshansky via Digitalmars-d-learn
On Monday, 8 April 2024 at 13:23:12 UTC, Richard (Rikki) Andrew Cattermole wrote: On 09/04/2024 1:20 AM, Dmitry Olshansky wrote: I haven’t done any research on the subject, would be nice if somebody pointed me to good example of how it’s done. — Dmitry Olshansky CEO @ Glowlabs

Re: Setting up CI for Dub project on Github

2024-04-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 09/04/2024 1:20 AM, Dmitry Olshansky wrote: I haven’t done any research on the subject, would be nice if somebody pointed me to good example of how it’s done. — Dmitry Olshansky CEO @ Glowlabs https://olshansky.me In case you haven't already found:

  1   2   3   4   5   6   7   8   9   10   >