by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Jarl André Hübenthal
    @jarlah
    import std.stdio;
    import std.conv;
    
    void main() {
        auto hello(string name, int age) {
            return "Hi, " ~ name ~ "! Your age is " ~ to!string(age);    
        }
    
        auto helloJarl = function (string delegate(string name, int age) f) {
            return f("Jarl", 100);
        };
    
        writeln(helloJarl(&hello));
    }
    i wonder .. is this the cleanest way to do it?
    i mean .. i have to explicitely define the params in the delegate?
    the functions are not really first class citizens .. they have to sent as pointers
    and thus D cant be a fully functional language in that definition
    Ilya Yaroshenko
    @9il
    I don't understand what are you talking about. Anyway, functional D is about templates and aliases. function pointers and delegatess are used for OO programming.
    Jarl André Hübenthal
    @jarlah
    sorry .. i have looked at and used d for hobby stuff over the 5 past years.. .. but following my growing like for functional programming languages like Haskell and Scala (semi functional) .. I am just trying to grasp the straws thats left in what connects me to dlang. . i think honestly that to like dlang youll have to appreciate working with low level languages .. i think im just another one of those high level programmers :) that for some reason believe that dlang with its similarities to high level languages can be used functionally .. which it cant .. unless you give me an example .. i am trying to understand functional programming in dlang
    Jarl André Hübenthal
    @jarlah
    http://beza1e1.tuxen.de/articles/functional_D.html ... there are at least some aspects of FP in D
    @9il delegates dont have to be used for OO
    Jarl André Hübenthal
    @jarlah
    figured it out:
    auto hello = (string name, int age) => "Hi, " ~ name ~ "! Your age is " ~ to!string(age);    
    auto helloJarl = (string function(string name, int age) f) => f("Jarl", 100);
    writeln(helloJarl(hello));
    auto helloPeter = (string function(string name, int age) f) => f("Peter", 50);
    writeln(helloPeter(hello));
    this is excactly as i am used to program with functions as first class citizens in real function oriented languages :) ... except for the part where D is a bit verbose
    Jarl André Hübenthal
    @jarlah
    woho :) with map, reduce, filter, each and fold in D along with lambda expressions and pointer less style of passing things around .. yey .. this seems to be a very good language for me .. much more simpler than haskell .. and both d and haskell is native languages... and i dont have to think about burritos ...
    Jarl André Hübenthal
    @jarlah

    concrete question .. vibe.d expects a certain type of object passed to listenHTTP... this for ex works ...

    listenHTTP(settings, (req, res) => res.writeBody("Hello, World!"));

    while this doesnt work:

    listenHTTP(settings, (req, res) => {
        res.writeBody("Hello, World!");
    });

    getting error:

    source/app.d(8,12): Error: None of the overloads of 'listenHTTP' are callable using argument types (HTTPServerSettings, void), candidates are:
    ../../.dub/packages/vibe-d-0.7.23/source/vibe/http/server.d(71,6):        vibe.http.server.listenHTTP(HTTPServerSettings settings, void delegate(HTTPServerRequest req, HTTPServerResponse res) request_handler)
    ../../.dub/packages/vibe-d-0.7.23/source/vibe/http/server.d(95,6):        vibe.http.server.listenHTTP(HTTPServerSettings settings, void function(HTTPServerRequest req, HTTPServerResponse res) request_handler)
    ../../.dub/packages/vibe-d-0.7.23/source/vibe/http/server.d(100,6):        vibe.http.server.listenHTTP(HTTPServerSettings settings, HTTPServerRequestHandler request_handler)
    why is that?
    is multiline lambda different type of object than one liner lambda?
    can use forums .. but i am on gitter .. dont like hacking on web forums
    John Colvin
    @John-Colvin
    (someArgs) => someExpression is a llambda, equivalent to (someArgs){ return someExpression; }. What you've written is a lambda that returns a delegate.
    Jarl André Hübenthal
    @jarlah
    Aha! Thanks! Then it was not typo but wrong type. ...but to be able to return delegate is nice
    I posted to forum btw and got help but your answer was the most concrete noe
    Jarl André Hübenthal
    @jarlah
    Just thinking about coding native apps with almost java/scala like syntax ....without classes. ... cool stuff
    Ilya Yaroshenko
    @9il
    @jarlah I have never use delegate and function keywords when I create idiomatic functional D code. They are used in D for OOP libraries and classes. If you open code for things likemapand reduce then you will see templates, aliases, struct Range {...}.
    Swoorup Joshi
    @Swoorup
    where is the D repl
    John Colvin
    @John-Colvin
    Daniil Kolesnichenko
    @KolesnichenkoDS
    hello everyone
    is there a way to build D projects without GC with DUB?
    LDC supports -nogc option and DMD has -vgc, wich doesn't actually disable GC, but prints all GC allocations
    but DUB seems to support only options that all compilers have
    John Colvin
    @John-Colvin
    Just add @nogc to main and no GC allocations will be allowed
    Mihai Popescu
    @mihaipopescu

    The synopsis example from https://dlang.org/phobos/std_parallelism.html generates

    /Library/D/dmd/src/phobos/std/parallelism.d(2633): Error: function std.parallelism.TaskPool.reduce!"a + b".reduce!(MapResult!(getTerm, Result)).reduce cannot get frame pointer to D main

    Is this a known bug?

    Mihai Popescu
    @mihaipopescu
    dlblv
    @dlblv
    Is there a chat for DMD?
    David Nadlinger
    @klickverbot
    @dlblv: I don't think so – you can try #d on freenode or the mailing lists/forums
    dlblv
    @dlblv
    Yep, thanx
    matrixbot
    @matrixbot
    araspik Anybody thought about adding a subdir in Phobos which only includes compile-time code?
    Sebastian Wilzbach
    @wilzbach
    @matrixbot this gitter chat is not active. Try #d on IRC, #phobos on Slack or the NG.
    To answer you question: well the cool part about D is that almost everything can be compile-time code (even almost everything in std.algorithm), so I'm assuming that you are referring to std.meta, std.traits and friends.
    Well, there's no real benefit of renaming/reshuffling code, is there? And it would break a lot of code.
    matrixbot
    @matrixbot
    araspik Cool, thanks!
    BTW: I meant importing from the normal sources. (eg import std.range: isInputRange, ...)
    I never realised that CTFE got that far :)
    Sebastian Wilzbach
    @wilzbach
    Kiti-nomad
    @kiti-nomad
    hello
    大家好
    matrixbot
    @matrixbot
    dejlek I am connected to here via matrix.org :)
    matrixbot
    @matrixbot
    dejlek Anyone here?
    vitaliy_rybalka yeah!
    dejlek Cool, at least I know now that Matrix works
    dejlek :D
    vitaliy_rybalka I'd like to use it more. Talked with Matrix people from London at the PyConWeb'19 in Munich
    Kiti-nomad
    @kiti-nomad
    诈尸啊
    Lance Add
    @LanceAdd
    @AmberSaber 知道哪有中文群吗,这群都没人活动的啊
    Kiti-nomad
    @kiti-nomad
    QQ群,有很多
    还有个国内唯一使用D语言的项目的群
    Kiti-nomad
    @kiti-nomad
    根本就不用活跃
    大家都是在官网里的论坛里交流
    用项目交流