www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - My presentation at Oscon last Thursday

reply Walter Bright <newshound2 digitalmars.com> writes:
http://assets.en.oreilly.com/1/event/45/The%20D%20Programming%20Language%20Presentation.pdf
Jul 24 2010
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Walter Bright:
 http://assets.en.oreilly.com/1/event/45/The%20D%20Programming%20Language%20Presentation.pdf

I'm currently reading many other PDF/PPT from other conferences too. In your RAII example you are doing something that's scary, mixing C heap allocations with D GC heap allocations with C free. This is a program based on your code: import std.c.stdlib: malloc, free; struct Buffer { this(size_t s) { buf = malloc(s)[0 .. s]; } this(this) { buf = buf.dup; } ~this() { free(buf.ptr); } void[] buf; } void main() { auto b1 = Buffer(100); auto b2 = b1; } But I think this is better: import std.c.stdlib: malloc, free; struct Buffer { this(size_t s) { buf = malloc(s)[0 .. s]; } this(this) { void* newbuf = malloc(buf.length); newbuf[0 .. buf.length] = buf[]; buf = newbuf[0 .. buf.length]; } ~this() { free(buf.ptr); } void[] buf; } void main() { auto b1 = Buffer(100); auto b2 = b1; } This is your example for the functional style: pure sum_of_squares  (immutable double[] a) {     auto sum = 0;     foreach (i; a)         sum += i * i;     return sum; } But I think this is better, the function name follows the D style page you have written and the 'sum' is not an integer value: pure double sumOfSquares(double[] arr) { double sum = 0.0; foreach (item; arr) sum += item * item; return sum; } For a functional-style piece of code I'd like to write: import std.algorithm: reduce; pure double sumOfSquares2(double[] arr) { return reduce!q{a + b * b}(0.0, arr); } But it seems reduce isn't pure yet... The page on compilers seems to show that both DMD and LDC are able to compile the given examples, but LDC is mostly D1 only for now... Bye, bearophile
Jul 24 2010
parent Walter Bright <newshound2 digitalmars.com> writes:
bearophile wrote:
 In your RAII example you are doing something that's scary, mixing C heap
 allocations with D GC heap allocations with C free.

You're right, the buf.dup code is not only scary, it's dead wrong. My screw up. Derp, derp.
Jul 24 2010
prev sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
The slides for another talk,  "Build Your Own Contributors (One Part at a
Time)", by Denise Paolucci (Dreamwidth Studios), Mark Smith (Dreamwidth
Studios):

http://assets.en.oreilly.com/1/event/45/Build%20Your%20Own%20Contributors%20_One%20Part%20at%20a%20Time_%20Presentation%201.ppt

Some of the things it says seems good to improve the D community management.

Bye,
bearophile
Jul 24 2010
parent bearophile <bearophileHUGS lycos.com> writes:
Nice slides, "High Wizardry in the Land of Scala Presentation" by Daniel
Spiewak, in pages 4-36 he shows Higher-Kinds and Typeclasses, that can be
interesting for D programmers too:

http://assets.en.oreilly.com/1/event/45/High%20Wizardry%20in%20the%20Land%20of%20Scala%20Presentation.pdf

Bye,
bearophile
Jul 25 2010