Re: Compilation error while adding two shorts
On 06/23/2014 10:03 PM, David Zaragoza wrote:> Hello > > I'm trying to compile the following program: > > module main; > > int main(string[] argv){ > short asd = 1; > short qwe = asd + asd; > return 0; > } > > And the compiler gives this error: > > C:\David>dmd simple > simple.d(5): Error: cannot implicitly convert expression (cast(int)asd + > cast(in > t)asd) of type int to short > > Why is there a cast if I'm adding to shorts? > > Regards This is a common gotcha of system languages like C, C++, and D. Operations like + are never executed in types like 'short'.[1] Since the result of that + is int, the compiler does not allow assigning the value back to a short, which can lose data. However, in this case it is clear that the value of asd is known to be 1 at compile time and that there will not be data loss. The D compilers apply what is known as 'value range propagation'[2], which should take care of your issue. I guess the use in your program is too complicated for the current compiler. Ali [1] See both "Integer Promotions" and "Usual Arithmetic Conversions" here: http://dlang.org/type.html [2] "Value Range Propagation" http://www.drdobbs.com/tools/value-range-propagation/229300211
Compilation error while adding two shorts
Hello I'm trying to compile the following program: module main; int main(string[] argv){ short asd = 1; short qwe = asd + asd; return 0; } And the compiler gives this error: C:\David>dmd simple simple.d(5): Error: cannot implicitly convert expression (cast(int)asd + cast(in t)asd) of type int to short Why is there a cast if I'm adding to shorts? Regards
Re: Missed it by THIS much
On 24/06/2014 1:13 p.m., Jason King wrote: This is me trying to link with Juno and getting tantalizingly close to success. DMD home is d:\d so binaries are d:\d\dmd2\windows\bin (on path) Juno is in D:\dlang\Juno-Windows-Class-Library D:\dlang\Juno-Windows-Class-Library\juno.lib exists sc.ini is untouched D:\dlang\Juno-Windows-Class-Library\examples\com>dmd -L+d:\dlang\Juno-Windows-Cl ass-Library\juno.lib -Id:\dlang\Juno-Windows-Class-Library events.d OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html d:\dlang\Juno-Windows-Class-Library\juno.lib(core) Error 42: Symbol Undefined _VarCmp@16 --- errorlevel 1 I'm pretty sure I've got the -L+ part right because when I didn't I got about 20 Symbol Undefined errors and if I leave out the -I part it doesn't even compile. What's the trick to get the link to work? Looks like that's a Windows API function [0]. Get it to link with OleAut32 and it should work, if I'm correct. [0] http://msdn.microsoft.com/en-us/library/windows/desktop/ms221006(v=vs.85).aspx
Another rambling musing by a Dynamic Programmer - map!
So in Ruby and R and Scheme and... I have happily used map / collect for years and years. Lovely thing. So I did the dumb obvious of string[] stringList = map!...; And D barfed, wrong type, some evil voldemort thing again. So.. auto stringList = map!; and we're good.. and happily use it as foreach( s; stringList) Suddenly the words in the map! documentation made sense to me... unlike Ruby, map doesn't allocate and populate an array. It just returns a lazy range. No array is allocated (unless I ask for one), it just does the lambda when I want it in the foreach! Cool! Very very cunning. Very light on resources. I itch to get D working in the OpenEmbedded environment...
Re: Why does this work?
On Monday, 23 June 2014 at 09:09:56 UTC, hane wrote: On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote: import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug? You declared a variable template named "tuple" (with unused type parameters a, b) on that line. http://dlang.org/template.html#variable-template I think this is very confusable syntax... void main() { auto tuple(a, b) = foo2(1); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(1, true)" tuple!(int, int) = foo2(20); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(20, true)" } Problem solved, Thank you so much!
Missed it by THIS much
This is me trying to link with Juno and getting tantalizingly close to success. DMD home is d:\d so binaries are d:\d\dmd2\windows\bin (on path) Juno is in D:\dlang\Juno-Windows-Class-Library D:\dlang\Juno-Windows-Class-Library\juno.lib exists sc.ini is untouched D:\dlang\Juno-Windows-Class-Library\examples\com>dmd -L+d:\dlang\Juno-Windows-Cl ass-Library\juno.lib -Id:\dlang\Juno-Windows-Class-Library events.d OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html d:\dlang\Juno-Windows-Class-Library\juno.lib(core) Error 42: Symbol Undefined _VarCmp@16 --- errorlevel 1 I'm pretty sure I've got the -L+ part right because when I didn't I got about 20 Symbol Undefined errors and if I leave out the -I part it doesn't even compile. What's the trick to get the link to work?
Re: Trying to reproduce Node.js async waterfall pattern.. (Meta-programming)
Just an idea that popped into my head... Maybe I can use variant for the input/output types? I haven't looked at it yet, so I'm not sure what it does, or the performance costs. I realized that because the final callback always gets called, and the types of the intermediate steps may be different, there is actually no way at all to define a completely uniformly type safe final callback... although the point is a little moot, because the only way you end up in the final callback is either by an Exception or a Result from the finalCallback - 1 step. So you can actually never get both an Exception and a Result
Re: Trying to reproduce Node.js async waterfall pattern.. (Meta-programming)
Just to be sure: whether or not an error is passed to a callback, the final callback is always called? I mean, the last callback could also be called *only when something fails*, a bit like a default case in a switch, or an error-handling routine. Yes, the final callback is always called, but if an error is passed to the callback by any of the main steps in the "sequence ladder", it will immediately jump to the final callback and not execute further steps. What do you mean? The compiler does deduce the type of Funcs. If you look at where I call Waterfall() in main, you'll see I had to manually specify (Callback cb) instead of just (cb); since it didn't know that the Funcs... were of type AsyncFunc What do you mean by 'specialize'? That is to say, there is no way I can see, to say that the variadic template parameter "Funcs..." are all AsyncFunc's. I think I noticed that in Swift you can say something like "Funcs:AsyncFunc..." to specialize the variadic. No swift expert, but was just browsing around today trying to compare how you might do it in C++ or other languages. (cb) { cb(null, "one");} is possible, but that means it's a function template, not a function. You can get this syntax by making the callbacks template arguments, which means they must be known at compile-time. Is that OK with you or do you need the possibility to define the callbacks at runtime? The goal was to do as much as possible at compile time. Could you elaborate on this a bit. I guess the answer is, yes, it's okay with me. I don't get it: none of your callbacks have a return type per se: they all return 'void'. Do you want callbacks that really return something? Yes, the callbacks at step0 should output a type in the result which is specific to step0, and then that type should be fed in as a secondary parameter to step1. I didn't get that far, as I was already stuck. You can test if func[0] takes one or two arguments: import std.traits: isCallable, ReturnType; static if (isCallable!(Func[0]) && ReturnType!(Func[0]).length == 1) Ah, yes, that sounds reasonable, I already thought something like that may do the trick. thanks for your patience!
Re: Momentary Eh?! for a Dynamic Language Programmmer. Tuples vs Arrays. Just rambling.
On Monday, 23 June 2014 at 22:11:57 UTC, John Carter wrote: On Monday, 23 June 2014 at 21:49:29 UTC, Ary Borenszweig wrote: Union types are very common (I use them every day), and IMHO it's very nice to have them included in the language (either built-in or as a library solution). As a library solution I would do something like this: Union!(int, string)[] elements; Hmm. egrepping through /usr/include/dmd fails to find '\bUnion\b', are you sure you don't mean Algebraic? You're looking for std.variant.Algebraic and std.typecons.Tuple. Tuple is actually a library-defined struct, with no compiler magic. The tuple situation in D is a bit weird; there are compiler tuples (which you don't need to worry about in this case), and library tuples, i.e., std.typecons.Tuple. There's also at least 1 other kind of special tuple, but you should hardly ever need to deal with that. For most cases, just use std.typecons.Tuple. Here's a few simple examples: import std.typecons: Tuple; Tuple!(string, File[]) getDirListing(string dir) { //... } //Even better alias DirListing = Tuple!(string, File[]); DirListing getDirListing(string dir) { //... } //Adding a string after a tuple member names that field alias DirListing = Tuple!(string, "dir", File[], "files"); void main() { //These functions for operating on files are just made up enum directory = "C:\SomeDir"; auto dirListing = getDirListing(directory); foreach (i, file; dirListing.files) { file.setName("%s-%s".format(dirListing.name, i); } }
Re: very short pipeShell program
Ali, of course, is right. The only thing I'd add is for a Windowsy programmer (unless you have cygwin installed) you probably want something like "cmd.exe" instead of bash.
Re: Momentary Eh?! for a Dynamic Language Programmmer. Tuples vs Arrays. Just rambling.
On Monday, 23 June 2014 at 21:49:29 UTC, Ary Borenszweig wrote: Union types are very common (I use them every day), and IMHO it's very nice to have them included in the language (either built-in or as a library solution). As a library solution I would do something like this: Union!(int, string)[] elements; Hmm. egrepping through /usr/include/dmd fails to find '\bUnion\b', are you sure you don't mean Algebraic?
Re: Momentary Eh?! for a Dynamic Language Programmmer. Tuples vs Arrays. Just rambling.
On Monday, 23 June 2014 at 21:26:19 UTC, Chris Williams wrote: More likely what you want are variants: Hmm. Interesting. Yes, Variant and VariantArray are much closer to the dynamic language semantics... But the interesting thing is Tuple is much closer to "What I Mean" when I create these things. I probably should used Rubies http://ruby-doc.org/core-2.0/Struct.html but apart from naming the elements it gives me nothing beyond more keystrokes to enter. Tuple is very similar, but also grants type safety.
Re: Momentary Eh?! for a Dynamic Language Programmmer. Tuples vs Arrays. Just rambling.
Ary Borenszweig: As a library solution I would do something like this: Union!(int, string)[] elements; elements ~= 1; elements ~= "hello"; Take a look at Algebraic in Phobos. Bye, bearophile
Re: Momentary Eh?! for a Dynamic Language Programmmer. Tuples vs Arrays. Just rambling.
On 6/23/14, 6:18 PM, John Carter wrote: I guess between perl and Ruby and Scheme etc. I got used to creating hybrid containers Want a pair of [string, fileList]? Just make an Array with two items, one a string, one and array of strings. Done. D barfed... leaving me momentarily stunned... then Oh Yes, type safety, Tuple's are the answer where Tuples where Tuples... Eventually found http://dlang.org/tuple.html and more specifically the somewhat unexpectedly named http://dlang.org/phobos/std_typecons.html and off I went... I do have a personal design guideline of when you adding too much behaviour to a heterocontainer, refactor into a class. But I guess I have never realised how often I do casually create heterogenous containers Just rambling and musing. Union types are very common (I use them every day), and IMHO it's very nice to have them included in the language (either built-in or as a library solution). As a library solution I would do something like this: Union!(int, string)[] elements; elements ~= 1; elements ~= "hello"; auto x = elements[0].cast!(int); // etc. The difference with Variant is that (I think) Variant allows any kind of type to be inserted into it, but for a Union you are just limited to a set of types. For example, the following would be a compile-time error: elements[0].cast!(float); // error, Union!(int, string) doesn't include float As a built-in way the way to use it would be much nicer, but of course it involves too many changes for that to happen...
Re: Momentary Eh?! for a Dynamic Language Programmmer. Tuples vs Arrays. Just rambling.
On Monday, 23 June 2014 at 21:18:39 UTC, John Carter wrote: I guess between perl and Ruby and Scheme etc. I got used to creating hybrid containers Want a pair of [string, fileList]? Just make an Array with two items, one a string, one and array of strings. Done. D barfed... leaving me momentarily stunned... then Oh Yes, type safety, Tuple's are the answer where Tuples where Tuples... Eventually found http://dlang.org/tuple.html and more specifically the somewhat unexpectedly named http://dlang.org/phobos/std_typecons.html and off I went... I do have a personal design guideline of when you adding too much behaviour to a heterocontainer, refactor into a class. But I guess I have never realised how often I do casually create heterogenous containers Just rambling and musing. More likely what you want are variants: http://dlang.org/library/std/variant/variantArray.html http://dlang.org/library/std/variant.html Tuples can hold multiple types, but they're only available during compile time.
Momentary Eh?! for a Dynamic Language Programmmer. Tuples vs Arrays. Just rambling.
I guess between perl and Ruby and Scheme etc. I got used to creating hybrid containers Want a pair of [string, fileList]? Just make an Array with two items, one a string, one and array of strings. Done. D barfed... leaving me momentarily stunned... then Oh Yes, type safety, Tuple's are the answer where Tuples where Tuples... Eventually found http://dlang.org/tuple.html and more specifically the somewhat unexpectedly named http://dlang.org/phobos/std_typecons.html and off I went... I do have a personal design guideline of when you adding too much behaviour to a heterocontainer, refactor into a class. But I guess I have never realised how often I do casually create heterogenous containers Just rambling and musing.
Re: Trying to reproduce Node.js async waterfall pattern.. (Meta-programming)
On Mon, Jun 23, 2014 at 9:39 PM, Christian Beaumont via Digitalmars-d-learn wrote: > Each function is given a callback, that when called, steps the waterfall > forward on to the next function to process. If an error is passed to the > callback (instead of null), then the waterfall stops processing and calls > the final callback at the end of the chain. Just to be sure: whether or not an error is passed to a callback, the final callback is always called? I mean, the last callback could also be called *only when something fails*, a bit like a default case in a switch, or an error-handling routine. > 1) I can't see any way to get the compiler to deduce the type of "Funcs...". What do you mean? The compiler does deduce the type of Funcs. > I had an urge to somehow specialize the variadic "Funcs..." but I couldn't > figure out any syntax to do that. What do you mean by 'specialize'? > Well, because of that, I have to > repeatedly say (Callback cb) instead of (cb). (cb) { cb(null, "one");} is possible, but that means it's a function template, not a function. You can get this syntax by making the callbacks template arguments, which means they must be known at compile-time. Is that OK with you or do you need the possibility to define the callbacks at runtime? > 2) I can't see a path to flow the output type of the previous callback to > the input "TLastResult" for the next... so it's stuck on "string" :( I don't get it: none of your callbacks have a return type per se: they all return 'void'. Do you want callbacks that really return something? > 3) I had to use a specialization to deal with the "head" case; (the first > function doesn't have an input from a previous result). Minor, but niggly. You can test if func[0] takes one or two arguments: import std.traits: isCallable, ReturnType; static if (isCallable!(Func[0]) && ReturnType!(Func[0]).length == 1)
Trying to reproduce Node.js async waterfall pattern.. (Meta-programming)
Hi, I just started learning D, and thought I'd throw myself in at the deep end with some meta-programming, trying to write the equivalent of the commonly used, async waterfall, and also, because I'd like to use it... If you aren't familiar with it, waterfall is a function that is passed a sequence of functions as its arguments that are to be executed in order... (it's a pattern for async programming). Here is an example in Node.js... waterfall( function(asyncCallback){ asyncCallback(null, "one"); }, function(lastResult, asyncCallback){ // lastResult equals "one" asyncCallback(null, "two"); }, function(lastResult, asyncCallback){ // lastResult equals "two" asyncCallback(null, "done"); } , // final callback function (error, finalResult) { // result equals "done" } ); Each function is given a callback, that when called, steps the waterfall forward on to the next function to process. If an error is passed to the callback (instead of null), then the waterfall stops processing and calls the final callback at the end of the chain. This is how I have it implemented so far, but as you can see, there are some issues... import std.stdio; import std.conv; import std.exception; alias Callback = void delegate(Exception error, string result); alias AsyncFunc = void function(Callback cb); static Waterfall(TLastResult, Funcs...)(Funcs funcs, Callback finalCallback, TLastResult lastResult) { static if (funcs.length) { auto cb = (Exception error, string result) { if (error is null) Waterfall(funcs[1 .. $], finalCallback, result); else finalCallback(error, result); }; funcs[0](cb); } else finalCallback(null, lastResult); } static Waterfall(Funcs...)(Funcs funcs, Callback finalCallback) { static if (funcs.length) { auto cb = (Exception error, string result) { if (error is null) Waterfall(funcs[1 .. $], finalCallback, result); else finalCallback(error, result); }; funcs[0](cb); } else finalCallback(null, lastResult); } void main() { Waterfall( (Callback cb) { writeln("fn0"); cb(null, "one"); }, (Callback cb) { writeln("fn1"); cb(null, "two"); }, // (Callback cb) { writeln("fnError"); cb(new Exception("Bad joojoo"), "two"); }, (Callback cb) { writeln("fn2"); cb(null, "done"); }, (Exception error, string result) { if (error !is null) writeln("Error = " ~ error.to!string); if (result !is null) writeln("Result = " ~ result.to!string); } ); } 1) I can't see any way to get the compiler to deduce the type of "Funcs...". I had an urge to somehow specialize the variadic "Funcs..." but I couldn't figure out any syntax to do that. Well, because of that, I have to repeatedly say (Callback cb) instead of (cb). 2) I can't see a path to flow the output type of the previous callback to the input "TLastResult" for the next... so it's stuck on "string" :( 3) I had to use a specialization to deal with the "head" case; (the first function doesn't have an input from a previous result). Minor, but niggly. Any input on how to proceed would be great! thanks! Christian BTW, you can read more about async-waterfall here... https://www.npmjs.org/package/async-waterfall
Re: Contributing to D language
A lot of developers will say thanks if you help with developing DGUI https://bitbucket.org/dgui/dgui/ D very need native and easy to use GUI lib...
Re: Passing around a list of differently typed functions
On Mon, 23 Jun 2014 14:30:12 -0400, Ali Çehreli wrote: On 06/22/2014 11:32 PM, FreeSlave wrote:> On Monday, 23 June 2014 at 01:16:49 UTC, Evan Davis wrote: >> As the subject says, I would like to pass around an array of >> functions. The trick is, that the functions have different type >> signatures. Is there a way to put the two functions >> >> int foo(int a, int b); >> bool bar(bool a, bool b); >> >> into one array, that I can pass around and cast as necessary? >> >> Thanks, Evan > > You can pass them as pointers, for example cast to void*. But you still > need correct signature to cast pointer to actual type before call function. In C and C++, void* is for data pointers only. As function pointers are a different kind of beast, casting to and from void* is undefined behavior. (Note: It works on all common platforms.) Wow, really? That is strange. I wonder whether D has any decision on that. I would hope it's defined. A pointer is a pointer. -Steve
Re: Passing around a list of differently typed functions
On 06/22/2014 11:32 PM, FreeSlave wrote:> On Monday, 23 June 2014 at 01:16:49 UTC, Evan Davis wrote: >> As the subject says, I would like to pass around an array of >> functions. The trick is, that the functions have different type >> signatures. Is there a way to put the two functions >> >> int foo(int a, int b); >> bool bar(bool a, bool b); >> >> into one array, that I can pass around and cast as necessary? >> >> Thanks, Evan > > You can pass them as pointers, for example cast to void*. But you still > need correct signature to cast pointer to actual type before call function. In C and C++, void* is for data pointers only. As function pointers are a different kind of beast, casting to and from void* is undefined behavior. (Note: It works on all common platforms.) I wonder whether D has any decision on that. Ali
Re: Question about iteger literals
On Sun, 22 Jun 2014 08:23:45 -0400, Uranuz wrote: If these rules are not so clear and have some exceptions (but I don't understand why they are needed) then some documentation needed about this. See integer promotion rules: http://dlang.org/type.html#Integer%20Promotions And the section below it. -Steve
Re: Contributing to D language
On Monday, 23 June 2014 at 16:43:31 UTC, Mike wrote: I wish I could help with the development of D (either the compiler or std library). Is there a TODO list kept somewhere? Neither Phobos nor DMD have an `issues` page on Github.. I found this http://wiki.dlang.org/Review_Queue but it's kind of short. Best regards, Mike issues.dlang.org is the official bug tracker and has plenty to work through.
Re: Contributing to D language
On Mon, Jun 23, 2014 at 04:43:30PM +, Mike via Digitalmars-d-learn wrote: > I wish I could help with the development of D (either the compiler or > std library). > > Is there a TODO list kept somewhere? Neither Phobos nor DMD have an > `issues` page on Github.. [...] http://issues.dlang.org/ See also: http://wiki.dlang.org/Get_involved T -- To provoke is to call someone stupid; to argue is to call each other stupid.
Contributing to D language
I wish I could help with the development of D (either the compiler or std library). Is there a TODO list kept somewhere? Neither Phobos nor DMD have an `issues` page on Github.. I found this http://wiki.dlang.org/Review_Queue but it's kind of short. Best regards, Mike
Re: Why does this work?
h_zet: Why does this work? Or it is a bug? When you play a little with this code it's easy to see _error_ that should not appear. So there's surely something worth reporting as bug, but I don't yet know what. Bye, bearophile
Re: Why does this work?
On Monday, 23 June 2014 at 09:29:15 UTC, Mason McGill wrote: Strange behavior, indeed. It took me a minute, but I think I know what's going on, and I'm pretty sure it's a bug. D recently introduced a short syntax for function-like templates: enum a(b) = "some_value"; It looks like this also (sort of) works with other qualifiers, which I believe it shouldn't. Here's a minimal example that might be good to put in a bug report: void main() { enum a(x) = "some_value"; // Good. auto b(x) = "some_value"; // Huh? // This also works for `const`, `static`, etc. } It looks like I'm mistaken. Variable templates are supposed to exist. Please ignore the previous post.
Re: Why does this work?
On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote: import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug? Strange behavior, indeed. It took me a minute, but I think I know what's going on, and I'm pretty sure it's a bug. D recently introduced a short syntax for function-like templates: enum a(b) = "some_value"; It looks like this also (sort of) works with other qualifiers, which I believe it shouldn't. Here's a minimal example that might be good to put in a bug report: void main() { enum a(x) = "some_value"; // Good. auto b(x) = "some_value"; // Huh? // This also works for `const`, `static`, etc. }
Re: Why does this work?
On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote: import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug? You declared a variable template named "tuple" (with unused type parameters a, b) on that line. http://dlang.org/template.html#variable-template I think this is very confusable syntax... void main() { auto tuple(a, b) = foo2(1); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(1, true)" tuple!(int, int) = foo2(20); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(20, true)" }
Re: Why does this work?
On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote: import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug? Looks grammaticallyu correct: R type is guessed/infered from the parameter
Why does this work?
import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug?
Re: Passing around a list of differently typed functions
On 23/06/2014 8:19 AM, Bienlein wrote: On Monday, 23 June 2014 at 01:16:49 UTC, Evan Davis wrote: As the subject says, I would like to pass around an array of functions. The trick is, that the functions have different type signatures. Is there a way to put the two functions int foo(int a, int b); bool bar(bool a, bool b); into one array, that I can pass around and cast as necessary? Thanks, Evan Have functions in the array without parpameters that call the function with the applicable parameters, e.g. int foo(int a, int b) or bool bar(bool a, bool b). That doesn't address the problem of the different return types (int and bool). So change the return type to void and return the value as an inout parameter. You could convert your functions to return via an out parameter (either manually or with template magic) then have an array of same-signatured closures that can call any function. A...
Unexpected OPTLINK Termination while building ddb and gtkd
My dub.json : ``` { "name": "ddb_test", "description": "A minimal D application.", "dependencies": { "gtk-d:gtkd": ">=2.3.3", "ddb": ">=0.2.1" } } ``` My source (source/app.d): ``` import ddb.postgres; import gtk.Window; int main(string[] argv) { return 0; } ``` On linux works, on WinXp and Win7 64bit I get following: ``` $ dub build --force Building ddb 0.2.1 configuration "library", build type debug. Running dmd... Building gtk-d:gtkd 2.3.3 configuration "library", build type debug. Running dmd... Building ddb_test ~master configuration "application", build type debug. Compiling using dmd... Linking... ``` I get a message: Unexpected OPTLINK Termination a t EIP=0040F5Ba If I comment just a row on app.d: ``` import ddb.postgres; // import gtk.Window; <= int main(string[] argv) { return 0; } ``` it works! Thank you
Re: Passing around a list of differently typed functions
On Monday, 23 June 2014 at 01:16:49 UTC, Evan Davis wrote: As the subject says, I would like to pass around an array of functions. The trick is, that the functions have different type signatures. Is there a way to put the two functions int foo(int a, int b); bool bar(bool a, bool b); into one array, that I can pass around and cast as necessary? Thanks, Evan Have functions in the array without parpameters that call the function with the applicable parameters, e.g. int foo(int a, int b) or bool bar(bool a, bool b). That doesn't address the problem of the different return types (int and bool). So change the return type to void and return the value as an inout parameter.