How to call function with variable arguments at runtime?
I need to store a hetrogeneous array of delegates. How can I do this but still call the function with the appropriate number of parameters at run time? I have the parameters as Variant[] params and a function/delegate pointer(void* for now). Normally I'd push the parameters on the stack and use a call, but I'm sure D has some ability to do this, like apply(foo, args) would be the same as foo(args[0], ..., args[1]). I'm not concerned about type correctness, it should always be consistent between what I call and what is stored. Thanks.
Undo?
I requiring an undo feature in my code. Rather than go the regular route of using commands, I'm wondering if D can facilitate an undo system quite easily? We can think of an undo system in an app as a sort of recorder. The traditional method is to use commands and inverse-commands. By recording the commands one can "unwind" the program by applying the inverse commands. The down side is that the app must be written with this approach in mind. Storing the complete state of the app is another way which some apps use but usually it is too much data to store. Since the only thing that one has to store from state of the app to the next is the change in data long with creation and deletion of the data, I think one could simplify the task? Is it possible to write a generic system that records the the entire state changes without much boilerplate? I'm thinking that two types of attributes would work, one for aggregates for creation and deletion of objects and one for properties to handle the data changes. If D can be used to automatically hook properties to have them report the changes to the undo system and one can properly deal with object creation and assignment, it might be a pretty sleek way to support undo. Help appreciated!
Re: How to make commented code to compile?
On Monday, 9 October 2017 at 15:15:48 UTC, Zhuo Nengwen wrote: test(cast(ushort) 1, (m, c) => { writeln(m); writeln(m); }); Just remove the => (m, c) { // code here }
Re: How to make commented code to compile?
On Monday, 9 October 2017 at 14:54:33 UTC, Adam D. Ruppe wrote: //test(cast(ushort) 1, (m, c) => { writeln(m); }); That's a function that returns a function. Perhaps you meant to just remove the => and be left with a multi-line function. I simplified the test codes. I want write mode codes in closure, such as: test(cast(ushort) 1, (m, c) => { writeln(m); writeln(m); });
Re: Add a precompiled c++ obj file to dub
On Sunday, 8 October 2017 at 04:03:27 UTC, user1234 wrote: On Sunday, 8 October 2017 at 02:58:36 UTC, Fra Mecca wrote: On Saturday, 7 October 2017 at 23:54:50 UTC, user1234 wrote: On Saturday, 7 October 2017 at 19:56:52 UTC, Fra Mecca wrote: Hi all, I am writing a backend that is partly Vibe.d and partly clucene in c++. I have some object files written in c++ and compiled with g++ that are not considered by dub during the linking phase and throws `function undefined error ` every time. Is there a way to tell dub to let dmd handle that .o files? Yes, add this to your JSON: "sourceFiles-linux-x86_64" : [ "somepath/yourobject.o" ], I tried the sourceFiles approach, it failed and I could reproduce that in some days. At the end I added them as linking options (lflags) but it is kinda odd that it works given that everything is supplied to dmd as -Lobj.o Huh, i'm surprised but well, if it works for you. My advice was based on https://github.com/BBasile/dbeaengine/blob/master/dub.json (object file is passed to dmd) which works, I often use it. Yeah that's becuz passing *.o / *.obj files to the linker or to dmd is the same buisness under the hood. The problem with this DUB project is that it will only compiles with DMD. Maybe the OP used another compiler. other compilers may not support the shortcut here: https://github.com/dlang/dmd/blob/master/src/ddmd/mars.d#L626
Re: How to make commented code to compile?
On Monday, 9 October 2017 at 14:34:48 UTC, Zhuo Nengwen wrote: //test(cast(ushort) 1, (m, c) => { writeln(m); }); That's a function that returns a function. Perhaps you meant to just remove the => and be left with a multi-line function.
How to make commented code to compile?
import std.stdio; void test(ushort market, void delegate(ushort market, char* pc) callback) { for (auto i = 0; i < 10; i++) { callback(cast(ushort) i, cast(char*) null); } } void main() { test(cast(ushort) 1, (m, c) => writeln(m)); //test(cast(ushort) 1, (m, c) => { writeln(m); }); test(cast(ushort) 1, (ushort m, char* c) => writeln(m)); //test(cast(ushort) 1, (ushort m, char* c) => { writeln(m); }); }
Re: Add a precompiled c++ obj file to dub
On 2017-10-08 04:58, Fra Mecca wrote: At the end I added them as linking options (lflags) but it is kinda odd that it works given that everything is supplied to dmd as -Lobj.o Everything passed to DMD with the -L flag is passed to the linker, basically as is. So if the linker accepts object files passed directly on the command line then it works. -- /Jacob Carlborg
Re: Bug? ElementType fails if element type is const
oops, it was my fault. sorry for noise. my apologies to ElementType ))
Bug? ElementType fails if element type is const
https://run.dlang.io/is/duecIS
Re: @nogc formattedWrite
On Saturday, 7 October 2017 at 18:14:00 UTC, Nordlöw wrote: Is it currently possible to somehow do @nogc formatted output to string? I'm currently using my `pure @nogc nothrow` array-container `CopyableArray` as @safe pure /*TODO nothrow @nogc*/ unittest { import std.format : formattedWrite; const x = "42"; alias A = CopyableArray!(char); A a; a.formattedWrite!("x : %s")(x); assert(a == "x : 42"); } but I can't tag the unittest as `nothrow @nogc` because of the call to `formattedWrite`. Is this because `formattedWrite` internally uses the GC for buffer allocations or because it may throw? It would be nice to be able to formatted output in -betterC... Phobos code is not @nogc (can be fixed), but it will not nothrow. PRs with @nogc formatting functionality are welcome in Mir Algorithm. Cheers, Ilya
Re: @nogc formattedWrite
On Saturday, 7 October 2017 at 18:27:36 UTC, jmh530 wrote: On Saturday, 7 October 2017 at 18:14:00 UTC, Nordlöw wrote: It would be nice to be able to formatted output in -betterC... Agreed. If you know the size of the buffer, you can use sformat, which might be @nogc, but I don't know if it's compatible with betterC. Also, you might check out Ocean, which might have nogc formatting. https://github.com/sociomantic-tsunami/ocean As far as I know sformat is still not @nogc because it may throw an exception if buffer is not large enough, and throwing exceptions requires allocation.