Re: A pass() identity range?
On Thursday, 2 December 2021 at 15:03:47 UTC, D Lark wrote: Because it does not seem like that from the tone of responses I have gotten: I did my due diligence, I believe, before posting my original reply to the old question. I had looked at the docs and also searched the forum. There is no need for the patronizing tone you have taken. No one has been patronizing to you. They were just explaining the informal custom in these forums. Please don't take it the wrong way. The forum software is a web interface to a newsgroup server. The software could be enhanced to prevent posting to old threads, but there's never been a need to (and people would still be able to post through the newsgroup server anyway). It's a fairly common convention across the internet (and has been for years) that reviving old threads is frowned upon (the term often used is "necroposting"). Normally, the warning provided is enough. So let's leave this thread to Rest in Peace. And next time you attempt to post an old thread here, please allow the forum software to do it's thing when it warns you. Thanks!
Re: sleeping vs sched_yield
On Thursday, 2 December 2021 at 23:29:17 UTC, Chris Katko wrote: there's: ```d import core.thread; Thread.sleep( dur!("msecs")(10) ); ``` but what if you want to simply yield all remaining time back to the time scheduler? Is there a D std.library accessible version of POSIX sched_yield: There's https://dlang.org/phobos/core_thread_osthread.html#.Thread.yield It seems I can (thanks to the amazing work of D community) simply do: ```d extern(C) int sched_yield(void); // #include ``` however, how does the linker know I need and not some local library, or SDL library, or SDL2.0 library, etc. Shouldn't I be specifying the library somewhere? Linker doesn't need sched.h. Like H.S.Theoh said, it'll look for that symbol in libraries you're linking against. sched_yield is in libc, and by default you do link against that. ``` source/app.d(226,16): Error: cannot have parameter of type `void` ``` Should that be corrected in the compiler? Shouldn't () and (void) be interchangeable as long as you're not doing void*? No: https://dlang.org/articles/ctod.html#funcvoid
Re: sleeping vs sched_yield
On Thu, Dec 02, 2021 at 11:29:17PM +, Chris Katko via Digitalmars-d-learn wrote: [...] > It seems I can (thanks to the amazing work of D community) simply do: > > ```d > extern(C) int sched_yield(void); // #include > ``` > > however, how does the linker know I need and not some local > library, or SDL library, or SDL2.0 library, etc. Shouldn't I be > specifying the library somewhere? An extern(C) function exists in the global namespace, namely, `sched_yield` will bind at link time to whatever library exports the symbol `sched_yield`. Most linkers (and linker configurations) will generate an error if there are multiple symbols with the same name defined. (The exception is when a symbol is marked as a "weak" symbol, but that's usually not done except for special purposes.) This is why good libraries like SDL always prefixes their API functions with `SDL_`, for example. In order to prevent confusion of SDL functions with a function of the same name from another library. [...] > Side side question: The above line fails to compile as-is because it > has (void) instead of (). > > ``` > source/app.d(226,16): Error: cannot have parameter of type `void` > ``` > > Should that be corrected in the compiler? Shouldn't () and (void) be > interchangeable as long as you're not doing void*? In C, `int func()` means `func` can take any number of arguments. That's why you need to write `int func(void)` to explicitly say there are NO parameters. But in D, `int func()` means `func` takes no arguments. So you never write `int func(void)`. D's `int func()` == C's `int func(void)`. T -- There are four kinds of lies: lies, damn lies, and statistics.
sleeping vs sched_yield
there's: ```d import core.thread; Thread.sleep( dur!("msecs")(10) ); ``` but what if you want to simply yield all remaining time back to the time scheduler? Is there a D std.library accessible version of POSIX sched_yield: https://man7.org/linux/man-pages/man2/sched_yield.2.html It seems I can (thanks to the amazing work of D community) simply do: ```d extern(C) int sched_yield(void); // #include ``` however, how does the linker know I need and not some local library, or SDL library, or SDL2.0 library, etc. Shouldn't I be specifying the library somewhere? Side side question: The above line fails to compile as-is because it has (void) instead of (). ``` source/app.d(226,16): Error: cannot have parameter of type `void` ``` Should that be corrected in the compiler? Shouldn't () and (void) be interchangeable as long as you're not doing void*?
Re: Debugging D code with GDB
On Tuesday, 30 November 2021 at 09:01:38 UTC, Iain Buclaw wrote: On Monday, 29 November 2021 at 14:48:21 UTC, Luís Ferreira wrote: [...] Indeed, gdb assumes calling convention is same as default for target (actually its been years since I last looked, but are calling conventions tags in dwarf? Does gdb know about functions with thiscall or regparm attributes?) Another thing on the gdb side, it is currently missing D language support for overloads, so that the correct function would be picked when you call e.g std.math.sin(1f). So currently the workaround is they way to go. Thank you all for your help and suggestions!
Re: Dub fails to run inside a docker container on MacBook
The first thing i'd check: - make sure you have curl installed on your docker image - make sure you link with the curl library (since you are using dub) That's on the notes: https://dlang.org/phobos/std_net_curl.html
Dub fails to run inside a docker container on MacBook
I am trying to create a Docker image where I can build my dub project. Here is a simple Dockerfile. ``` FROM ubuntu as build RUN apt-get update \ && apt-get install --no-install-recommends -y -q locales build-essential apt-transport-https ca-certificates dub\ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* WORKDIR /compiling COPY source source COPY dub.json . RUN dub build -b release ``` When I try to run `docker build .`, I get the following output: ``` [+] Building 1.0s (10/10) FINISHED => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 424B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/ubuntu:latest 0.6s => [internal] load build context 0.0s => => transferring context: 2.41kB 0.0s => [1/6] FROM docker.io/library/ubuntu@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322 0.0s => CACHED [2/6] RUN apt-get update && apt-get install --no-install-recommends -y -q locales build-essential apt-transport-https ca-certificates dub&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 0.0s => CACHED [3/6] WORKDIR /compiling 0.0s => CACHED [4/6] COPY source source 0.0s => CACHED [5/6] COPY dub.json . 0.0s => ERROR [6/6] RUN dub build -b release 0.2s -- > [6/6] RUN dub build -b release: #10 0.208 dub: symbol lookup error: dub: undefined symbol: _D3std3net4curl4HTTP9__mixin376onSendMFNdDFAvZmZv ``` I am running this from M1 MacBook but was successfully using similar Dockerfile with dub on a Linux machine. Could it be the issue?
Re: A pass() identity range?
On Thursday, 2 December 2021 at 14:53:31 UTC, D Lark wrote: On Thursday, 2 December 2021 at 14:47:17 UTC, Paul Backus wrote: This is why it's generally frowned upon to revive old threads: the information they contain is often out of date, and potentially misleading to anyone who reads them without looking carefully at the timestamps. [1]: https://phobos.dpldocs.info/std.range.tee.1.html [2]: https://github.com/dlang/phobos/pull/1965 I had see the std.range.tee, but it does not appear to me to be the same as itertools.tee. I think with std.range.tee you get an input range and an output range out of an input range. With python's itertool.tee you get two or more input ranges from an input range (hence my claim earlier that it sort of simulates forwardRange.save). Even in the present day, it seems there still exists a misconception. **Beyond the name there is not much similarity between the two, so I think my question is still valid**. Because it does not seem like that from the tone of responses I have gotten: I did my due diligence, I believe, before posting my original reply to the old question. I had looked at the docs and also searched the forum. There is no need for the patronizing tone you have taken.
Re: A pass() identity range?
On Thursday, 2 December 2021 at 14:47:17 UTC, Paul Backus wrote: On Thursday, 2 December 2021 at 11:35:53 UTC, D Lark wrote: I am a newcomer to D and I am looking for equivalent functionality in phobos (so far I have not found). The function you are looking for is [`std.range.tee`][1]. It was added to Phobos in 2014 by [pull request #1965][2], approximately one year after the post you replied to. This is why it's generally frowned upon to revive old threads: the information they contain is often out of date, and potentially misleading to anyone who reads them without looking carefully at the timestamps. [1]: https://phobos.dpldocs.info/std.range.tee.1.html [2]: https://github.com/dlang/phobos/pull/1965 I had see the std.range.tee, but it does not appear to me to be the same as itertools.tee. I think with std.range.tee you get an input range and an output range out of an input range. With python's itertool.tee you get two or more input ranges from an input range (hence my claim earlier that it sort of simulates forwardRange.save). I felt the need to reply in-line to correct the misconception from that post that itertools.tee "basically works on forwardRanges". It does something very different, there is no "forwardRange" in python the only range concept (iterators) are equivalent to inputRanges and nothing more.
Re: A pass() identity range?
On Thursday, 2 December 2021 at 14:47:17 UTC, Paul Backus wrote: On Thursday, 2 December 2021 at 11:35:53 UTC, D Lark wrote: I am a newcomer to D and I am looking for equivalent functionality in phobos (so far I have not found). The function you are looking for is [`std.range.tee`][1]. It was added to Phobos in 2014 by [pull request #1965][2], approximately one year after the post you replied to. This is why it's generally frowned upon to revive old threads: the information they contain is often out of date, and potentially misleading to anyone who reads them without looking carefully at the timestamps. [1]: https://phobos.dpldocs.info/std.range.tee.1.html [2]: https://github.com/dlang/phobos/pull/1965 I had see the std.range.tee, but it does not appear to me to be the same as itertools.tee. I think with std.range.tee you get an input range and an output range out of an input range. With python's itertool.tee you get two or more input ranges from an input range (hence my claim earlier that it sort of simulates forwardRange.save). I felt the need to reply in-line to correct the misconception from that post that itertools.tee "basically works on forwardRanges". It does something very different, there is no "forwardRange" in python the only range concept (iterators) are equivalent to inputRanges and nothing more.
Re: A pass() identity range?
On Thursday, 2 December 2021 at 11:35:53 UTC, D Lark wrote: I am a newcomer to D and I am looking for equivalent functionality in phobos (so far I have not found). The function you are looking for is [`std.range.tee`][1]. It was added to Phobos in 2014 by [pull request #1965][2], approximately one year after the post you replied to. This is why it's generally frowned upon to revive old threads: the information they contain is often out of date, and potentially misleading to anyone who reads them without looking carefully at the timestamps. [1]: https://phobos.dpldocs.info/std.range.tee.1.html [2]: https://github.com/dlang/phobos/pull/1965
Re: A pass() identity range?
On Thursday, 2 December 2021 at 13:22:55 UTC, Steven Schveighoffer wrote: On 12/2/21 6:35 AM, D Lark wrote: On Wednesday, 2 January 2013 at 18:49:06 UTC, H. S. Teoh wrote: Note the date of post you are responding to. When the system says "hey, you are responding to a really old thread, let me fix that for you", you should click the button. Please don't reply to really old threads directly, instead you use a link (which is what the system will do for you automatically) -Steve PS: I think this message is unhelpful, unnecessary (since you know that the system issues a warning) and is worse than ignoring the post altogether (if you otherwise had nothing to contribute).
Re: A pass() identity range?
On Thursday, 2 December 2021 at 13:22:55 UTC, Steven Schveighoffer wrote: On 12/2/21 6:35 AM, D Lark wrote: On Wednesday, 2 January 2013 at 18:49:06 UTC, H. S. Teoh wrote: Note the date of post you are responding to. When the system says "hey, you are responding to a really old thread, let me fix that for you", you should click the button. Please don't reply to really old threads directly, instead you use a link (which is what the system will do for you automatically) -Steve Well, if it should not be possible to reply then maybe disable it altogether? I think it is reasonable to respond to old threads if the context makes sense (as I believe it does in this case), and the system agrees with me.
Re: Running only one instance of the app
On Thursday, 2 December 2021 at 13:28:12 UTC, Steven Schveighoffer wrote: On 12/2/21 7:05 AM, Bagomot wrote: This works for Windows. I need something similar for Linux and Macos. Tell me how, if you know. Maybe the standard library D already has the required functionality? Or are there better ways to only run one instance of the app? Typically this is done using pid files. https://linux.die.net/man/3/pidfile But I don't know if MacOS has a specialized call for it, or if you have to do it yourself. I think you need to lock the file with `flock` to get it to work properly. -Steve I can't use flock, because my app uses the file rename to auto-update in Windows. It renames itself to old.app.exe, downloads the new version and runs it, then exits. I haven’t figured out how to do this in other OSs yet.
Re: Running only one instance of the app
On 12/2/21 7:05 AM, Bagomot wrote: This works for Windows. I need something similar for Linux and Macos. Tell me how, if you know. Maybe the standard library D already has the required functionality? Or are there better ways to only run one instance of the app? Typically this is done using pid files. https://linux.die.net/man/3/pidfile But I don't know if MacOS has a specialized call for it, or if you have to do it yourself. I think you need to lock the file with `flock` to get it to work properly. -Steve
Re: A pass() identity range?
On 12/2/21 6:35 AM, D Lark wrote: On Wednesday, 2 January 2013 at 18:49:06 UTC, H. S. Teoh wrote: Note the date of post you are responding to. When the system says "hey, you are responding to a really old thread, let me fix that for you", you should click the button. Please don't reply to really old threads directly, instead you use a link (which is what the system will do for you automatically) -Steve
Running only one instance of the app
Hello everyone! I need to allow only one instance of my application to run. I use this way for Windows: ```d import std.stdio; import std.utf; version(Windows) { import core.sys.windows.winbase; import core.sys.windows.windows; } void main(string[] args) { string mutexName = ""; version(Windows) { HANDLE mutex; //global handle mutex try { mutex=CreateMutex(NULL, true, uuidMutexName.toUTF16z); DWORD result; result = WaitForSingleObject(mutex, 0); if(result != WAIT_OBJECT_0) { writeln("The app is already running!"); return; } } catch(Exception e) { writeln(e.msg); } scope(exit) { ReleaseMutex(mutex); CloseHandle(mutex); } } //todo while(true){} } ``` This is where the application creates a global mutex with a specific name. At startup, the application checks for the presence of such a mutex. If it is, then a instance of the application has already been launched. This works for Windows. I need something similar for Linux and Macos. Tell me how, if you know. Maybe the standard library D already has the required functionality? Or are there better ways to only run one instance of the app?
Re: A pass() identity range?
On Wednesday, 2 January 2013 at 18:49:06 UTC, H. S. Teoh wrote: On Wed, Jan 02, 2013 at 07:19:31PM +0100, bearophile wrote: H. S. Teoh: [...] >but I thought tee() might be a better name. Python programmers have this "tee": http://docs.python.org/3/library/itertools.html#itertools.tee [...] Hmm. But isn't that just the same as repeatedly calling .save with D's forward ranges? T Not really, the python itertools.tee affords a sort of 'save' on *inputRanges* (all python iterators roughly model inputRanges, and nothing more) hence letting you simulate forwardRange: you just have to promise not to touch the underlying range directly after a call to itertools.tee and instead work with the resulting split ranges provided. I am a newcomer to D and I am looking for equivalent functionality in phobos (so far I have not found). Is there a way to convert inputRanges into forwardRanges, at the cost of extra memory? PS: thanks for your range calendar tutorial!
Re: How to make a new dub subpackage? [Answered]
On Saturday, 20 November 2021 at 13:45:43 UTC, BoQsc wrote: [...] To make a subpackage with dub; follow these general guidelines. **General guidelines** [...] Just a side note, you can also supply a name to init directly and it creates the directory etc: dub init myproject