Re: cannot find source code for runtime library file 'object.d'
On Monday, 20 November 2023 at 07:50:22 UTC, thinkunix wrote: denis via Digitalmars-d-learn wrote: ``` $ zypper install dmd $ dmd main.d Error: cannot find source code for runtime library file 'object.d' dmd might not be correctly installed. Run 'dmd -man' for installation instructions. config file: /etc/dmd.conf I would say the package has files in the wrong locations. Try the binary from dlang.org: https://downloads.dlang.org/releases/2.x/2.105.3/dmd-2.105.3-0.openSUSE.x86_64.rpm I'm not familiar with zypper but I'll bet you can install it by: # zypper install ./dmd-2.105.3-0.openSUSE.x86_64.rpm On a RHEL-like distro, this works: # yum install ./pkgname.rpm ... scot Thank you Scot, I confirm that installing manually does the trick Regards Denis
Re: What is :-) ?
On Monday, 20 November 2023 at 16:47:13 UTC, Paul Backus wrote: You can put the `delegate` keyword in front of the function literal: ```d auto createCounter = delegate (int nextValue) => () => nextValue++; ``` This syntax is documented in the spec's section on [Function Literals][2] (look at the grammar box and the examples). [2]: https://dlang.org/spec/expression.html#function_literals Thaks Paul
Re: What is :-) ?
On Monday, 20 November 2023 at 16:32:22 UTC, evilrat wrote: ```d // this is a function returning a delegate auto createCounter(int nextValue) => auto delegate() => nextValue++; Thank you!!!. Compiler forces me to omit "auto" keyword ```d auto createCounter(int nextValue) => delegate () => nextValue++ ; ``` Explicit return must be specified after "delegate" keyword ```d auto createCounter(int nextValue) => delegate int () => nextValue++ ; ``` When declaring a type (variable or parameter) is when keywords order must be "inverted" ```d import std.stdio; int callWith10( int delegate (int) x) =>x(10); void main(){ int j=100; // Explicit writeln( callWith10( delegate int (int i)=>i+j ) ); // Inferred writeln( callWith10( i=>i+j ) ); // OMG writeln( ( i=>i+j ).callWith10 ); } ``` // this is a function returning a function auto createCounter(int nextValue) => auto function() => nextValue++; ``` I think this will not work, because nextValue is defined out of the returned function scope: you must return a closure (delegate). Thanks a lot evilrat!!! **From your answer (and other ones too) I have to say that...** * **D Closures rocks!!!** It is hard to find something so powerful in other natively compiled languages: **Heap + GC** has it's advantages. * **D offers nice syntax features**: you can declare arrow methods very similar to dart, or assign an arrow function/delegate to a variable like Javascript/Typescript lambdas.