July 07, 2013
On Sun, 07 Jul 2013 15:23:03 +0200
Artur Skawina <art.08.09@gmail.com> wrote:
> 
> template allSatisfy(alias F, T...) {
>    enum allSatisfy = {
>       foreach (E; T)
>          if (!F!E)
>             return false;
>       return true;
>    }();
> }
> 
> // And no, it isn't perfect. But not /that/ much is missing.
> // It's the more complex cases that would benefit from more meta
> features.
> 

It'd be even nicer when/if this becomes possible (I *think* I remember Walter saying it was planned...):

enum allSatisfy(alias F, T...) = {
   foreach (E; T)
      if (!F!E)
         return false;
   return true;
}();

July 07, 2013
On Sunday, 7 July 2013 at 12:27:02 UTC, Peter Alexander wrote:
> On Sunday, 7 July 2013 at 03:03:03 UTC, Andrei Alexandrescu wrote:
>> Terrible. If you have conditionals, iteration, functions, and objects
>> in D's straight programming support, you should have conditionals,
>> iteration, functions, and objects in D's metalanguage.
>
> :-(
>
> template allSatisfy(alias F, T...)
> {
>     static if (T.length == 0)
>     {
>         enum allSatisfy = true;
>     }
>     else static if (T.length == 1)
>     {
>         enum allSatisfy = F!(T[0]);
>     }
>     else
>     {
>         enum allSatisfy =
>             allSatisfy!(F, T[ 0  .. $/2]) &&
>             allSatisfy!(F, T[$/2 ..  $ ]);
>     }
> }
>
> Still looks like half-assed functional programming to me.
>
> Where's the iteration? Why can't I write this?
>
> template allSatisfy(alias F, T...) {
>     foreach(t; T)
>         if (!F!(t))
>             return false;
>     return true;
> }
>
> (Those are rhetorical questions btw, before anyone links me to a D tutorial).
>
> We're almost there with CTFE, but CTFE can only run functions that could run at runtime. In a crazy world where types were first class objects, stuff like this would be feasible. Or perhaps we just need a compile-time metalanguage that allows things like this to be run with CTFE?

Static foreach would help, at least in my case: http://forum.dlang.org/post/ebvrirxozwllqjbffwzh@forum.dlang.org

Sadly, there are more important issues (shared libs, 83 PRs in dmd) so this will probably have to wait for better times.
July 07, 2013
On 7/7/2013 5:09 AM, Andrej Mitrovic wrote:
> On 7/7/13, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
>> While doing some unrelated research I stumbled upon my very first email
>> to Walter, dated April 26, 2004.
>
> That's a cool teaser, but how did the discussion continue? :)
>

Generally along these lines:

"And you, Scarecrow, have the effrontery to ask for a brain, you billowing bale of bovine fodder!"
July 08, 2013
On Sunday, 7 July 2013 at 03:03:03 UTC, Andrei Alexandrescu wrote:
>> * And if you really want to go meta, define metacode that can take
>> an AST node as a parameter and can visit the AST and figure out what
>> each node is. That would allow things such as loop fusion and other
>> advanced stuff. But for now, let's leave those aside.
>>

hoooooooo :P
July 08, 2013
On Sunday, 7 July 2013 at 22:03:17 UTC, Walter Bright wrote:
> On 7/7/2013 5:09 AM, Andrej Mitrovic wrote:
>> That's a cool teaser, but how did the discussion continue? :)
>
> Generally along these lines:
>
> "And you, Scarecrow, have the effrontery to ask for a brain, you billowing bale of bovine fodder!"


What happened when Toto pulled back the curtain? :-)
July 09, 2013
On Sunday, 7 July 2013 at 12:27:02 UTC, Peter Alexander wrote:
> :-(
>
> template allSatisfy(alias F, T...)
> {
>     static if (T.length == 0)
>     {
>         enum allSatisfy = true;
>     }
>     else static if (T.length == 1)
>     {
>         enum allSatisfy = F!(T[0]);
>     }
>     else
>     {
>         enum allSatisfy =
>             allSatisfy!(F, T[ 0  .. $/2]) &&
>             allSatisfy!(F, T[$/2 ..  $ ]);
>     }
> }

It's deplhi-style
http://www.freepascal.org/docs-html/ref/refse77.html#x155-16500014.3
1 2
Next ›   Last »