Re: Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));
On Tue, Nov 12, 2019 at 11:50 PM Marcone via Digitalmars-d-learn wrote: > > > Can you make Alias for: > task!func().executeInNewThread(); > > Thank you! AFAIK that is not possible without some wrapper because executeInNewThread is member function of Task so it will need this reference for object
linking to shared lib on Windows
I now have the following working on Linux and macOS. - name "myapp" targetType "executable" description "A minimal D application." authors "bartland" copyright "Copyright © 2019, bartland" license "public" libs "mylib" lflags "-L../../_cache/" "-rpath" "../../_cache/" --- What is the approach on Windows these days (many posts on the matter seem out of date)? The shared C dll was built in MSYS2/MINGW32. On Windows (PATH=C:\D\dmd2\windows\bin;C:\D\dmc\dm\bin): (Looks like it's invoking the MS linker?) Linking... C:\D\dmd2\windows\bin\dmd.exe -of.dub\build\application-debug-windows-x86_64-dmd_2089-5F4166A8E1793C219FB49EC77A7D7D35\myapp.exe .dub\build\application-debug-windows-x86_64-dmd_2089-5F4166A8E1793C219FB49EC77A7D7D35\myapp.obj mylib.lib -L-L../../_cache/ -L-rpath -L../../_cache/ -m64 -g LINK : warning LNK4044: unrecognized option '/L../../_cache/'; ignored LINK : warning LNK4044: unrecognized option '/rpath'; ignored LINK : fatal error LNK1104: cannot open file '../../_cache/.obj' Error: linker exited with status 1104
Re: Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));
On Tuesday, 12 November 2019 at 22:26:48 UTC, Daniel Kozak wrote: On Tuesday, 12 November 2019 at 21:24:54 UTC, Marcone wrote: I am using this function to sleep, but I want a simple Alias. How can I alias this? // Function sleep(int) void sleep(int seconds){ Thread.sleep(dur!("seconds")( seconds )); } sleep(1); // Using function. You can do this: import std.functional; import core.time; import core.thread; alias sleep = compose!(Thread.sleep, dur!("seconds")); void main() { sleep(10); } Can you make Alias for: task!func().executeInNewThread(); Thank you!
Re: Strange function
On Tuesday, 12 November 2019 at 21:05:35 UTC, Adam D. Ruppe wrote: On Tuesday, 12 November 2019 at 20:45:11 UTC, Orfeo wrote: In druntime (core/bitop.d line 302) I found this function it is a magic function that the compiler recognizes and outputs a cpu instruction instead of a regular call. core.bitop has a few of those. Wow! Thank you very much
Re: Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));
On Tuesday, 12 November 2019 at 22:26:48 UTC, Daniel Kozak wrote: On Tuesday, 12 November 2019 at 21:24:54 UTC, Marcone wrote: I am using this function to sleep, but I want a simple Alias. How can I alias this? // Function sleep(int) void sleep(int seconds){ Thread.sleep(dur!("seconds")( seconds )); } sleep(1); // Using function. You can do this: import std.functional; import core.time; import core.thread; alias sleep = compose!(Thread.sleep, dur!("seconds")); void main() { sleep(10); } Daniel Kozak Thank you very much! It works very well!
Re: Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));
On Tuesday, 12 November 2019 at 21:24:54 UTC, Marcone wrote: I am using this function to sleep, but I want a simple Alias. How can I alias this? // Function sleep(int) void sleep(int seconds){ Thread.sleep(dur!("seconds")( seconds )); } sleep(1); // Using function. You can do this: import std.functional; import core.time; import core.thread; alias sleep = compose!(Thread.sleep, dur!("seconds")); void main() { sleep(10); }
Re: Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));
On Tuesday, November 12, 2019 2:24:54 PM MST Marcone via Digitalmars-d-learn wrote: > I am using this function to sleep, but I want a simple Alias. How > can I alias this? > > // Function sleep(int) > void sleep(int seconds){ > Thread.sleep(dur!("seconds")( seconds )); > } > > sleep(1); // Using function. An alias just gives a different name for a symbol. It can't pass arguments for you or call a function and pass its result to another. So, while you could create an alias for Thread.sleep, you'd have to call it exactly like you'd call Thread.sleep - just with a different name. If you want to do something like have it accept an int instead of a Duration, then you need a wrapper function like you're already doing. Now, in core.time, dur!"seconds" has an alias named seconds, so if you're simply looking to reduce how much typing you're doing, you could have Thread.sleep(seconds(42)), or if you aliased Thread.sleep to sleep, you could do sleep(seconds(42)), but you can't do something like sleep(42) without a wrapper function. In any case, I'd suggest that you avoid passing around naked integers as time values. Thread.sleep takes a Duration specifically because it makes for clearer code and is less error-prone than using a naked integer (since a naked integer has no units). - Jonathan M Davis
Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));
I am using this function to sleep, but I want a simple Alias. How can I alias this? // Function sleep(int) void sleep(int seconds){ Thread.sleep(dur!("seconds")( seconds )); } sleep(1); // Using function.
Re: Strange function
On Tuesday, 12 November 2019 at 20:45:11 UTC, Orfeo wrote: In druntime (core/bitop.d line 302) I found this function it is a magic function that the compiler recognizes and outputs a cpu instruction instead of a regular call. core.bitop has a few of those.
Re: Which is the active fork in DFL gui library ?
On Saturday, 2 November 2019 at 20:01:27 UTC, Vinod K Chandran wrote: Hi all, I just found that DFL gui library very interesting. But after some searching, i can see that DFL is inactive and there is few other forks for it. So this is my question - Which fork is good for a gui development in windows platform. BTW, i just tested the gtkD and successfully compiled a hello app. How do i avoid the console window when compiling gtkD app ? Thanks in advance. Another similar work is [DGui](https://github.com/o3o/dguihub)
Strange function
In druntime (core/bitop.d line 302) I found this function ``` /** * Tests and resets (sets to 0) the bit. */ int btr(size_t* p, size_t bitnum) pure @system; ``` Honestly don't understand: where is the body of the function? I thought I could find something like that: ``` int btr(size_t* p, size_t bitnum) pure @system { // body } Thank you
Re: Troubleshooting DUB invocations
On Tuesday, 12 November 2019 at 16:44:06 UTC, Dukc wrote: When trying to compile a project including newest Spasm (DUB package) using the newest LDC via DUB, the result is: ``` lld: error: unknown argument: --no-as-needed ``` I then ran DUB with -v switch and it turned out the invocation contained `-L--no-as-needed` as first of all the -L arguments. The trouble is, how do I know what causes DUB to add that argument to the invocation? I could find no reason in `dub.` files of either my package, Spasm or any package in Spasm dependency tree. Dub is open-source, so you can grep the source. - Dub uses it for all 3 compilers (e.g., https://github.com/dlang/dub/blob/f87302dd206b0e5871b39704e694b2194e294aa5/source/dub/compilers/ldc.d#L249), and I'm not sure it's really needed. Anyway, you can also use another linker that supports this flag (e.g., via `-linker=gold`).
Troubleshooting DUB invocations
When trying to compile a project including newest Spasm (DUB package) using the newest LDC via DUB, the result is: ``` lld: error: unknown argument: --no-as-needed ``` I then ran DUB with -v switch and it turned out the invocation contained `-L--no-as-needed` as first of all the -L arguments. The trouble is, how do I know what causes DUB to add that argument to the invocation? I could find no reason in `dub.` files of either my package, Spasm or any package in Spasm dependency tree.
Blog Post #87: Nodes-n-noodles, Part VI - Defining Hot Spots
Sorry I'm late today... Carrying on with the Nodes-n-noodles series, today we define the hot spots for the drag bar and the in/out terminals. You can find it here: https://gtkdcoding.com/2019/11/12/0087-nodes-vi-hotspots.html
Re: Is there any writeln like functions without GC?
If your goal is to debug your @nogc code, you can use writeln in debug statement: @nogc void main() { debug writeln("hello, debug world!"); }
(SOLVED) Re: rpath on macOS
On Tuesday, 12 November 2019 at 10:44:07 UTC, kinke wrote: On Tuesday, 12 November 2019 at 10:19:30 UTC, cartland wrote: but on macOS with DMD or LDC this gives ld: unknown option: -rpath=../../_cache/" IIRC, Mac's ld64 linker requires 2 separated args: "-rpath" "../../_cache/" Brilliant. lflags "-L../../_cache/" "-rpath" "../../_cache/" also works on Linux. Thanks
Re: rpath on macOS
On Tuesday, 12 November 2019 at 10:19:30 UTC, cartland wrote: but on macOS with DMD or LDC this gives ld: unknown option: -rpath=../../_cache/" IIRC, Mac's ld64 linker requires 2 separated args: "-rpath" "../../_cache/"
Re: rpath on macOS
On Tuesday, 12 November 2019 at 10:19:30 UTC, cartland wrote: On Linux, this works: *snip* but on macOS with DMD or LDC this gives ld: unknown option: -rpath=../../_cache/" Currently I do this post build to get the binary to work: -- install_name_tool -add_rpath "../../_cache" myapp --
rpath on macOS
On Linux, this works: name "myapp" targetType "executable" description "A minimal D application." authors "bartland" copyright "Copyright © 2019, bartland" license "public" libs "mylib" lflags "-L../../_cache/" "-rpath=../../_cache/" but on macOS with DMD or LDC this gives ld: unknown option: -rpath=../../_cache/"
Re: Unexpected aliasing
On Tuesday, 12 November 2019 at 08:15:20 UTC, Basile B. wrote: I'm curious to know what is the equivalent in Pascal that your transpiler fails to translate since Pascal records don't have constructors at all. Maybe you used an old school 'Object' ? Note that Extended Pascal is not exactly Pascal. An example: TYPE Ints(upperBound) = ARRAY [1 .. upperBound] of Integer; MyRecord = RECORD integers : Ints(5); END; SchematicRecord(num) = RECORD integers : Ints(num); END; IntsPtr = ^Ints; PROCEDURE myProcedure(PROTECTED VAR someArr : Ints); BEGIN writeln(someArr.upperBound); END; PROCEDURE proc; VAR dynamicInts : IntsPtr; rec : MyRecord; BEGIN dynamicInts = new(10); myProcedure(dynamicInts^); myProcedure(rec.integers); END; In this case, only the upper bound of Ints is parameterized, but the lower bound could be parameterized as well. Records can also be schematized. Procedure arguments can take schemas that are undiscriminated, they carry their schemaparameters as properties. Bastiaan.
Re: Unexpected aliasing
On Monday, 11 November 2019 at 21:52:12 UTC, Jonathan M Davis wrote: On Monday, November 11, 2019 12:17:37 PM MST Bastiaan Veelo via Digitalmars- d-learn wrote: [...] I could use some help in rewriting the code below so that arr1 and arr2 each have their own data; ideally with minimal changes so that I can make the transcompiler do the right thing. Thanks! Bastiaan. void main() { import std.stdio; WrapIntegerArray arr1; arr1[0] = 42; WrapIntegerArray arr2; writeln(arr2[0]); // 42, not 0. writeln("arr1.wrap.arr.ptr = ", arr1.wrap.arr.ptr); writeln("arr2.wrap.arr.ptr = ", arr2.wrap.arr.ptr); // identical assert(arr2[0] == 0); // fails } struct IntegerArray { int[] arr; alias arr this; this(int l) { arr = new int[l]; } } struct WrapIntegerArray { auto wrap = IntegerArray(5); // This is CTFE! :-( alias wrap this; } All struct and class members which are directly initialized must have their values known at compile-time. For structs, that's what goes in the init value for the type. A side effect of this is that it's usually a bad idea to directly initialize dynamic arrays which are member variables. You need to do the initialization in a constructor. And for structs, if you need a no-arg constructor, then you'll need to use a factory function (since structs can't have no-arg constructors). e.g. struct WrapIntegerArray { IntegerArray wrap; alias wrap this; this(int len) { wrap = IntegerArray(len); } } or struct WrapIntegerArray { IntegerArray wrap; alias wrap this; static make() { WrapIntegerArray retval; retval.wrap = IntegerArray(5); return retval; } } So, you could then have something like auto arr1 = WrapIntegerArray(5); arr1[0] = 42; or auto arr1 = WrapIntegerArray.make(); arr1[0] = 42; but if you use the init value (which is what you get if you let the type be default-initialized), then you'll have to first do something to allocate the dynamic array if you want to be able to index it, since if you don't give it a value at compile-time, it's null (and you don't want to give it a value at compile-time, because then every default-initialized struct of that type will refer to the same dynamic array). Of course, you could always just append values, and the dynamic array will be allocated and grow accordingly, but that's obviously not the same as allocating it up front to have a specific length. - Jonathan M Davis Thank you Jonathan. A factory function seems to be what I need, then. It'll be an interesting challenge to have my transpiler detect when a factory function is needed, and making sure that they are called at the right places. But this might escalate since structs can have members that are structs that have a factory function. So the enclosing struct also needs a factory function. And so forth. My problem is the translation of so called schematic arrays, a type that I have only seen in Extended Pascal. A schematic array is a type in which the length of the array is a parameter of the type. Extended Pascal does not have dynamic arrays, so schematic arrays are its attempt at improving a bit on just plain static arrays. The length parameter can be constant, in which it behaves akin to templates (which it doesn't have either), but it can also be set at run time during initialization (so I can't translate it to a template). Maybe I can omit the translation of schematic arrays (IntegerArray in this case) altogether and instead detect where and how they are instantiated. Then replace them with a static array whenever the length is known at compile time, and a dynamic array otherwise. A static array is not nice, but at least they can be members of structs without a factory function. Either way, my transpiler needs to smarten up... Bastiaan.
Re: SQL Questions Query
On Monday, 21 October 2019 at 09:57:16 UTC, Arjunkumar wrote: Hello Everyone, I am looking for SQL interview questions list. I have scheduled my interviews in the upcoming week, Recruiters told me they might test my SQL knowledge too. What kind of questions should I expect? One is a consultant swe / data scientist and the other is an application developer. Here I am sharing with you a list of interview questions, which you need to go through and you will get an answer to these questions from here (https://hackr.io/blog/top-sql-interview-questions). 1. What is the difference between DBMS and RDBMS? 2. Can we embed Pl/SQL in SQL? Justify your answers 3. What do you mean by data manipulation language - DML? 4. What is a join in SQL? What are the types of joins? 5. What is the difference between CHAR and VARCHAR2 datatype in SQL? 6. What is a trigger? 7. What are SQL constraints give examples? 8. What are ACID properties in a transaction? 9. What is SAVEPOINT in a transaction control? 10. What are the scalar functions in SQL? Give an example
Re: Unexpected aliasing
On Tuesday, 12 November 2019 at 07:59:39 UTC, Bastiaan Veelo wrote: On Monday, 11 November 2019 at 20:05:11 UTC, Antonio Corbi wrote: [...] Thanks, Antonio. My problem is that the length of the array should be a built-in property of WrapIntegerArray (immutable in this case); what I'd actually want is a constructor without arguments. Jonathan's suggestion of using a factory function comes closest to that. Bastiaan. I'm curious to know what is the equivalent in Pascal that your transpiler fails to translate since Pascal records don't have constructors at all. Maybe you used an old school 'Object' ?
Re: Unexpected aliasing
On Monday, 11 November 2019 at 20:05:11 UTC, Antonio Corbi wrote: Defining and using a constructor for WrapIntegerArray seems to work: void main() { import std.stdio; WrapIntegerArray arr1 = WrapIntegerArray(5); arr1[0] = 42; WrapIntegerArray arr2 = WrapIntegerArray(5); writeln(arr2[0]); // 42, not 0. writeln("arr1.wrap.arr.ptr = ", arr1.wrap.arr.ptr); writeln("arr2.wrap.arr.ptr = ", arr2.wrap.arr.ptr); // identical assert(arr2[0] == 0); // fails } struct IntegerArray { int[] arr; alias arr this; this(int l) { arr = new int[l]; } } struct WrapIntegerArray { this (int v) { wrap = IntegerArray(5); } IntegerArray wrap; alias wrap this; } Hope this helps. Antonio Thanks, Antonio. My problem is that the length of the array should be a built-in property of WrapIntegerArray (immutable in this case); what I'd actually want is a constructor without arguments. Jonathan's suggestion of using a factory function comes closest to that. Bastiaan.