Re: Pegged, From EBNF to PEG

2012-03-17 Thread Philippe Sigaud
On Wed, Mar 14, 2012 at 10:48, Dmitry Olshansky dmitry.o...@gmail.com wrote:

 That's one of the caveats on PEG. That and greedy operators.

 'a*a' never succeeds because 'a*' consumes all the available a's.


 Hey, wait, I thought there has to be backtrack here, i.e. when second 'a'
 finally fails?

PEG only do local backtracking in 'or' choices, not in sequences. I
think that's because the original author was dealing with packrat
parsing and its O(input-size) guarantee.

I remember trying compile-time backtracking in another similar library
in D 1-2 years ago and getting lots of pb. I might add that in Pegged,
but I don't know the consequences. How do you do that in std.regex?

(nice article btw, I learnt some about regexes)


Re: Pegged: Syntax Highlighting

2012-03-17 Thread Philippe Sigaud
On Wed, Mar 14, 2012 at 21:03, Andrej Mitrovic
andrej.mitrov...@gmail.com wrote:

 how would one use a parser like Pegged for syntax
 highlighting?

 Ok, typically one would use a lexer and not a parser. But using a
 parser might be more interesting for creating more complex syntax
 highlighting. :)


 Actually I think I can use the new ddmd-clean port for just this
 purpose. Sorry for the noise.

Sorry for the late reply, I was away for a few days, in a Net-forsaken place ;)

If ddmd-clean is OK for you, that's cool. Keep us informed how that went.
If you want to use Pegged, you'd need to enter the entire D grammar to
get a correct parse tree.
I just finished writing it, but I'm afraid to try and compile it :)
It's one huge monster.


Re: Pegged, From EBNF to PEG

2012-03-17 Thread Dmitry Olshansky

On 17.03.2012 10:59, Philippe Sigaud wrote:

On Wed, Mar 14, 2012 at 10:48, Dmitry Olshanskydmitry.o...@gmail.com  wrote:


That's one of the caveats on PEG. That and greedy operators.

'a*a' never succeeds because 'a*' consumes all the available a's.



Hey, wait, I thought there has to be backtrack here, i.e. when second 'a'
finally fails?


PEG only do local backtracking in 'or' choices, not in sequences. I
think that's because the original author was dealing with packrat
parsing and its O(input-size) guarantee.



Ok, let's agree on fact that semantically
a* is :
As - a As / a

and a*? is this:
As - a / a As

Now that's local ;)



I remember trying compile-time backtracking in another similar library
in D 1-2 years ago and getting lots of pb. I might add that in Pegged,
but I don't know the consequences. How do you do that in std.regex?



There are two fundamental ways to get around the problem, the easiest
to implement is to use a stack to record a position in input + number of 
alternative/production (I call it a PC - program counter) every time 
there is a fork like that. Then when the current path ultimately fails 
pop stack, reset input and go over again until you either match or empty 
the stack. That's how to avoid dp recursion that happens here.


The problematic thing now is combinatorial explosion of
a* a* a*  //simplified, but you get the idea

The trick to avoid this sort of crap is to
1) agree that whatever matches first has higher priority (left-most 
match) that's a simple disambiguation rule.
2) record what positions + pc you place on stack e.g. use a set, or in 
fact, a bitmap to push every unique combination  (pc,index) only once.


Voila! Now you have a linear worst-case algorithm with (M*N) complexity 
where M is number of all possible PCs, and N is number of all possible 
indexes in input.


Now if we put aside all crap talk about mathematical purity and monads, 
and you name it, a packrat is essentially this, a dynamic programming 
trick applied to recursive top-down parsing. The trick could be extended 
even more to avoid extra checks on input characters, but the essence is 
this memoization.




(nice article btw, I learnt some about regexes)


Thanks, I hope it makes them more popular.
Might as well keep me busy fixing bugs :)

--
Dmitry Olshansky


Re: DUnit - class MyTest { mixin TestMixin; void testMethod1() {} void testMethod2() {}}

2012-03-17 Thread Marc P. Michel
On Monday, 20 February 2012 at 01:49:04 UTC, Juan Manuel Cabo 
wrote:
I thought I could do a better effort to describe why DUnit is 
so extraordinary,
for a native language, especially for those unfamiliar with 
xUnit frameworks


This is great stuff, thanks !

Anyway, I'm not fond of your examples; so here is a silly one 
from me :


http://lanael.free.fr/summertest.d.html




Re: Pegged: Syntax Highlighting

2012-03-17 Thread Extrawurst

On 17.03.2012 08:01, Philippe Sigaud wrote:

On Wed, Mar 14, 2012 at 21:03, Andrej Mitrovic
andrej.mitrov...@gmail.com  wrote:


how would one use a parser like Pegged for syntax
highlighting?


Ok, typically one would use a lexer and not a parser. But using a
parser might be more interesting for creating more complex syntax
highlighting. :)



Actually I think I can use the new ddmd-clean port for just this
purpose. Sorry for the noise.


Sorry for the late reply, I was away for a few days, in a Net-forsaken place ;)

If ddmd-clean is OK for you, that's cool. Keep us informed how that went.
If you want to use Pegged, you'd need to enter the entire D grammar to
get a correct parse tree.
I just finished writing it, but I'm afraid to try and compile it :)
It's one huge monster.


I want to use Pegged for that purpose. So go ahead an commit the D 
grammar ;)

Would be so awesome if Pegged would be able to parse D.

~Extrawurst


Re: Pegged, From EBNF to PEG

2012-03-17 Thread Philippe Sigaud
On Sat, Mar 17, 2012 at 10:09, Dmitry Olshansky dmitry.o...@gmail.com wrote:

 Ok, let's agree on fact that semantically
 a* is :
 As - a As / a

 and a*? is this:
 As - a / a As

 Now that's local ;)

It's local, yes. But the pb is with   Expr - A* B C D, when D fails.
PEG sequences don't backtrack.


 I remember trying compile-time backtracking in another similar library
 in D 1-2 years ago and getting lots of pb. I might add that in Pegged,
 but I don't know the consequences. How do you do that in std.regex?



 There are two fundamental ways to get around the problem
(snip)

Thanks for the explanations. Does std.regex implement this?


 Now if we put aside all crap talk about mathematical purity and monads, and
 you name it, a packrat is essentially this, a dynamic programming trick
 applied to recursive top-down parsing. The trick could be extended even more
 to avoid extra checks on input characters, but the essence is this
 memoization.

I plan to store indices anyway. I might add this in the future. A read
something on using PEGs to parse Java and C and there was no need to
do a complete memoization: storing the last parse result as a
temporary seemed to be enough.

 (nice article btw, I learnt some about regexes)


 Thanks, I hope it makes them more popular.
 Might as well keep me busy fixing bugs :)

As people said on Reddit, you should make more whooping sounds about
CT-regex. That was what wowed me and pushed me to tackle CT-parsing
again.


Re: Pegged: Syntax Highlighting

2012-03-17 Thread Extrawurst

On 17.03.2012 15:13, Philippe Sigaud wrote:

The D grammar is a 1000-line / hundreds of rules monster. I finished
writing it and am now crushing bugs.


Any ETA when u gonna commit it for the public ? Wouldn't mind getting my 
hands dirty on it and looking for bugs too ;)


Re: Pegged, From EBNF to PEG

2012-03-17 Thread Dmitry Olshansky

On 17.03.2012 18:11, Philippe Sigaud wrote:

On Sat, Mar 17, 2012 at 10:09, Dmitry Olshanskydmitry.o...@gmail.com  wrote:


Ok, let's agree on fact that semantically
a* is :
As- a As / a

and a*? is this:
As- a / a As

Now that's local ;)


It's local, yes. But the pb is with   Expr- A* B C D, when D fails.
PEG sequences don't backtrack.


I'd argue they do. As I see it as:
Expr - As B C D / B C D
As - A / A As
(or use an epsilon production for As, is it allowed in pegged ?)





I remember trying compile-time backtracking in another similar library
in D 1-2 years ago and getting lots of pb. I might add that in Pegged,
but I don't know the consequences. How do you do that in std.regex?




There are two fundamental ways to get around the problem

(snip)

Thanks for the explanations. Does std.regex implement this?



It does the second way that I haven't told about, and had hard time to 
implement in C-T :)
And the simple version of what I presented (i.e. stack stuff) is used 
in CT-regex and as fallback in R-T. The problem with doing a bitmap 
memoization is that regex often used to _search_ things in large inputs. 
Some compromise and/or thresholds have to be estimated and found.
Parsing on the contrary guaranties that the whole input is used or in 
error, hence bitmap is not wasted.





Now if we put aside all crap talk about mathematical purity and monads, and
you name it, a packrat is essentially this, a dynamic programming trick
applied to recursive top-down parsing. The trick could be extended even more
to avoid extra checks on input characters, but the essence is this
memoization.


I plan to store indices anyway. I might add this in the future. A read
something on using PEGs to parse Java and C and there was no need to
do a complete memoization: storing the last parse result as a
temporary seemed to be enough.



Well even straight no-memorization is somehow enough, it's just a way to 
ensure no extra work is done. C  Java are not much of backtracky grammars.



(nice article btw, I learnt some about regexes)



Thanks, I hope it makes them more popular.
Might as well keep me busy fixing bugs :)


As people said on Reddit, you should make more whooping sounds about
CT-regex. That was what wowed me and pushed me to tackle CT-parsing
again.


It's just I'm also well aware of how much luck it (still) takes to fly ;)
The asserts that compare C-T vs R-T go off too often for my taste, other 
then this the memory usage during compile is too high.
I recall once dmd had GC re-enabled for brief period, dmd used no more 
then ~64Mb doing real crazy ct-regex stuff.


OK, back to C-T parsing, I have one crazy idea that I can't get away 
from - add operator precedence grammar into the mix. From what I observe 
it should integrate into PEG smoothly. Then it would make 
military-grade hybrid that uses operator precedence parsing of 
expressions and the like. Few more tricks and it may beat some

existing parser generators.

See this post, where I tried to describe that idea early on:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.Darticle_id=159562

I might catch spare time to go about adding it myself, the only tricky 
thing is to embed plain semantic actions, as AST generation would be 
more or less the same.


--
Dmitry Olshansky


Re: It's official: The D Programming Language will participate to GSoC 2012!

2012-03-17 Thread Jacob Carlborg

On 2012-03-16 19:32, Steven Schveighoffer wrote:

On Fri, 16 Mar 2012 14:24:38 -0400, Andrei Alexandrescu
seewebsiteforem...@erdani.org wrote:


Just got the acceptance message. This is great news!

If you consider being a mentor, please apply as described in
http://dlang.org/gsoc2012.html. Thanks!


You really think Google summer of code is going to sponsor development
of iPhone compatibility? :) Not that I wouldn't welcome this with open
arms...


We'll see what happens. It can't hurt to have as an idea.

--
/Jacob Carlborg


Re: Pegged: Syntax Highlighting

2012-03-17 Thread Andrei Alexandrescu

On 3/17/12 9:13 AM, Philippe Sigaud wrote:

I want to use Pegged for that purpose. So go ahead an commit the D grammar
;)
Would be so awesome if Pegged would be able to parse D.

~Extrawurst


The D grammar is a 1000-line / hundreds of rules monster. I finished
writing it and am now crushing bugs.
God, that generates a 10_000 line module to parse it. I should
simplify the code generator somewhat.


Science is done. Welcome to implementation :o).

I can't say how excited I am about this direction. I have this vision of 
having a D grammar published on the website that is actually it, i.e. 
the same exact grammar is used by a validator that goes through all of 
our test suite. (The validator wouldn't do any semantic checking.) The 
parser generator _and_ the reference D grammar would be available in 
Phobos, so for anyone it would be dirt cheap to parse some D code and 
wander through the generated AST. The availability of a reference 
grammar and parser would be golden to a variety of D toolchain creators.


Just to gauge interest:

1. Would you consider submitting your work to Phobos?

2. Do you think your approach can generate parsers competitive with 
hand-written ones? If not, why?



Andrei


Re: Pegged, From EBNF to PEG

2012-03-17 Thread Philippe Sigaud
On Sat, Mar 17, 2012 at 15:48, Dmitry Olshansky dmitry.o...@gmail.com wrote:

 PEG sequences don't backtrack.


 I'd argue they do. As I see it as:
 Expr - As B C D / B C D
 As - A / A As

That's what people doing Regex-to-PEG translations do, yes. But it's
not the spontaneous behavior of A* B C D in PEG.

But that means I could add a switch to transform the expressions that way.


 (or use an epsilon production for As, is it allowed in pegged ?)

I called it 'Eps', it's a predefined parser that always matches and
consumes nothing.
I used the greek epsilon at the beginning (ε) but thought that many
people would shout at this :)


 OK, back to C-T parsing, I have one crazy idea that I can't get away from -
 add operator precedence grammar into the mix. From what I observe it should
 integrate into PEG smoothly. Then it would make military-grade hybrid that
 uses operator precedence parsing of expressions and the like. Few more
 tricks and it may beat some
 existing parser generators.

 See this post, where I tried to describe that idea early on:
 http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.Darticle_id=159562

I remember reading this. But I don't feel I'm up to it for now.


 I might catch spare time to go about adding it myself, the only tricky thing
 is to embed plain semantic actions, as AST generation would be more or less
 the same.

Cool!


Re: Pegged: Syntax Highlighting

2012-03-17 Thread Philippe Sigaud
On Sat, Mar 17, 2012 at 15:44, Extrawurst s...@extrawurst.org wrote:
 On 17.03.2012 15:13, Philippe Sigaud wrote:

 The D grammar is a 1000-line / hundreds of rules monster. I finished
 writing it and am now crushing bugs.


 Any ETA when u gonna commit it for the public ? Wouldn't mind getting my
 hands dirty on it and looking for bugs too ;)

I just pushed it on Github.

pegged/examples/dgrammar.d just contains the D grammar as a string.
pegged/examples/ddump.d is the generated parser family.

There are no more syntax bugs, Pegged accepts the string as a correct
grammar and DMD accepts to compile the resulting classes.
I tested the generated parser on microscopic D files and... it
sometimes works :)

I made many mistakes and typos while writing the grammar. I corrected
a few, but there are many more, without a doubt

I'll write a wiki page on how to generate the grammar anew, if need be.

Btw, the D grammar comes from the website (I didn't find the time to
compare it to the grammar Rainer uses for Mono-D), and its horribly
BNF-like: almost no + or * operators, etc. I tried to factor some
expressions and simplify some, but it could be a bit shorter (not
much, but still).


mysql tool

2012-03-17 Thread dnewbie
Hi D friends.

I'd like to share with you a little tool. It allows you to execute SQL 
statements in your MySQL database.
It displays the data in a nice data grid widget written by David Hillard.

I hope you like it.

Link
http://my.opera.com/run3/blog/2012/03/17/mysql-tool



Re: Pegged: Syntax Highlighting

2012-03-17 Thread Philippe Sigaud
On Sat, Mar 17, 2012 at 18:11, Andrei Alexandrescu
seewebsiteforem...@erdani.org wrote:

 The D grammar is a 1000-line / hundreds of rules monster. I finished
 writing it and am now crushing bugs.
 God, that generates a 10_000 line module to parse it. I should
 simplify the code generator somewhat.


 Science is done. Welcome to implementation :o).

Hey, it's only 3.000 lines now :) Coming from a thousand-lines
grammar, it's not that much an inflation.


 I can't say how excited I am about this direction. I have this vision of
 having a D grammar published on the website that is actually it, i.e. the
 same exact grammar is used by a validator that goes through all of our test
 suite. (The validator wouldn't do any semantic checking.) The parser
 generator _and_ the reference D grammar would be available in Phobos, so for
 anyone it would be dirt cheap to parse some D code and wander through the
 generated AST. The availability of a reference grammar and parser would be
 golden to a variety of D toolchain creators.

Indeed, but I fear the D grammar is a bit too complex to be easily
walked. Now that I read it, I realize that '1' is parsed as a
10-levels deep leaf!
Compared to lisp, it's... not in the same league, to say the least. I
will see to drastically simplify the parse tree.

Does anyone have experience with other languages similar to D and that
offer AST-walking? Doesn't C# have something like this?
(I'll have a look at Scala macros)

 Just to gauge interest:

 1. Would you consider submitting your work to Phobos?

Yes, of course. It's already Boost-licensed.
Seeing the review processes for other modules, it'd most certainly put
the code in great shape. But then, it's far from being submittable
right now.


 2. Do you think your approach can generate parsers competitive with
 hand-written ones? If not, why?

Right now, no, if only because I didn't take any step in making it
fast or in limiting its RAM consumption.
After applying some ideas I have, I don't know. There are many people
here that are parser-aware and could help make the code faster. But at
the core, to allow mutually recursive rules, the design use classes:

class A : someParserCombinationThatMayUseA { ... }

Which means A.parse (a static method) is just typeof(super).parse
(also static, and so on). Does that entail any crippling disadvantage
compared to hand-written parser?


Philippe


Re: Pegged: Syntax Highlighting

2012-03-17 Thread bls

On 03/17/2012 01:53 PM, Philippe Sigaud wrote:

Does anyone have experience with other languages similar to D and that
offer AST-walking? Doesn't C# have something like this?
(I'll have a look at Scala macros)



Hi Philippe.
Of course the visitor pattern comes in mind.

Eclipse (Java) uses a specialized visitor pattern  called hierarchical 
visitor pattern to traverse the AST.


The classic visitor pattern has the following disadvantages :

-- hierarchical navigation -- the traditional Visitor Pattern has no 
concept of depth. As a result, visitor cannot determine if one composite 
is within another composite or beside it.


-- conditional navigation -- the traditional Visitor Pattern does not 
allow branches to be skipped. As a result, visitor cannot stop, filter, 
or optimize traversal based on some condition.


Interesting stuff at :

http://c2.com/cgi/wiki?HierarchicalVisitorPattern
You'll find some implementation details at the bottom of the doc.
hth Bjoern


Re: D to Javascript converter (a hacked up dmd)

2012-03-17 Thread Adam D. Ruppe

This is still alive:

https://github.com/adamdruppe/dmd/tree/dtojs

Merging in DMD changes as they happen has been fairly
easy, so we have things like UFCS in there.

I'm pretty happy with the core setup, though it still
isn't finished. Enough of the D language works like
you expect that you can do a lot of things with it
naturally.

Thus, I've moved on to libraries. I previously
talked about the jslang and browser packages. These
provide zero-overhead, direct access to javascript
built-ins.

You can also use a good chunk of the real Phobos in
here if you want.


But now, I'm adding minimal overhead nicer libraries,
including a port of my dom.d, adopted to try to
cover some browser incompatibilities. (The browser
package, being zero overhead, makes no attempt at
this. It just provides the tools to DIY.)


The trick is though, doing it with as lean code as
possible. Here's my domtest.d:

import arsd.dom;
import browser.window;

void main() {
Element e = document.getElementById(cool);
e.addClass(sweet);
e.style = font-weight: bold;;
e.style.fontSize = 30px;
e.innerText = e.style;
window.alert(e.parentNode.tagName);
e.removeFromTree();
}


It generates about 2 kb of javascript, libraries
included, after you strip unused functions and
reduce the variable name length. (NOT gzipped!)

Let's talk about one line at a time:

Element e = document.getElementById(cool);

In browser.document, there are JSElement and JSDocument
classes defined. Here, though, I'm using a custom
type: Element.

The implementation for this uses zero overhead forwarding
to native methods, unless I override them, in which case
it is implemented as a free function.

Many functions are now mixin templates in browser.document
so I don't have to repeat them, even if changing types.

Using alias this, these are compatible with the native
types as well.


e.addClass(sweet);

Is a new function in class Element. It manipulates the
native className property and in the resulting .js file
is a free function.

e.style = font-weight: bold;;

The style object is defined in browser.document and has
a  long list of properties. It maps directly to native
code, but with one addition:

   alias cssText this;


style.cssText in Javascript is the attribute as a string.
In my dom.d, Element.style can be treated as a string or
a struct, and I wanted that here too.

alias this accomplishes that goal with zero overhead.
e.style = ; translates simply to e.style.cssText = ;

e.style.fontSize = 30px;

The property is a native one, nothing special here.

e.innerText = e.style;

innerText, while a property on some browsers, isn't present
on all of them.

Thus, class Element defines it itself. This generates a free
function (with a mangled D name, so no conflict) that is
called using D property syntax.

The generated code looks like this:
_D_mangled_innerText(e.style.cssText, e);



This is the general pattern I'll do for browser compatibility.
Use the real name in D, but let it implement as free functions
with mangled names.

window.alert(e.parentNode.tagName);


The browser.window module defines some things that are global
in JS, including alert(). e.parentNode returns an Element,
thanks to a mixin that can specialize on types with zero overhead.


tagName, while a native property, is actually a function here.
The reason is dom.d uses lowercase tag names, but Javascript
uses uppercase.

Thus, this is implemented:

@property string tagName() { return 
__js_this.tagName.toLowerCase(); }



and the above line calls a D function. Some overhead, but very
little.

e.removeFromTree();


Finally, this is just a regular function. I'm thinking about
changing it to UFCS though so it can check for null on e too.

(It does:

 if(parentNode) parentNode.removeChild(this);

the idea being to just ensure it isn't in the tree without
needing an external null check.

If this is null, it is also not in the tree, so its contract
is satisified anyway, so it might as well succeed. Currently,
though, it will not work since the Element invariant will
segfault it.)




But, there's a rundown of what I'm doing with libraries.
Beautiful D code, compatible implementations, minimal
overhead.


I'll be posting the library soon, and then this will
be sharable.


Re: Pegged: Syntax Highlighting

2012-03-17 Thread Andrei Alexandrescu

On 3/17/12 3:53 PM, Philippe Sigaud wrote:

On Sat, Mar 17, 2012 at 18:11, Andrei Alexandrescu
seewebsiteforem...@erdani.org  wrote:


The D grammar is a 1000-line / hundreds of rules monster. I finished
writing it and am now crushing bugs.
God, that generates a 10_000 line module to parse it. I should
simplify the code generator somewhat.



Science is done. Welcome to implementation :o).


Hey, it's only 3.000 lines now :) Coming from a thousand-lines
grammar, it's not that much an inflation.


That's quite promising.


Indeed, but I fear the D grammar is a bit too complex to be easily
walked. Now that I read it, I realize that '1' is parsed as a
10-levels deep leaf!
Compared to lisp, it's... not in the same league, to say the least. I
will see to drastically simplify the parse tree.


This is where custom directives for helping AST creation might help. 
Also, ANTLR solves that problem by allowing people to define tree 
walkers. They have much simpler grammars (heck, the hard job has already 
been done - no more ambiguities). At an extreme, languages such as ML 
are good at walking trees because they essentially embed a tree walker 
in their pattern matching grammar for function parameters.



Does anyone have experience with other languages similar to D and that
offer AST-walking? Doesn't C# have something like this?
(I'll have a look at Scala macros)


Heck, I just found this which destroys ANTLR's tree walkers:

http://www.antlr.org/article/1170602723163/treewalkers.html

Didn't read it yet, but clearly it's an opposing viewpoint and relevant 
to your work (don't forget to also read the article to which it's 
replying http://antlr.org/article/1100569809276/use.tree.grammars.tml).



1. Would you consider submitting your work to Phobos?


Yes, of course. It's already Boost-licensed.
Seeing the review processes for other modules, it'd most certainly put
the code in great shape. But then, it's far from being submittable
right now.


Let us know how we can help. This is an important project.


2. Do you think your approach can generate parsers competitive with
hand-written ones? If not, why?


Right now, no, if only because I didn't take any step in making it
fast or in limiting its RAM consumption.
After applying some ideas I have, I don't know. There are many people
here that are parser-aware and could help make the code faster. But at
the core, to allow mutually recursive rules, the design use classes:

class A : someParserCombinationThatMayUseA { ... }

Which means A.parse (a static method) is just typeof(super).parse
(also static, and so on). Does that entail any crippling disadvantage
compared to hand-written parser?


I'm not sure without seeing more code.


Andrei


Re: automated C++ binding generation.. Booost D, NO , Not us. SIMD is more important.

2012-03-17 Thread Gour
On Sat, 17 Mar 2012 02:29:26 +0100
Andrej Mitrovic andrej.mitrov...@gmail.com wrote:

 Sorry for the long wait. Turns out I was *extremely* wrong about this.
 Generating the D side turned out to be a hell of a lot more work then
 I initially thought (mostly due to C++ and D type incompatibilities
 and scoping issues).

Huh, Murphy in action?

 So now I'm starting to work on wxc generation again. Once that's done,
 I have to test linking between wxd and wxc. Then, I have to fix any
 runtime segfaults I might run into (there's bound to be a few codegen
 issues). Once I have a few wxD samples working on the major platforms,
 I'll release an alpha of wxD (+ the codegenerator) and then we can
 start testing the library more thoroughly before any official release.

Although we're still swamped into non-D computer issues, we'll find the
time to be tester of your alpha release.

Thank you, again, for your hard work!


Sincerely,
Gour


-- 
O chastiser of the enemy, the sacrifice performed in knowledge 
is better than the mere sacrifice of material possessions. 
After all, O son of Pṛthā, all sacrifices of work culminate 
in transcendental knowledge.

http://atmarama.net | Hlapicina (Croatia) | GPG: 52B5C810


signature.asc
Description: PGP signature


Re: Interesting Memory Optimization

2012-03-17 Thread Don Clugston

On 16/03/12 13:24, Kevin Cox wrote:


On Mar 16, 2012 7:45 AM, Alex Rønne Petersen xtzgzo...@gmail.com
mailto:xtzgzo...@gmail.com wrote
 
  I don't see any reason why c couldn't point to element number 3 of b,
and have its length set to 3...
 
  --
  - Alex

And the previous examples were language agnostic.  In D and other
languages where the length of a string is stored we can nest strings
anywhere inside other strings.

const char[] a = foofoo;
const char[] b = oof;

Those can't be nested in null terminated strings, bit they can where
strings have an explicit length.



Unfortunately string literals in D have an implicit \0 added beyond the 
end, so we don't have much more freedom than C.


BlockingTextWriter?

2012-03-17 Thread Paul D. Anderson

In the Phobos documentation for std.format:

[O]utput is sent do this writer. Typical output writers include 
std.array.Appender!string and std.stdio.BlockingTextWriter.


std.stdio doesn't have a BlockingTextWriter but it does have a 
LockingTextWriter.


Typo? Name change? BlockingTextWriter is scheduled for 
deprecation?


Also --

It was only after I cut and pasted the documentation fragment 
that I noticed that  output is sent do this writer.


Paul



Re: automated C++ binding generation.. Booost D, NO , Not us. SIMD is more important.

2012-03-17 Thread bls

On 03/16/2012 06:29 PM, Andrej Mitrovic wrote:

So, stay tight! Good times ahead.:)


Incredible good news! Thanks.

One of the very first wxD applications could be a GUI for the generator.





Re: OpenBSD port of dmd?

2012-03-17 Thread Johannes Pfau
Am Fri, 16 Mar 2012 14:37:43 -0700
schrieb Sean Kelly s...@invisibleduck.org:

 On Mar 16, 2012, at 2:19 PM, Johannes Pfau wrote:
 
  Am Fri, 16 Mar 2012 12:08:01 -0700
  schrieb Walter Bright newshou...@digitalmars.com:
  
  On 3/16/2012 7:53 AM, Andrei Alexandrescu wrote:
  Just found this, has anyone tried dmd or friends on OpenBSD?
  
  http://stackoverflow.com/questions/9698581/programming-in-d-for-openbsd
  
  There was a start on an OpenBSD port, but it hasn't progressed very
  far. It shouldn't be hard - if someone wants to pick up the flag on
  this and run with it, I'd be happy to fold in the changes.
  
  AFAICS OpenBSD doesn't support TLS (the __thread tls, posix
  pthread_getspecific works of course). Can D work at all without TLS
  support?
  
  (We have a similar problem with Android, I know for sure TLS isn't
  supported there.)
 
 OSX pre-Lion doesn't support __thread either, so DMD rolls its own
 there.  The same functionality could probably be used for OpenBSD.
 

That's interesting. GCC does have emulated TLS as well but GCC's
implementation doesn't work with the GC. I guess the dmd tls emulation
is in the backend, so nothing GDC could use?


Re: Proposal: user defined attributes

2012-03-17 Thread Manu
On 17 March 2012 02:53, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:

 On 3/17/12, Kapps opantm2+s...@gmail.com wrote:
  @WebForm(Account);
  @PostTo(Services/CreateAccount)
  @SecureOnly(true)
  struct CreateAccountForm {

 That kind of turns D from a structural to a declarative language. :p


And that's awesome in many situations! :)

This also maps really well to games/tools/editors/script bindings. C# has
this, and it's an invaluable language feature. It adds so much simplicity
to the tools code.


Re: OpenBSD port of dmd?

2012-03-17 Thread Alix Pexton

I think Walter and Andrei are both right, just about different things.

I think Walter is right that there is no such thing as a default 
implementation when it comes to compatibility with the host environment, 
and asserting is the best course of action.


I think Andrei is right that when a particular environment has some 
advantageous alternate implementation of a feature it can be used while 
leaving the default for the cases where said feature is unavailable.


Walter is concerned with compatibility, Andrei with opportunistic 
optimisation.


Knowing how to tell the difference is the real trick, and that is often 
a much harder thing to pin down. Code that potentially needs to be 
different on every platform should assert when the platform is 
unrecognised. Code which is specialised for just a few platforms and has 
a known good default can use else to provide said default. When 
unsure, assert is the more cautious option.


A...


Re: Scala macros

2012-03-17 Thread Tobias Pankrath

There a different tools for rewriting code out there. Maybe you
can get some inspiration by there syntax.

Examples are:

TXL (www.txl.ca)
Domain Maintenance System (www.semdesigns.com)
Raincode (www.raincode.com)

where the last one probably isn't worth the look.


Re: Proposal: user defined attributes

2012-03-17 Thread Gor Gyolchanyan
What we're talking about here is subject-oriented programming: having
the attributes get enclosed into objects, rather then objects
enclosing attributes. And this is extremely useful, IMO.

On Sat, Mar 17, 2012 at 1:23 PM, Manu turkey...@gmail.com wrote:
 On 17 March 2012 02:53, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:

 On 3/17/12, Kapps opantm2+s...@gmail.com wrote:
  @WebForm(Account);
  @PostTo(Services/CreateAccount)
  @SecureOnly(true)
  struct CreateAccountForm {

 That kind of turns D from a structural to a declarative language. :p


 And that's awesome in many situations! :)

 This also maps really well to games/tools/editors/script bindings. C# has
 this, and it's an invaluable language feature. It adds so much simplicity to
 the tools code.



-- 
Bye,
Gor Gyolchanyan.


Re: OpenBSD port of dmd?

2012-03-17 Thread Sean Kelly
On Mar 17, 2012, at 1:25 AM, Johannes Pfau nos...@example.com wrote:

 Am Fri, 16 Mar 2012 14:37:43 -0700
 schrieb Sean Kelly s...@invisibleduck.org:
 
 On Mar 16, 2012, at 2:19 PM, Johannes Pfau wrote:
 
 Am Fri, 16 Mar 2012 12:08:01 -0700
 schrieb Walter Bright newshou...@digitalmars.com:
 
 On 3/16/2012 7:53 AM, Andrei Alexandrescu wrote:
 Just found this, has anyone tried dmd or friends on OpenBSD?
 
 http://stackoverflow.com/questions/9698581/programming-in-d-for-openbsd
 
 There was a start on an OpenBSD port, but it hasn't progressed very
 far. It shouldn't be hard - if someone wants to pick up the flag on
 this and run with it, I'd be happy to fold in the changes.
 
 AFAICS OpenBSD doesn't support TLS (the __thread tls, posix
 pthread_getspecific works of course). Can D work at all without TLS
 support?
 
 (We have a similar problem with Android, I know for sure TLS isn't
 supported there.)
 
 OSX pre-Lion doesn't support __thread either, so DMD rolls its own
 there.  The same functionality could probably be used for OpenBSD.
 
 
 That's interesting. GCC does have emulated TLS as well but GCC's
 implementation doesn't work with the GC. I guess the dmd tls emulation
 is in the backend, so nothing GDC could use?

There's a bit of blackened support to denote tls data, but the rest is in 
library. Look at core.thread. 

Re: OpenBSD port of dmd?

2012-03-17 Thread Sean Kelly
Pretty much. I'd expect to see:

version (linux) {
// optimized impl
} else version (OSX) {
version = UseDefault;
} else {
static assert(false, unknown platform);
}
version (UseDefault) {
...
}

This way, new platforms have to be evaluated, but once they are they can all 
share whatever common implementation is the default. 

On Mar 17, 2012, at 3:31 AM, Alix Pexton alix.dot.pex...@gmail.dot.com wrote:

 I think Walter and Andrei are both right, just about different things.
 
 I think Walter is right that there is no such thing as a default 
 implementation when it comes to compatibility with the host environment, and 
 asserting is the best course of action.
 
 I think Andrei is right that when a particular environment has some 
 advantageous alternate implementation of a feature it can be used while 
 leaving the default for the cases where said feature is unavailable.
 
 Walter is concerned with compatibility, Andrei with opportunistic 
 optimisation.
 
 Knowing how to tell the difference is the real trick, and that is often a 
 much harder thing to pin down. Code that potentially needs to be different on 
 every platform should assert when the platform is unrecognised. Code which is 
 specialised for just a few platforms and has a known good default can use 
 else to provide said default. When unsure, assert is the more cautious option.
 
 A...


More putrid beef soup (Was: Re: Implicit string lit conversion to wstring/dstring)

2012-03-17 Thread H. S. Teoh
On Wed, Mar 14, 2012 at 02:07:04PM -0500, Andrei Alexandrescu wrote:
[...]
 Aha! This is one of those cases in which built-in magic smells of
 putrid beef soup.
[...]

It gets worse than we first thought:

void f1(dstring x) { dstring y = x; }

void f2()(dstring x) { dstring y = x; }
void f2(U)(U x) if (!is(U==string)) { dstring y = x; }

void f3(byte[] x) { byte[] y = x; }

void f4()(byte[] x) { byte[] y = x; }
void f4(U)(U x) if (!is(U==int[])) { byte[] y = x; }

void main() {
f1(abc);  // OK: abc deduced as dstring

f2(abc);  // OK: abc defaults to string, but f2(U)(U)
// declines U==string, so f2()(dstring) is
// chosen, and abc is deduced as dstring

f3([1,2,3]);// OK: [1,2,3] deduced as byte[]

f4([1,2,3]);// Error: template test2.f4() does not match 
any function template declaration
// Error: template test2.f4() cannot deduce 
template function from argument types !()(int[])
}

WAT?? So abc will match f()(dstring x), but [1,2,3] doesn't match
f()(byte[] b)?

Upon further investigation:

void f5(dstring s) {}
void f6()(dstring s) {}
void f7(byte[] s) {}
void f8()(byte[] s) {}
void main() {
f5(abc);  // OK
f6(abc);  // OK (!)
f7([1,2,3]);// OK

f8([1,2,3]);// cannot deduce template function from 
argument types !()(int[])
}

WAT?


T

-- 
You know, maybe we don't *need* enemies. Yeah, best friends are about all I 
can take. -- Calvin  Hobbes


Re: Turning a SIGSEGV into a regular function call under Linux, allowing throw

2012-03-17 Thread deadalnix

Le 15/03/2012 21:20, FeepingCreature a écrit :

On 03/15/12 16:16, Kagamin wrote:

Does it recover from

void function() f=null;
f();


Not as currently written, no. It should be possible to detect this case and get 
a proper stackframe back, though.


It is supported as written in my sample code. I have do do another one 
for x86_64.


Re: Proposal: user defined attributes

2012-03-17 Thread Jacob Carlborg

On 2012-03-16 14:35, Adam D. Ruppe wrote:

On the ride over here today, I had a thought that
I think neatly solves the user defined attribute
question.


I would love to have user defined attributes in D but I'm not completely 
like your approach. I would go with something more like Java 
annotations. This is how I would like user defined attributes to work.


Attributes can be applied to most declarations like: classes, fields, 
variables, functions, parameters and so on. Attributes are used with the 
following syntax:


@foo(key = value, key2 = value2) class Bar {}

foo is the name of the attribute. In the parentheses is a key-value 
list passed to the attribute. The values can be of any type available at 
compile time.


Attributes are defined as follows:

We add a new attribute called @annotation or @attribute. This 
attribute is applied to a class or struct to make it an attribute:


@attribute class foo
{
string key;
string key2;
}

The keys the attribute accepts are declared in the class as either 
fields or methods (haven't decided yet). It's perfectly fine to have an 
attribute accepting no values which doesn't have to declare any keys:


@attribute class bar {}

If an attribute only accepts one value the name of the value needs to be 
value:


@attribute class fooBar
{
string value;
}

This allows to not have to specify the key when passing a value to the 
attribute:


@fooBar(asd) class Foo {}

Accessing information about attribute should be possible both during 
compile time and runtime. At compile time __traits can be used:


__traits(hasAttribute, bar, Foo); // returns true if the attribute bar 
as been applied to Foo


__traits(getAttribute, bar, key, Foo); // returns the value of the key key

This is all very similar to how it works in Java:

http://docs.oracle.com/javase/1.5.0/docs/guide/language/annotations.html

--
/Jacob Carlborg


Re: OpenBSD port of dmd?

2012-03-17 Thread Jose Armando Garcia
On Sat, Mar 17, 2012 at 7:10 AM, Sean Kelly s...@invisibleduck.org wrote:
 Pretty much. I'd expect to see:

 version (linux) {
    // optimized impl
 } else version (OSX) {
    version = UseDefault;

Speaking of version specification, in this particular example is
version(UseDefault) only define on this module? The Language reference
doesn't seem to mention anything explicitly about this. It does have
the following:

Predefined version identifiers are global, i.e. they apply to all
modules being compiled and imported.

Does this mean that the opposite is true? 'version = UseDefault' is
only define in the module defined.

Thanks,
-Jose

 } else {
    static assert(false, unknown platform);
 }
 version (UseDefault) {
    ...
 }

 This way, new platforms have to be evaluated, but once they are they can all 
 share whatever common implementation is the default.

 On Mar 17, 2012, at 3:31 AM, Alix Pexton alix.dot.pex...@gmail.dot.com 
 wrote:

 I think Walter and Andrei are both right, just about different things.

 I think Walter is right that there is no such thing as a default 
 implementation when it comes to compatibility with the host environment, and 
 asserting is the best course of action.

 I think Andrei is right that when a particular environment has some 
 advantageous alternate implementation of a feature it can be used while 
 leaving the default for the cases where said feature is unavailable.

 Walter is concerned with compatibility, Andrei with opportunistic 
 optimisation.

 Knowing how to tell the difference is the real trick, and that is often a 
 much harder thing to pin down. Code that potentially needs to be different 
 on every platform should assert when the platform is unrecognised. Code 
 which is specialised for just a few platforms and has a known good default 
 can use else to provide said default. When unsure, assert is the more 
 cautious option.

 A...


Re: BlockingTextWriter?

2012-03-17 Thread Andrei Alexandrescu

On 3/17/12 2:29 AM, Paul D. Anderson wrote:

In the Phobos documentation for std.format:

[O]utput is sent do this writer. Typical output writers include
std.array.Appender!string and std.stdio.BlockingTextWriter.

std.stdio doesn't have a BlockingTextWriter but it does have a
LockingTextWriter.

Typo? Name change? BlockingTextWriter is scheduled for deprecation?

Also --

It was only after I cut and pasted the documentation fragment that I
noticed that output is sent do this writer.


Typos fixed. Thanks!

Andrei




Re: OpenBSD port of dmd?

2012-03-17 Thread Andrei Alexandrescu

On 3/17/12 9:10 AM, Sean Kelly wrote:

Pretty much. I'd expect to see:

version (linux) {
 // optimized impl
} else version (OSX) {
 version = UseDefault;
} else {
 static assert(false, unknown platform);
}
version (UseDefault) {
 ...
}


Taking this to its logical conclusion means that _all_ code that is 
currently unguarded must be guarded by version (UseDefault).


Andrei




Re: automated C++ binding generation.. Booost D, NO , Not us. SIMD is more important.

2012-03-17 Thread Jacob Carlborg

On 2012-03-17 04:34, Andrej Mitrovic wrote:

On 3/17/12, Brad Andersone...@gnuk.net  wrote:

Could the wxc generator be be used as a base for building bindings for
other libraries?


I hope it will be. It's kind of crazy that the first thing I'm using
it on is a huge library like wxD, this will likely be its biggest
unittest, so to speak. :p

Doxygen can be run on libraries with no documentation (there's a
switch for that), so it can extract the needed data for the generator.
Of course it depends how complex the library is, e.g. you can't run
doxygen directly on wxWidgets include files because they're very
complicated (it actually crashes doxygen), but this is why the wx devs
have created a separate set of interface files for doxygen.


This is why a proper compiler is needed, this will not work in the long run.

--
/Jacob Carlborg


confused about pure functions

2012-03-17 Thread markusle

Using dmd 2.058 I can compile the following

pure bool has_path(string paths[], string needle) {

   paths[0] = bad;

   ... do something else ...

   return false;
}

and change the passed in array paths. Isn't this a violation of
has_path's pure contract? Shouldn't all pure function parameters
be passed as in to avoid side effects. Sorry if I missed
something obvious.


Re: confused about pure functions

2012-03-17 Thread Adam D. Ruppe

In D, pure means it doesn't have any side effects outside
its parameter list.

It can change what you pass in, but nothing else.


Pass it all in, const, or best of all, immutable params
and it can't change anything - that's the pure you're
probably thinking of.



The reason it lets you change the arguments is so you
can use more functions as pure. Consider that you can
have mutable local variables in a pure function - a
local variable doesn't change the outside world, so
it never breaks the contract.

You might want to use a helper function on your local
variables.


Editing a local variable is allowed, so calling a function
that edits a local variable should be allowed too. As far
as the outside world can tell, this is exactly the same thing.

pure void increment(ref int a) { a++; }
int myInt = 0;
increment(myInt); // is logically the same as myInt++;
// we'd allow myInt++;, so we should allow increment(myInt) too.



But, under the strictest definition of pure, that increment
function wouldn't be allowed. Pure functions can only call
other pure functions.


That's why D pure is a little looser: this /should/ be
allowed. Thus, it can be marked as pure.


Does this break the big contract? No, because editing the
params is a purely local modification - the outside world
doesn't need to care how you build your own local variables.


When combined with transitive immutable, you can create
nice pockets of purity while retaining flexibility in
how you implement the function itself. Only what you
pass and get from it is important.


Understanding Templates: why can't anybody do it?

2012-03-17 Thread Entity325
(Sorry if this is the wrong place for this, or if there's already 
a thread in existence which would be better.  If either of these 
is the case, simply point me in the right direction, and I'll be 
on my way.)


My first interaction with Templates was about 5 years ago, in a 
C++ class at my university.  I immediately thought A general 
type?  This would be great for my logger! and tried to implement 
them into the small library I had been developing to save time on 
the class assignments.


Naturally, I didn't understand them, so after a couple of 
half-hearted attempts, I gave up and went back to doing things 
the way I had before.  I've avoided Templates since then, because 
they don't make any sense!


5 years later, enter D.  In the process of trying to teach myself 
some D, I've found myself with a library of Structs for which the 
operator overloading features are extremely handy.


Teensy problem here: the documentation on how to use operators 
makes use of Template types in the examples.


Having developed a bit more analytical skill and tenacity in the 
intervening years, I resolved to actually figure the mess out 
this time.  I have come to a conclusion.


The reason nobody understands Templates is that nobody 
understands them.


That is to say, nobody understands how Templates work is because, 
as was the case for me, the sum total of explanation we are given 
on them in programming class is These are Templates.  They 
exist.  They look something like this.


Even the (quite thorough) documentation for the D language 
reference isn't immune to this, if we take a look.  
(http://dlang.org/template.html) As you can see, the page more or 
less starts off with --And here are some cool things you can do 
with templates.


Wait, what?  I feel like I've started watching Primer 20 minutes 
before the end, without anybody telling me what's going on.


Herein, I think, lies the root of the reason why nobody 
understands Templates.  I think the solution to this problem is 
not to comfort programming students by saying Don't worry, 
nobody understands Templates.  I think it's time we collectively 
figured out what they are.  That done, we can overhaul the way 
new programmers learn how to use them.


Who's with me?  Anybody have a short(but COMPLETE!) example of 
code that makes use of Templates that you actually understand 
what's going on there?


Re: automated C++ binding generation.. Booost D, NO , Not us. SIMD is more important.

2012-03-17 Thread bls

On 03/17/2012 09:50 AM, Jacob Carlborg wrote:

This is why a proper compiler is needed, this will not work in the long
run.


Are you aware that doxgen's xml output is based on gcc-xml ?

I think it is necessary to say that doxygen, respective gcc-xml, is 
working on stripped and annotated header files (so called interface files)

f.i. http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/interface/wx/

So, stupid manual work is needed to create these interface files.

Until you don't have a heavily templated c++ lib, using doygen's xml 
output is, IMHO, a reasonable way to create bindings.


well, will see


Re: automated C++ binding generation.. Booost D, NO , Not us. SIMD is more important.

2012-03-17 Thread Jacob Carlborg

On 2012-03-17 18:36, bls wrote:

On 03/17/2012 09:50 AM, Jacob Carlborg wrote:

This is why a proper compiler is needed, this will not work in the long
run.


Are you aware that doxgen's xml output is based on gcc-xml ?


No, I was not aware of that. What is the problem then, doxygen choking 
on the XML or GCC choking on the include files?



I think it is necessary to say that doxygen, respective gcc-xml, is
working on stripped and annotated header files (so called interface files)
f.i. http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/interface/wx/

So, stupid manual work is needed to create these interface files.


That sucks.

--
/Jacob Carlborg


Re: automated C++ binding generation.. Booost D, NO , Not us. SIMD is more important.

2012-03-17 Thread bls

On 03/17/2012 10:44 AM, Jacob Carlborg wrote:

On 2012-03-17 18:36, bls wrote:

On 03/17/2012 09:50 AM, Jacob Carlborg wrote:

This is why a proper compiler is needed, this will not work in the long
run.


Are you aware that doxgen's xml output is based on gcc-xml ?


No, I was not aware of that. What is the problem then, doxygen choking
on the XML or GCC choking on the include files?


I think it is necessary to say that doxygen, respective gcc-xml, is
working on stripped and annotated header files (so called interface
files)
f.i. http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/interface/wx/

So, stupid manual work is needed to create these interface files.


That sucks.

 Yeah it sucks, but on the other hand it is AFAIK just removing the 
private stuff (methods, decls,  etc.) forward decls, and write some 
annotations.. like @iOS-only from the header.


I really hope to see a working wxD soon. I will try to create bindings 
for the wxShapeFramework than..




Re: automated C++ binding generation.. Booost D, NO , Not us. SIMD is more important.

2012-03-17 Thread bls

On 03/17/2012 10:44 AM, Jacob Carlborg wrote:

What is the problem then, doxygen choking on the XML or GCC choking on
the include files?


gcc-xml is stalled. Means newer C++ stuff is not supported.

See news...
http://www.gccxml.org/HTML/News.html


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Andrei Alexandrescu

On 3/17/12 12:14 PM, Entity325 wrote:

Who's with me? Anybody have a short(but COMPLETE!) example of code that
makes use of Templates that you actually understand what's going on there?


You're on to something here. Then, as usual, from idea to realization 
there are quite a few steps.


I took a complementary approach in TDPL: there's no chapter on templates 
at all. Templates are naturally interwoven with whatever topic is at 
hand, wherever they're useful. I hoped people would learn templates 
without even knowing it.



Andrei


Re: confused about pure functions

2012-03-17 Thread Andrei Alexandrescu

On 3/17/12 12:02 PM, markusle wrote:

Using dmd 2.058 I can compile the following

pure bool has_path(string paths[], string needle) {

paths[0] = bad;

... do something else ...

return false;
}

and change the passed in array paths. Isn't this a violation of
has_path's pure contract? Shouldn't all pure function parameters
be passed as in to avoid side effects. Sorry if I missed
something obvious.


D's working definition of a pure function is effect only depends on 
parameters. Mutating parameters does fit the definition.


This is less tight than other languages' definition, but we believe it's 
a sweet spot between reaping the modularity benefits of purity, and 
benefiting of the advantages of mutation.


Also, not all is lost. If you want to disallow parameter mutation, add 
in to them. That way, you only need to see the function's signature to 
draw a variety of interesting facts about it.



Andrei


Re: OpenBSD port of dmd?

2012-03-17 Thread Walter Bright

On 3/17/2012 9:16 AM, Jose Armando Garcia wrote:

On Sat, Mar 17, 2012 at 7:10 AM, Sean Kellys...@invisibleduck.org  wrote:

version (linux) {
// optimized impl
} else version (OSX) {
version = UseDefault;


Speaking of version specification, in this particular example is
version(UseDefault) only define on this module?


   version=identifier;

declarations apply only to the module that declaration appears in.


Re: automated C++ binding generation.. Booost D, NO , Not us. SIMD is more important.

2012-03-17 Thread bls

On 03/17/2012 10:51 AM, bls wrote:

Are you aware that doxgen's xml output is based on gcc-xml ?


I should be more carefull :( It's another wxWidgets utility that is 
using gcc-xml.


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Walter Bright

On 3/17/2012 10:55 AM, Andrei Alexandrescu wrote:

On 3/17/12 12:14 PM, Entity325 wrote:

Who's with me? Anybody have a short(but COMPLETE!) example of code that
makes use of Templates that you actually understand what's going on there?


You're on to something here. Then, as usual, from idea to realization there are
quite a few steps.

I took a complementary approach in TDPL: there's no chapter on templates at all.
Templates are naturally interwoven with whatever topic is at hand, wherever
they're useful. I hoped people would learn templates without even knowing it.


Sans value parameters:

 int foo() {
return 3;
 }

With value parameters:

  int foo(int i) {
return i;
  }

Sans type parameters:

 struct S {
   int i;
 }

With type parameters:

 struct S(T) {
   T i;
 }

i.e. templates are type parameters.


Re: OpenBSD port of dmd?

2012-03-17 Thread Sean Kelly
On Mar 17, 2012, at 9:43 AM, Andrei Alexandrescu 
seewebsiteforem...@erdani.org wrote:

 On 3/17/12 9:10 AM, Sean Kelly wrote:
 Pretty much. I'd expect to see:
 
 version (linux) {
 // optimized impl
 } else version (OSX) {
 version = UseDefault;
 } else {
 static assert(false, unknown platform);
 }
 version (UseDefault) {
 ...
 }
 
 Taking this to its logical conclusion means that _all_ code that is currently 
 unguarded must be guarded by version (UseDefault).

No need for logical fallacies.  My point was that for code where 
platform-specific optimizations are performed, construct the code in such a way 
that when porting to a new platform, the compiler points at places that bear 
investigation. 

Re: confused about pure functions

2012-03-17 Thread markusle
On Saturday, 17 March 2012 at 17:59:12 UTC, Andrei Alexandrescu 
wrote:

On 3/17/12 12:02 PM, markusle wrote:

Using dmd 2.058 I can compile the following

pure bool has_path(string paths[], string needle) {

paths[0] = bad;

... do something else ...

return false;
}

and change the passed in array paths. Isn't this a violation 
of
has_path's pure contract? Shouldn't all pure function 
parameters

be passed as in to avoid side effects. Sorry if I missed
something obvious.


D's working definition of a pure function is effect only 
depends on parameters. Mutating parameters does fit the 
definition.


This is less tight than other languages' definition, but we 
believe it's a sweet spot between reaping the modularity 
benefits of purity, and benefiting of the advantages of 
mutation.


Also, not all is lost. If you want to disallow parameter 
mutation, add in to them. That way, you only need to see the 
function's signature to draw a variety of interesting facts 
about it.



Andrei


Thanks a lot for yours and Adam's detailed explanation. This 
makes much more sense now.


Re: OpenBSD port of dmd?

2012-03-17 Thread Johannes Pfau
Am Sat, 17 Mar 2012 07:04:20 -0700
schrieb Sean Kelly s...@invisibleduck.org:

 On Mar 17, 2012, at 1:25 AM, Johannes Pfau nos...@example.com wrote:
 
  Am Fri, 16 Mar 2012 14:37:43 -0700
  schrieb Sean Kelly s...@invisibleduck.org:
  
  
  OSX pre-Lion doesn't support __thread either, so DMD rolls its own
  there.  The same functionality could probably be used for OpenBSD.
  
  
  That's interesting. GCC does have emulated TLS as well but GCC's
  implementation doesn't work with the GC. I guess the dmd tls
  emulation is in the backend, so nothing GDC could use?
 
 There's a bit of blackened support to denote tls data, but the rest
 is in library. Look at core.thread. 

Thanks.
I guess this could be supported in gdc (maybe it's already supported on
OSX? I'll have to look that up), it doesn't look too complicated. But it
won't work for dynamic libraries and/or dlopen, right?


Re: std.simd

2012-03-17 Thread Robert Jacques

On Fri, 16 Mar 2012 16:45:05 -0500, Manu turkey...@gmail.com wrote:

On 16 March 2012 22:39, Robert Jacques sandf...@jhu.edu wrote:

On Fri, 16 Mar 2012 08:24:58 -0500, David Nadlinger s...@klickverbot.at
wrote:
 On Thursday, 15 March 2012 at 23:32:29 UTC, Robert Jacques wrote:


[snip]


Unrelated libraries using the same name is relatively painless. Highly
related libraries that conflict, on the other hand, are generally painful.
Yes, there are a lot of mechanisms available to work around this, but
selective imports and renaming all add to the cognitive load of using and
writing the code.

To me float4 isn't a SIMD name; its a vector name and if it's implemented
using SIMD, great, but that's an implementation detail. I can understand a
close to the metal SIMD library and encourage the work. But if it isn't
also going to be a vector library, if possible, it shouldn't use the vector
names.



Can you give me an example of a non-simd context where this is the case?
Don't say shaders, because that is supported in hardware, and that's my
point.
Also there's nothing stopping a secondary library adding/emulating the
additional types. They could work seamlessly together. flaot4 may come from
std.simd, float3/float2 may be added by a further lib that simply extends
std.simd.


Shaders. :) Actually, float4 isn't supported in hardware if you're on NVIDIA. 
And IIRC ATI/AMD is moving away from hardware support as well. I'm not sure 
what Intel or the embedded GPUs do. On the CPU side SIMD support on both ARM 
and PowerPC is optional. As for examples, pretty much every graphics, vision, 
imaging and robotics library has a small vector library attached to it; were 
you looking for something else?

Also, clean support for float3 / float2 / etc. has shown up in Intel's Larrabee 
and its Knight's derivatives; so, maybe we'll see it in a desktop processor 
someday. To say nothing of the 245-bit and 512-bit SIMD units on some machines.

My concern is that std.simd is (for good reason) leaking the underlying 
hardware implementation (std.simd seems to be very x86 centric), while vectors, 
in my mind, are a higher level abstraction.


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Xinok

On Saturday, 17 March 2012 at 18:16:31 UTC, Walter Bright wrote:

i.e. templates are type parameters.


Maybe in C++. In C++, templates are attached to a class or 
function, where as in D, they're an independent construct. The 
way I think of it, templates are a tool for building static code 
from a set of parameters. String mixins are a similar tool which 
are more powerful but less elegant.


Programmers will use templates for unintended purposes, but that 
doesn't change what they are. You can use full closures to store 
references to variables, but that doesn't make functions 
reference types.


Re: OpenBSD port of dmd?

2012-03-17 Thread Martin Nowak

On Fri, 16 Mar 2012 21:00:47 +0100, Nick Sabalausky a@a.a wrote:


Martin Nowak d...@dawgfoto.de wrote in message
news:op.wa9r9izqsqugbd@localhost...

On Fri, 16 Mar 2012 15:53:45 +0100, Andrei Alexandrescu
seewebsiteforem...@erdani.org wrote:


Just found this, has anyone tried dmd or friends on OpenBSD?

http://stackoverflow.com/questions/9698581/programming-in-d-for-openbsd


OpenBSD would need some druntime work.


Do you have anything in particular in mind?


Porting any POSIX/ELF OS should be very simple.

- add OS detection to makefiles
- add in OS specific struct layouts in core.sys (ucontext_t, siginfo_t,  
sockaddr...)
- add rt.memory functions, using the linker script to find static segment  
brackets



We use the following pattern all over the place.

version (Windows) {}
else version (OSX) {}
else version (linux) {}
else version (FreeBSD) {}
else static assert(0);

For anything but struct layouts the following would be correct.

version (Windows) {}
else version (linux, OSX) {} // iff specialized
else version (POSIX) {}
else static assert(0);

Because of this you'll need to change core.{thread...} and dmd as well.

I'm not stepping into the discussion below but I don't see the point of
differencing FreeBSD, NetBSD, OpenBSD, DragonFlyBSD, Darwin, Solaris,  
OpenIndiana...

After all that's what POSIX was made for.

Have a look at core.sync.mutex which will work on all of these platforms.


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Paulo Pinto

Maybe you should first try to learn some concepts about generic programming

http://en.wikipedia.org/wiki/Generic_programming

You will see this is nothing specific to C++ or D, and almost
all modern languages do have some form of genericity.

If you still cannot understand them, you cold try to explain why
you have difficulties understanding this concept, and we could
try to explain them to you. Even improve D's documentation.

--
Paulo

Am 17.03.2012 18:14, schrieb Entity325:

(Sorry if this is the wrong place for this, or if there's already a
thread in existence which would be better. If either of these is the
case, simply point me in the right direction, and I'll be on my way.)

My first interaction with Templates was about 5 years ago, in a C++
class at my university. I immediately thought A general type? This
would be great for my logger! and tried to implement them into the
small library I had been developing to save time on the class assignments.

Naturally, I didn't understand them, so after a couple of half-hearted
attempts, I gave up and went back to doing things the way I had before.
I've avoided Templates since then, because they don't make any sense!

5 years later, enter D. In the process of trying to teach myself some D,
I've found myself with a library of Structs for which the operator
overloading features are extremely handy.

Teensy problem here: the documentation on how to use operators makes use
of Template types in the examples.

Having developed a bit more analytical skill and tenacity in the
intervening years, I resolved to actually figure the mess out this time.
I have come to a conclusion.

The reason nobody understands Templates is that nobody understands them.

That is to say, nobody understands how Templates work is because, as was
the case for me, the sum total of explanation we are given on them in
programming class is These are Templates. They exist. They look
something like this.

Even the (quite thorough) documentation for the D language reference
isn't immune to this, if we take a look.
(http://dlang.org/template.html) As you can see, the page more or less
starts off with --And here are some cool things you can do with
templates.

Wait, what? I feel like I've started watching Primer 20 minutes before
the end, without anybody telling me what's going on.

Herein, I think, lies the root of the reason why nobody understands
Templates. I think the solution to this problem is not to comfort
programming students by saying Don't worry, nobody understands
Templates. I think it's time we collectively figured out what they are.
That done, we can overhaul the way new programmers learn how to use them.

Who's with me? Anybody have a short(but COMPLETE!) example of code that
makes use of Templates that you actually understand what's going on there?




Re: std.simd

2012-03-17 Thread Manu
On 17 March 2012 20:42, Robert Jacques sandf...@jhu.edu wrote:

 On Fri, 16 Mar 2012 16:45:05 -0500, Manu turkey...@gmail.com wrote:

 Can you give me an example of a non-simd context where this is the case?

 Don't say shaders, because that is supported in hardware, and that's my
 point.
 Also there's nothing stopping a secondary library adding/emulating the
 additional types. They could work seamlessly together. flaot4 may come
 from
 std.simd, float3/float2 may be added by a further lib that simply extends
 std.simd.


 Shaders. :) Actually, float4 isn't supported in hardware if you're on
 NVIDIA. And IIRC ATI/AMD is moving away from hardware support as well. I'm
 not sure what Intel or the embedded GPUs do. On the CPU side SIMD support
 on both ARM and PowerPC is optional. As for examples, pretty much every
 graphics, vision, imaging and robotics library has a small vector library
 attached to it; were you looking for something else?


GPU hardware is fundamentally different than CPU vector extensions. The
goal is not to imitate shaders on the CPU. There are already other
possibilities for that anyway.

Also, clean support for float3 / float2 / etc. has shown up in Intel's
 Larrabee and its Knight's derivatives; so, maybe we'll see it in a desktop
 processor someday. To say nothing of the 245-bit and 512-bit SIMD units on
 some machines.


Well when that day comes, we'll add hardware abstraction for it. There are
2 that do currently exist, 3DNow, but that's so antiquated, I see no reason
to support it. The other is the Gamecube, Wii, WiiU line of consoles; all
have 2D vector hardware. I'll gladly add support for that the very moment
anyone threatens to use D on a Nintendo system, but no point right now.

float3 on the other hand is not supported on any machine, and it's very
inefficient. Use of float3 should be discouraged at all costs. People
should be encouraged to use float4's and pack something useful in W if they
can. And if not, they should be aware that they are wasting 25% of their
flops.

I don't recall ever dismissing 256bit vector units. Infact I've suggested
support for AVX is mandatory on plenty of occasions. I'm also familiar with
a few 512bit vector architectures, but I don't think they warrant a
language level implementation yet. Let's just work through what we have,
and what will be used to start with. I'd be keen to see how it tends to be
used, and make any fundamental changes before blowing it way out
of proportion.


 My concern is that std.simd is (for good reason) leaking the underlying
 hardware implementation (std.simd seems to be very x86 centric), while
 vectors, in my mind, are a higher level abstraction.


It's certainly not SSE centric. Actually, if you can legitimately criticise
me of anything, it's being biased AGAINST x86 based processors. I'm
critically aware of VMX, NEON, SPU, and many architectures that came before.
What parts of my current work in progress do you suggest is biased to x86
hardware implementation? From my experience, I'm fairly happy with how it
looks at this point being an efficiency-first architecture-abstracted
interface.

As I've said, I'm still confident that people will just come along and wrap
it up with what they feel is a simple/user-friendly interface anyway. If I
try to make this higher-level/more-user-friendly, I still won't please
everyone, and I'll sacrifice raw efficiency in the process, which defeats
the purpose.

How do you define vectors in your mind?


Re: automated C++ binding generation.. Booost D, NO , Not us. SIMD is more important.

2012-03-17 Thread Andrej Mitrovic
On 3/17/12, Jacob Carlborg d...@me.com wrote:
 This is why a proper compiler is needed, this will not work in the long run.

The generator doesn't really care which tool you use to extract the
data. It should be possible to use a tool such as LLVM to fill the
structs with all the information it needs to build the wrappers. So in
essence it works in a similar way as your dstep project, although I
don't really know how far you've gone in implementing dstep so I can't
compare the two.


Re: OpenBSD port of dmd?

2012-03-17 Thread Martin Nowak

AFAICS OpenBSD doesn't support TLS (the __thread tls, posix
pthread_getspecific works of course). Can D work at all without TLS
support?

(We have a similar problem with Android, I know for sure TLS isn't
supported there.)

Which is just strange given how little effort is needed to
implement this in the runtime loader/libc.
Now that C++11 has 'thread_local' the situation will hopefully improve  
soon.


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Ali Çehreli

On 03/17/2012 10:14 AM, Entity325 wrote:

 Who's with me? Anybody have a short(but COMPLETE!) example of code that
 makes use of Templates that you actually understand what's going on 
there?


The Templates chapter of Programming in D is supposed to be a gentle 
introduction to templates:


  http://ddili.org/ders/d.en/templates.html

The book have supposed to build up enough base in the previous chapters 
to make the topic easy to follow but some of the previous chapters have 
not been translated to English yet. There is a second templates chapter 
later in the book that covers to-me more advanced features, which also 
has not been translated yet.


Please provide feedback. :)

The chapter also contains a link to Philippe Sigaud's D Templates: A 
Tutorial.


Ali



Re: Proposal: user defined attributes

2012-03-17 Thread Walter Bright

On 3/16/2012 7:11 AM, Manu wrote:

attribute myAttribute
{
   this(int something);

   bool bNeedsAttention;

   property void refresh(bool bRefresh) { bNeedsAttention = bRefresh; }
}

@myAttribute(10) int thing;

thing.refresh = true;


Under the hood, where would that per-instance data be stored?

Compile-time annotations can be stored internally to the compiler, but 
per-instance runtime data? How is it connected to the instance? When is it 
constructed and destroyed?


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Ali Çehreli

On 03/17/2012 12:57 PM, Ali Çehreli wrote:


http://ddili.org/ders/d.en/templates.html


[...]


The chapter also contains a link to Philippe Sigaud's D Templates: A
Tutorial.


Sorry, I did not intend to leave the link to that document out:


https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/dtemplates.pdf

Ali


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Max Klyga

On 2012-03-17 20:14:47 +0300, Entity325 said:
Who's with me?  Anybody have a short(but COMPLETE!) example of code 
that makes use of Templates that you actually understand what's going 
on there?


Philippe Sigaud made a very good tutorial on templates in D - 
https://github.com/PhilippeSigaud/D-templates-tutorial/raw/master/dtemplates.pdf 





Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Nick Sabalausky
Entity325 lonewolf...@gmail.com wrote in message 
news:pgzkvphadihglayfu...@forum.dlang.org...

 That is to say, nobody understands how Templates work is because, as was 
 the case for me, the sum total of explanation we are given on them in 
 programming class is These are Templates.  They exist.  They look 
 something like this.


I've spent a total of about 6 years in college, always got A's and B's in 
the CS classes, and yet I'm convinced that programming classes are 
completely and utterly useless. Most of the instructors themselves barely 
even know how to code (among many, many other problems). So if you're 
learning programming at college, then I'm not surprised you've gotten the 
impression that nobody understands templates: Around universities, they 
probably don't. (Also, it doesn't help that C++'s templates could be a lot 
better.)

I even had one CS prof, he said that the only language he knew was C. And 
yet, after seeing his feedback on my code, it became abundantly clear to me 
that he didn't even understand how strings worked (ie: C's famous 
null-terminated strings) *in the ONE language he knew*.

Here's a little templates primer, I hope it helps:

A template is just clean way of generating code instead of manually 
copy-pasting a bunch of times (which would end up being a maintenance 
nightmare).

Suppose you have this:

int add(int a, int b)
{
return a + b;
}

Call it, of course, like this:

add(7, 42);

And then you want another version that does it with doubles:

double add(double a, double b)
{
return a + b;
}

Called, of course, like this:

add(3.14, 5.73);

Now you've got two copies that are exactly the same thing, just with one 
little thing changed. If you need top modify one, you'll have to remember to 
modify the other too. And god help you if it's a really big function and you 
accidentally make a mistake copying it. It just gets to be a big problem. It 
violates what we call DRY: Don't Repeat Yourself.

Let's step back into first grade for a minute: Have you ever drawn or 
painted with stencils? You make one design, once, by cutting it out of 
paper. Then you can easily draw and re-draw the same design with different 
colors: Just place the stencil on a new piece of paper, choose a color, 
color it, lift the stencil, and there's another copy of your design, but in 
whatever different color you wanted.

Templates are stencils for code. Heck, even outside of code this is true 
too. template is just another word for stencil.

So here's how you make an add() function stencil. Just punch out what 
you want to change, by making it a template parameter:

// Make a stencil
template myTemplate(T)
{
// This is what's in the stencil
T add(T a, T b)
{
return a + b;
}
}

Notice how the add() function is exactly the same as before, but the ints 
were changed to T (for Type).

Let's stamp down some add() prints:

// The dot in between is because add is *inside* the template 
myTemplate
myTemplate!(int).add(7, 42);
myTemplate!(double).add(3.14, 5.73);

Notice how that's exactly the same as before, but I have that 
myTemplate!(int), and another with float. The compiler turns that into:

int add(int a, int b)
{
return a + b;
}
add(7, 42);

double add(double a, double b)
{
return a + b;
}
add(3.14, 5.73);

Suppose now we also want to be able to use add() for ulong and BigInt. 
Instead of manually copying the function and changing the type, we can just 
let the *compiler* copy the function and change the type:

myTemplate!(ulong).add(7, 42);
myTemplate!(BigInt).add(BigInt(7), BigInt(42));

The compiler, of course, automatically generates:

ulong add(ulong a, ulong b)
{
return a + b;
}

BigInt add(BigInt a, BigInt b)
{
return a + b;
}

And then calls them:

add(7, 42);
add(BigInt(7), BigInt(42));

You can also add more stuff to the template:

// A bigger stencil
template myTemplate(T)
{
T add(T a, T b)
{
return a + b;
}

T mult(T a, T b)
{
return a * b;
}
}

So now the compiler will turn this:

myTemplate!(int)
myTemplate!(double)

Into this:

int add(int a, int b)
{
return a + b;
}

int mult(int a, int b)
{
return a * b;
}

double add(double a, double b)
{
return a + b;
}

double mult(double a, double b)
{
return a * b;
}

And you can use them like this:

myTemplate!(int).add(7, 42);
myTemplate!(double).add(3.14, 5.73);

myTemplate!(int).mult(7, 42);
myTemplate!(double).mult(3.14, 5.73);

You can put other things inside the template, too, like structs and classes, 
or even variables:

template anotherTemplate(T, int initialValue)
{
struct Foo
{
T 

Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Andrej Mitrovic
On 3/17/12, Entity325 lonewolf...@gmail.com wrote:
 Who's with me?  Anybody have a short(but COMPLETE!) example of
 code that makes use of Templates that you actually understand
 what's going on there?

I wrote this a long time ago when I was just figuring out what
templates were about (it's not a general-purpose template tutorial but
just an explanation of a Phobos templated function that someone was
curious about):
http://prowiki.org/wiki4d/wiki.cgi?D__Tutorial/D2Templates

I had no idea what templates were when I started using D, and I
thought I would never need to use them either. But now I use them
extensively. They really become a natural tool in programming. They're
so nice to use that I never have to reach for the big fat OOP monster,
I can just write simple procedural code and use templates when I need
some flexibility.

In the meantime people have written some pretty good tutorials, like
Ali Çehreli's chapter on templates, and recently Philippe Sigaud's D
Template book. Those should be good resources on templates.


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread novice2
templates are a tool for building static code from a set of 
parameters.


unfortunately (imho), there is no way to see the result code



Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Gour
On Sat, 17 Mar 2012 21:29:18 +0100
Andrej Mitrovic andrej.mitrov...@gmail.com wrote:

 I had no idea what templates were when I started using D, and I
 thought I would never need to use them either. But now I use them
 extensively. They really become a natural tool in programming. They're
 so nice to use that I never have to reach for the big fat OOP monster,
 I can just write simple procedural code and use templates when I need
 some flexibility.

Thank you for this paragraph. ;)

I also consider to write procedural/functional code in my project and
leave OOP behind, so it's nice to know that templates are the way to go.


Sincerely,
Gour


-- 
The work of a man who is unattached to the modes of material 
nature and who is fully situated in transcendental knowledge 
merges entirely into transcendence.

http://atmarama.net | Hlapicina (Croatia) | GPG: 52B5C810


signature.asc
Description: PGP signature


Re: automated C++ binding generation.. Booost D, NO , Not us. SIMD is more important.

2012-03-17 Thread Jacob Carlborg

On 2012-03-17 20:20, Andrej Mitrovic wrote:

On 3/17/12, Jacob Carlborgd...@me.com  wrote:

This is why a proper compiler is needed, this will not work in the long run.


The generator doesn't really care which tool you use to extract the
data. It should be possible to use a tool such as LLVM to fill the
structs with all the information it needs to build the wrappers. So in
essence it works in a similar way as your dstep project, although I
don't really know how far you've gone in implementing dstep so I can't
compare the two.


Not ready for a comparison yet.

--
/Jacob Carlborg


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread novice2
How it come, that we build another abstartion level above strong 
typed language?
Onece we builded high level language above assembler. Are we now 
building another more high level? Will temlate will become 
another language used as complete language? Will generic 
prigramming become mainstream, like high level languages today?


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Paulo Pinto

Am 17.03.2012 21:20, schrieb Nick Sabalausky:

Entity325lonewolf...@gmail.com  wrote in message
news:pgzkvphadihglayfu...@forum.dlang.org...


That is to say, nobody understands how Templates work is because, as was
the case for me, the sum total of explanation we are given on them in
programming class is These are Templates.  They exist.  They look
something like this.



I've spent a total of about 6 years in college, always got A's and B's in
the CS classes, and yet I'm convinced that programming classes are
completely and utterly useless. Most of the instructors themselves barely
even know how to code (among many, many other problems). So if you're
learning programming at college, then I'm not surprised you've gotten the
impression that nobody understands templates: Around universities, they
probably don't. (Also, it doesn't help that C++'s templates could be a lot
better.)

I even had one CS prof, he said that the only language he knew was C. And
yet, after seeing his feedback on my code, it became abundantly clear to me
that he didn't even understand how strings worked (ie: C's famous
null-terminated strings) *in the ONE language he knew*.



I would say that most European universities seem to provide a completely 
different experience, at least speaking from my experience in 
Portuguese/Swiss/German ones.





Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Simen Kjærås

On Sat, 17 Mar 2012 21:56:14 +0100, novice2 so...@noem.ail wrote:

How it come, that we build another abstartion level above strong typed  
language?
Onece we builded high level language above assembler. Are we now  
building another more high level? Will temlate will become another  
language used as complete language? Will generic prigramming become  
mainstream, like high level languages today?


It seems to me that templates are mostly useful for libraries. In user
code this flexibility is rarely as useful. It may however be that this
very same argument was put forth when OO was introduced.


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Paulo Pinto

Am 17.03.2012 21:56, schrieb novice2:

How it come, that we build another abstartion level above strong typed
language?
Onece we builded high level language above assembler. Are we now
building another more high level? Will temlate will become another
language used as complete language? Will generic prigramming become
mainstream, like high level languages today?


Generic programming is already mainstream.

D, Delphi, C++, Java, Scala, Ada, C#, VB.Net, Haskell, OCaml, F#, Eiffel 
are just a few of the current languages that support generic programming.


--
Paulo


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Simen Kjærås
On Sat, 17 Mar 2012 22:16:37 +0100, Paulo Pinto pj...@progtools.org  
wrote:



Am 17.03.2012 21:56, schrieb novice2:

How it come, that we build another abstartion level above strong typed
language?
Onece we builded high level language above assembler. Are we now
building another more high level? Will temlate will become another
language used as complete language? Will generic prigramming become
mainstream, like high level languages today?


Generic programming is already mainstream.

D, Delphi, C++, Java, Scala, Ada, C#, VB.Net, Haskell, OCaml, F#, Eiffel  
are just a few of the current languages that support generic programming.


The languages support it. The hard part is getting programmers to use it.


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Simen Kjærås

On Sat, 17 Mar 2012 21:20:42 +0100, Nick Sabalausky a@a.a wrote:


I've spent a total of about 6 years in college, always got A's and B's in
the CS classes, and yet I'm convinced that programming classes are
completely and utterly useless. Most of the instructors themselves barely
even know how to code (among many, many other problems). So if you're
learning programming at college, then I'm not surprised you've gotten the
impression that nobody understands templates: Around universities, they
probably don't. (Also, it doesn't help that C++'s templates could be a  
lot better.)


I even had one CS prof, he said that the only language he knew was C. And
yet, after seeing his feedback on my code, it became abundantly clear to  
me that he didn't even understand how strings worked (ie: C's famous

null-terminated strings) *in the ONE language he knew*.


You seem to be harping on this a lot. My experience has been that
programming teachers generally know what they're doing, but they're not
exactly experts. Then again, like Paulo said, this might be a european
phenomenon.


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Paulo Pinto

Am 17.03.2012 22:19, schrieb Simen Kjærås:

On Sat, 17 Mar 2012 22:16:37 +0100, Paulo Pinto pj...@progtools.org
wrote:


Am 17.03.2012 21:56, schrieb novice2:

How it come, that we build another abstartion level above strong typed
language?
Onece we builded high level language above assembler. Are we now
building another more high level? Will temlate will become another
language used as complete language? Will generic prigramming become
mainstream, like high level languages today?


Generic programming is already mainstream.

D, Delphi, C++, Java, Scala, Ada, C#, VB.Net, Haskell, OCaml, F#,
Eiffel are just a few of the current languages that support generic
programming.


The languages support it. The hard part is getting programmers to use it.


I agree 100% with you.

Still I would like to remark, that at least from my work colleagues, the 
ones with problems to make proper use of algorithms and abstractions, 
are the ones without CS background.





Re: Proposal: user defined attributes

2012-03-17 Thread Manu
On 17 March 2012 21:56, Walter Bright newshou...@digitalmars.com wrote:

 On 3/16/2012 7:11 AM, Manu wrote:

 attribute myAttribute
 {
   this(int something);

   bool bNeedsAttention;

   property void refresh(bool bRefresh) { bNeedsAttention = bRefresh; }
 }

 @myAttribute(10) int thing;

 thing.refresh = true;


 Under the hood, where would that per-instance data be stored?

 Compile-time annotations can be stored internally to the compiler, but
 per-instance runtime data? How is it connected to the instance? When is it
 constructed and destroyed?


In Java+C# it just lives in the class somewhere. Put it right beside the
attributed member, or maybe separate them into an attribute section at the
end of the class (to preserve structural layout). Construct along with the
class, I suppose the moment would be after member initialisation, but
before the constructor executes.
I wonder if it should only be allowed on classes/class members... adding
hidden data to a 'struct' almost defeats the purpose. Java doesn't have
'struct', so no problem. I wonder what C# does exactly...


Re: Proposal: user defined attributes

2012-03-17 Thread Manu
On 17 March 2012 23:52, Manu turkey...@gmail.com wrote:

 On 17 March 2012 21:56, Walter Bright newshou...@digitalmars.com wrote:

 On 3/16/2012 7:11 AM, Manu wrote:

 attribute myAttribute
 {
   this(int something);

   bool bNeedsAttention;

   property void refresh(bool bRefresh) { bNeedsAttention = bRefresh; }
 }

 @myAttribute(10) int thing;

 thing.refresh = true;


 Under the hood, where would that per-instance data be stored?

 Compile-time annotations can be stored internally to the compiler, but
 per-instance runtime data? How is it connected to the instance? When is it
 constructed and destroyed?


 In Java+C# it just lives in the class somewhere. Put it right beside the
 attributed member, or maybe separate them into an attribute section at the
 end of the class (to preserve structural layout). Construct along with the
 class, I suppose the moment would be after member initialisation, but
 before the constructor executes.
 I wonder if it should only be allowed on classes/class members... adding
 hidden data to a 'struct' almost defeats the purpose. Java doesn't have
 'struct', so no problem. I wonder what C# does exactly...


I tend to think of 'struct's as 'passive', and compile-time annotations
would provide me with every use case I can imagine for my own purposes in
the case of structs. classes seem far more likely to need stateful
attributes.


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread H. S. Teoh
On Sat, Mar 17, 2012 at 10:13:44PM +0100, Paulo Pinto wrote:
 Am 17.03.2012 21:20, schrieb Nick Sabalausky:
[...]
 I've spent a total of about 6 years in college, always got A's and
 B's in the CS classes, and yet I'm convinced that programming classes
 are completely and utterly useless. Most of the instructors
 themselves barely even know how to code (among many, many other
 problems). So if you're learning programming at college, then I'm not
 surprised you've gotten the impression that nobody understands
 templates: Around universities, they probably don't. (Also, it
 doesn't help that C++'s templates could be a lot better.)
 
 I even had one CS prof, he said that the only language he knew was C.
 And yet, after seeing his feedback on my code, it became abundantly
 clear to me that he didn't even understand how strings worked (ie:
 C's famous null-terminated strings) *in the ONE language he knew*.
 
 
 I would say that most European universities seem to provide a
 completely different experience, at least speaking from my experience
 in Portuguese/Swiss/German ones.
[...]

My experience in a Canadian university wasn't quite that bad either.
True, there *were* some courses where the profs don't really care about
teaching, or where they're so self-absorbed that you can barely even
begin to understand where their sentences start and end, let alone
understand what they're trying to say. But I did have quite a few good
programming classes, notably one that got me started off with C, and
another that got me started with C++.

Of course, I also learned a lot more stuff about C/C++ that wasn't
taught in class, but then you can hardly expect the prof to teach you
*everything* there is to know about C/C++. After all, you're expected to
be an adult by then, and theoretically you'd know how to learn more on
your own.

Anyway.

Coming back to templates, I think Nick did an excellent job at
explaining them.

When learning something new in programming, I always like to ask, why is
feature X this way?  What is it used for? Why did people invent such a
thing in the first place? What was the motivation behind it? What does
it solve? What's so good about them that I have to learn this?

Templates are the result of a long history of trying to minimize the
amount of code you have to write/change when all you want is to add some
new data to existing code.

Suppose you have a program that needs to keep track of a list of
integers, say. There are, of course, many ways of doing this, but
suppose you chose to implement it as a linked list. So you write
something like this:

class Node {
Node next;
int data;
}
class LinkedList {
Node head;
Node tail;

void add(int data) {
Node n = new Node;
n.data = data;
... // insert node into list
}
void del(int data) {
...
}
}

So far so good. But what if later on, you realize that you need to store
not just an int, but also a float as well? So you'd have to go through
all that code, and add a new field wherever it's needed:

class Node {
Node  next;
int   intdata;
float floatdata;
}
class LinkedList {
Node head;
Node tail;

void add(int idata, float fdata) {
Node n = new Node;
n.intdata = idata;
n.floatdata = fdata;
... // insert node into list
}
void del(int data, float fdata) {
...
}
}

OK, that's a lot of code changes for something as simple as adding a
single field to your list nodes. What if you need a string next? You
have to go through the entire code and insert string fields and string
arguments everywhere. And what if you need something else after that?
Again, you have to go through all your code and update everything. (And
perhaps miss a few places, causing subtle bugs to creep into your
program.)

We can do better. We can encapsulate the data inside a separate struct
so that we don't have to keep changing Node and LinkedList every time we
need to store new data:

struct Data {
int intdata;
float floatdata;
}
class Node {
Node next;
Data data;  // ahhh, much better!
}
class LinkedList {
Node head;
Node tail;

void add(Data d) {
Node n = new Node;
n.data = d;
... // insert node into list
}
void del(Data d) {
...
}
}

Now, what if we need 

Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread H. S. Teoh
On Sat, Mar 17, 2012 at 10:15:26PM +0100, Simen Kjærås wrote:
 On Sat, 17 Mar 2012 21:56:14 +0100, novice2 so...@noem.ail wrote:
 
 How it come, that we build another abstartion level above strong
 typed language?
 Onece we builded high level language above assembler. Are we now
 building another more high level? Will temlate will become another
 language used as complete language? Will generic prigramming
 become mainstream, like high level languages today?
 
 It seems to me that templates are mostly useful for libraries. In user
 code this flexibility is rarely as useful. It may however be that this
 very same argument was put forth when OO was introduced.

I disagree. I use templates all the time, in my own code. It's a great
way to factor out common code, so that you avoid code duplication (which
often also means bug duplication).

For example, I'm writing a grid-based game, where I have a Board class
that stores an array of tiles representing game pieces. For various
reasons (not relevant here), I decided I should store the tiles as a
linear array, and just overload opIndex() to provide 2D access:

class Board {
Tile[] tiles;
int width, height;

Tile opIndex(int x, int y) {
return tile[offsetOf(x,y)];
}

private int offsetOf(int x, int y)
in { assert(x=0  xwidth  y=0  yheight); }
out(z) { assert(z=0  ztiles.length); }
body {
return x + y*width;
}
}

Later on, after I've implemented a working game, I decide to make the AI
player a bit smarter. For that, I decided to have the AI precompute
optimal movement paths by assigning an integer to each tile, and then
scanning the board to find optimal paths based on the ints assigned to
each tile.

I *could* add an int to Tile and use that, but the problem is, they are
only used during the pre-game computation by the AI; the computed paths
are stored separately after this computation is done, so the integers
are not needed during the actual gameplay. So storing the ints in Tile
is a waste of space.

So what I really need is a Board that stores ints instead of Tiles. But
the current Board class is already bound to Tile's! What can I do?

Aha! I can make Board a template:

class Board(T) {
T[] tiles;
int width, height;

T opIndex(int x, int y) { ... }
...
}

Then for the actual game board, I'd have:

Board!Tile gameboard;

And for the AI's precomputed data, I'd have:

Board!int aidata;

After the AI has found the optimal paths, I can discard aidata and
continue using gameboard.

Situations like this arise quite often in my code. So I'd say that
templates are definitely not limited to library code. They are generally
applicable.


T

-- 
Famous last words: I *think* this will work...


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread H. S. Teoh
On Sat, Mar 17, 2012 at 09:45:51PM +0100, Gour wrote:
 On Sat, 17 Mar 2012 21:29:18 +0100
 Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
 
  I had no idea what templates were when I started using D, and I
  thought I would never need to use them either. But now I use them
  extensively. They really become a natural tool in programming.
  They're so nice to use that I never have to reach for the big fat
  OOP monster, I can just write simple procedural code and use
  templates when I need some flexibility.
 
 Thank you for this paragraph. ;)
 
 I also consider to write procedural/functional code in my project and
 leave OOP behind, so it's nice to know that templates are the way to
 go.
[...]

I don't think you can discard OOP entirely. It still has its place IMO.
When you need runtime polymorphism, OOP is still the best tool for the
job.

But yeah, quite often you don't need full-fledged runtime polymorphism,
just a little compile-time flexibility (contrary to what the OO zealots
would have you believe). D templates are more than suitable for the job.
Using OO for this kind of thing just introduces unnecessary bloat and
slow performance.

(Not to mention, D templates can do some stuff that no OO can hope to
attain. But it goes both ways. Templates can't do runtime polymorphism
either.)


T

-- 
Sometimes the best solution to morale problems is just to fire all of the 
unhappy people. -- despair.com


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Jos van Uden

On 17-3-2012 21:20, Nick Sabalausky wrote:


Here's a little templates primer, I hope it helps:


[...]

Part of this primer would serve well as introduction
to Phillipe's tutorial, because it skips the basics.

(I knew the basics, but not everybody does.)

Jos



force inline/not-inline

2012-03-17 Thread Manu
I just started writing an emulator in D for some fun; I needed an
application to case-study aggressive performance characteristics in
hot-loop situations.
I know this has come up time and time again, but I just want to put it out
there again... if I were shipping this product, I would NEED forceinline +
force-not-inline.

I know D likes to try and intelligently inline code, but in these very high
performance cases, I know what's best for my code, and I have also shipped
this product commercially before. I know exactly what was required of it
from months of meticulous performance profiling, and I can see immediately
that D is not making the right choices. Programmers need to be able to
explicitly control to inline-ing in many cases.

Cross module inline-ing is a really big problem. What is the plan here? Is
there a solution in the foreseeable future? What about libs?


Re: force inline/not-inline

2012-03-17 Thread Alex Rønne Petersen

On 17-03-2012 23:53, Manu wrote:

I just started writing an emulator in D for some fun; I needed an
application to case-study aggressive performance characteristics in
hot-loop situations.
I know this has come up time and time again, but I just want to put it
out there again... if I were shipping this product, I would NEED
forceinline + force-not-inline.

I know D likes to try and intelligently inline code, but in these very
high performance cases, I know what's best for my code, and I have also
shipped this product commercially before. I know exactly what was
required of it from months of meticulous performance profiling, and I
can see immediately that D is not making the right choices. Programmers
need to be able to explicitly control to inline-ing in many cases.


Amen.



Cross module inline-ing is a really big problem. What is the plan here?
Is there a solution in the foreseeable future? What about libs?


--
- Alex


Re: force inline/not-inline

2012-03-17 Thread Andrej Mitrovic
On 3/17/12, Manu turkey...@gmail.com wrote:
 I just started writing an emulator in D for some fun

FWIW another dev did this http://code.google.com/p/pspemu/


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Entity325

Wow, popular thread is popular.

Thanks for all the help, everyone.  I haven't read all of it, but 
I will take the time to sift through everything and see what I 
can apply.


Response to some of what I did read:
-I didn't conclude that templates are confusing because they 
confused me.  I concluded templates are confusing because both of 
the D language reference pages which talk about them have quotes 
at the top talking about how confusing Templates are.  Reflecting 
on my (short!) experience trying to learn them, I merely 
concluded that templates are confusing because nobody really 
makes an effort to explain them cleanly.  Now, the effort has 
been made about 22 times(by my count) in this thread alone, so 
that's a plus!


-While most of my programming professors had a decent idea of 
what they were doing, the classes themselves left massive, gaping 
holes in my education that I never even realized were there until 
I got a job writing Java code.  I don't even particularly LIKE 
Java.


Could just be that I'm a slow learner.

I messed around with Templates after making that post and learned 
that they seem to behave similar to Generic types in Java(I am 
forever finding warnings that a generic type hasn't been type 
specified in our code.  Sometimes I fix it, sometimes I leave it 
alone)  I tried rewriting my structs to utilize templates(I 
currently have separate versions for float and int types) but 
that did little more than illustrate just how lost I was, so I 
switched back.  It should be possible in theory, the question is 
the practice.


Study was further set back by the fact that I suddenly realized 
none of my operator overloads are working... at all.  It looks 
like it checks with the language reference page, but I think it's 
time to write another toy-sized learning program.


Re: force inline/not-inline

2012-03-17 Thread Manu
On 18 March 2012 01:51, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:

 On 3/17/12, Manu turkey...@gmail.com wrote:
  I just started writing an emulator in D for some fun

 FWIW another dev did this http://code.google.com/p/pspemu/


Yeah, I've seen that. But it's a PC app, and JITs. Different application.
If I tried to run this on a phone (or an xbox) without strict inline
control, I lose a lot of performance.

I'm not saying it's urgent, just that it's important.


Re: OpenBSD port of dmd?

2012-03-17 Thread Alix Pexton

On 17/03/2012 16:43, Andrei Alexandrescu wrote:

On 3/17/12 9:10 AM, Sean Kelly wrote:

Pretty much. I'd expect to see:

version (linux) {
// optimized impl
} else version (OSX) {
version = UseDefault;
} else {
static assert(false, unknown platform);
}
version (UseDefault) {
...
}


Taking this to its logical conclusion means that _all_ code that is
currently unguarded must be guarded by version (UseDefault).

Andrei




Firstly, I don't think the name UseDefault was well chosen for this 
example. I don't think its meant to be a catch all for every occasion 
when version statements are used. Perhaps NoFeatureXyzIntrinsic would 
be clearer.


Secondly, if every line of D code is potentially platform-specific 
and/or inherently inefficient unless optimised with some case specific 
intrinsic, then there must be some glaring problems with the 
abstractions that the language provides.


I will also reiterate that I believe that there are 2 different cases 
being considered together here.
_Compatibility_, where asserting in the else of a version statement is 
the best course of action.
_Opportunistic-Optimisation_, where providing a default case in the else 
as a fall back is quite sensible.


The scenario which applies can often be easily deduced, it is my 
experience that optimisations are versioned-in while incompatibilities 
are versioned-out.
i.e. Adding a platform specific optimisation is versioning-in, and the 
prior platform agnostic code becomes the default. Proofing a platform 
specific module is versioning-out removing inapplicable code and 
leaving a note for the maintainer that other platforms will require 
their own implementation.


In the cases where the programmer does not have enough knowledge to know 
which scenario applies (perhaps not knowing if a particular intrinsic 
has compatible implementations across all platforms), I find it hard to 
find any argument in favour of providing a default action that may have 
unknown effects on another system.


A...


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Nick Sabalausky
H. S. Teoh hst...@quickfur.ath.cx wrote in message 
news:mailman.834.1332023905.4860.digitalmar...@puremagic.com...

 (Not to mention, D templates can do some stuff that no OO can hope to
 attain. But it goes both ways. Templates can't do runtime polymorphism
 either.)


Combined with compile-time reflection, I'm sure they could be used to create 
a runtime polymorphism tool, even multiple dispatch. Like I mentioned 
recently in a seperate thread, you'd just need to use templates/ctfe to 
automate/genericize this:

void singleDispatch(Object o)
{
if(auto derived = cast(DerivedClassA)o)
derived.foo();
else if(auto derived = cast(DerivedClassB)o)
derived.foo();
else if(auto derived = cast(DerivedClassC)o)
derived.foo();
//etc...
}

Although I guess *technically* you're still relying on OO polymorphism (in 
the form of downcasting) to achieve this. OTOH, you could still base it on 
Variant or Algebraic instead of (or in addition to) Object. Then you'd have 
built runtime polymorphism out of templates (among other things) without 
relying on OO.




Re: OpenBSD port of dmd?

2012-03-17 Thread Sean Kelly
In truth it would be

else version (Posix)

Anyway, which isn't the bare else Walter was advising against. 

On Mar 17, 2012, at 5:10 PM, Alix Pexton alix.dot.pex...@gmail.dot.com wrote:

 On 17/03/2012 16:43, Andrei Alexandrescu wrote:
 On 3/17/12 9:10 AM, Sean Kelly wrote:
 Pretty much. I'd expect to see:
 
 version (linux) {
 // optimized impl
 } else version (OSX) {
 version = UseDefault;
 } else {
 static assert(false, unknown platform);
 }
 version (UseDefault) {
 ...
 }
 
 Taking this to its logical conclusion means that _all_ code that is
 currently unguarded must be guarded by version (UseDefault).
 
 Andrei
 
 
 
 Firstly, I don't think the name UseDefault was well chosen for this 
 example. I don't think its meant to be a catch all for every occasion when 
 version statements are used. Perhaps NoFeatureXyzIntrinsic would be clearer.
 
 Secondly, if every line of D code is potentially platform-specific and/or 
 inherently inefficient unless optimised with some case specific intrinsic, 
 then there must be some glaring problems with the abstractions that the 
 language provides.
 
 I will also reiterate that I believe that there are 2 different cases being 
 considered together here.
 _Compatibility_, where asserting in the else of a version statement is the 
 best course of action.
 _Opportunistic-Optimisation_, where providing a default case in the else as a 
 fall back is quite sensible.
 
 The scenario which applies can often be easily deduced, it is my experience 
 that optimisations are versioned-in while incompatibilities are 
 versioned-out.
 i.e. Adding a platform specific optimisation is versioning-in, and the 
 prior platform agnostic code becomes the default. Proofing a platform 
 specific module is versioning-out removing inapplicable code and leaving a 
 note for the maintainer that other platforms will require their own 
 implementation.
 
 In the cases where the programmer does not have enough knowledge to know 
 which scenario applies (perhaps not knowing if a particular intrinsic has 
 compatible implementations across all platforms), I find it hard to find any 
 argument in favour of providing a default action that may have unknown 
 effects on another system.
 
 A...


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread H. S. Teoh
On Sat, Mar 17, 2012 at 08:37:35PM -0400, Nick Sabalausky wrote:
 H. S. Teoh hst...@quickfur.ath.cx wrote in message 
 news:mailman.834.1332023905.4860.digitalmar...@puremagic.com...
 
  (Not to mention, D templates can do some stuff that no OO can hope
  to attain. But it goes both ways. Templates can't do runtime
  polymorphism either.)
 
 
 Combined with compile-time reflection, I'm sure they could be used to
 create a runtime polymorphism tool, even multiple dispatch. Like I
 mentioned recently in a seperate thread, you'd just need to use
 templates/ctfe to automate/genericize this:
 
 void singleDispatch(Object o)
 {
 if(auto derived = cast(DerivedClassA)o)
 derived.foo();
 else if(auto derived = cast(DerivedClassB)o)
 derived.foo();
 else if(auto derived = cast(DerivedClassC)o)
 derived.foo();
 //etc...
 }
 
 Although I guess *technically* you're still relying on OO polymorphism
 (in the form of downcasting) to achieve this. OTOH, you could still
 base it on Variant or Algebraic instead of (or in addition to) Object.
 Then you'd have built runtime polymorphism out of templates (among
 other things) without relying on OO.
[...]

But now you're just reimplementing OO in terms of templates. :-) You can
do OO in C, too. (In fact, at work some of the C code I deal with are
approximations to OO.) That has nothing to do with templates themselves
per se.


T

-- 
He who does not appreciate the beauty of language is not worthy to bemoan its 
flaws.


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Nick Sabalausky
Entity325 lonewolf...@gmail.com wrote in message 
news:vxadflowsujbbmpnr...@forum.dlang.org...

 -While most of my programming professors had a decent idea of what they 
 were doing, the classes themselves left massive, gaping holes in my 
 education that I never even realized were there until I got a job writing 
 Java code.  I don't even particularly LIKE Java.


IMHO, that means you're smart :)

But you touched on an interesting thing about learning and knowledge: It's 
difficult to know how much is out there that you don't know. After all, if 
you're unaware of it, then how *can* you know that you're unaware of it? 
Arguably, one measure of personal progress is how much you suddenly realze 
there is that you *don't* know and didn't know.

As amateurs, we're opened up to a new world and tend to feel like we know 
everything about the subject and can do anything with it. Then as we 
progress we learn how much there really is left to learn. Sort of Zen or 
Tao, really.

 I messed around with Templates after making that post and learned that 
 they seem to behave similar to Generic types in Java

Definitely. Generic types in language like Java can be thought of as one 
specific special case of templates. Templates are a good way to do generic 
types, but then they can *also* do a lot more than just types.




Re: OpenBSD port of dmd?

2012-03-17 Thread Walter Bright

On 3/17/2012 5:40 PM, Sean Kelly wrote:

In truth it would be

else version (Posix)

Anyway, which isn't the bare else Walter was advising against.


And is Posix really predictably compatible across diverse systems?


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Nick Sabalausky
Simen Kjærås simen.kja...@gmail.com wrote in message 
news:op.wbb24i010gp...@biotronic.lan...
 On Sat, 17 Mar 2012 21:20:42 +0100, Nick Sabalausky a@a.a wrote:

 I've spent a total of about 6 years in college, always got A's and B's in
 the CS classes, and yet I'm convinced that programming classes are
 completely and utterly useless. Most of the instructors themselves barely
 even know how to code (among many, many other problems). So if you're
 learning programming at college, then I'm not surprised you've gotten the
 impression that nobody understands templates: Around universities, they
 probably don't. (Also, it doesn't help that C++'s templates could be a 
 lot better.)

 I even had one CS prof, he said that the only language he knew was C. And
 yet, after seeing his feedback on my code, it became abundantly clear to 
 me that he didn't even understand how strings worked (ie: C's famous
 null-terminated strings) *in the ONE language he knew*.

 You seem to be harping on this a lot.

Sorry. I definitely *do* have a big chip on my shoulder on the matter.




Re: OpenBSD port of dmd?

2012-03-17 Thread Bernard Helyer

On Sunday, 18 March 2012 at 00:53:17 UTC, Walter Bright wrote:

On 3/17/2012 5:40 PM, Sean Kelly wrote:

In truth it would be

else version (Posix)

Anyway, which isn't the bare else Walter was advising against.


And is Posix really predictably compatible across diverse 
systems?


If you restrict yourself to the LCD stuff, yeah mostly. The 
trouble is you get various nicer ways of doing things that aren't 
(as) portable.


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Nick Sabalausky
H. S. Teoh hst...@quickfur.ath.cx wrote in message 
news:mailman.839.1332031513.4860.digitalmar...@puremagic.com...
 On Sat, Mar 17, 2012 at 08:37:35PM -0400, Nick Sabalausky wrote:
 H. S. Teoh hst...@quickfur.ath.cx wrote in message
 news:mailman.834.1332023905.4860.digitalmar...@puremagic.com...
 
  (Not to mention, D templates can do some stuff that no OO can hope
  to attain. But it goes both ways. Templates can't do runtime
  polymorphism either.)
 

 Combined with compile-time reflection, I'm sure they could be used to
 create a runtime polymorphism tool, even multiple dispatch. Like I
 mentioned recently in a seperate thread, you'd just need to use
 templates/ctfe to automate/genericize this:

 void singleDispatch(Object o)
 {
 if(auto derived = cast(DerivedClassA)o)
 derived.foo();
 else if(auto derived = cast(DerivedClassB)o)
 derived.foo();
 else if(auto derived = cast(DerivedClassC)o)
 derived.foo();
 //etc...
 }

 Although I guess *technically* you're still relying on OO polymorphism
 (in the form of downcasting) to achieve this. OTOH, you could still
 base it on Variant or Algebraic instead of (or in addition to) Object.
 Then you'd have built runtime polymorphism out of templates (among
 other things) without relying on OO.
 [...]

 But now you're just reimplementing OO in terms of templates. :-) You can
 do OO in C, too. (In fact, at work some of the C code I deal with are
 approximations to OO.) That has nothing to do with templates themselves
 per se.


I'd argue: To view that (particularly if using Variants) as reimplementing 
OO, is to blur the distinction between OO and polymorphism. OO is such a 
popular form of polymorphism that we're conditioned to look at polymorphism 
and say Oh, that's OO. Really, OO is just one way of doing polymorphism. 
You define a class. You define a subclass and override its methods. Etc. 
Other forms of polymorphism exist, such as defining over*loads* and 
dispatching to them based on the type in a Variant - which, AIUI, is what 
some non-OO polymorphic languages do behind-the-scenes (though I could be 
wrong). Uhh, i *think* ML is one such example. Anyway, these other types of 
polymorphism can easily look like OO because, since they're all just forms 
of polymorphism, they look like they're just variations on the same 
fundamental thing. And that's because they are just variations on the same 
fundamental thing: polymorphism.




Re: Proposal: user defined attributes

2012-03-17 Thread Walter Bright

On 3/17/2012 2:55 PM, Manu wrote:

I tend to think of 'struct's as 'passive', and compile-time annotations would
provide me with every use case I can imagine for my own purposes in the case of
structs. classes seem far more likely to need stateful attributes.


I currently find the notion of runtime attribute state to be fraught with all 
kinds of unresolved and murky issues with no obvious answer:


1. construction/destruction
2. shared
3. const/immutable
4. thread locality
5. allocated statically or dynamically
6. shared library issues?

If the attribute is code, when does that code get run?

1. on initialization
2. on termination
3. on read
4. on write
5. what about read/write?


Re: Understanding Templates: why can't anybody do it?

2012-03-17 Thread Nick Sabalausky
novice2 so...@noem.ail wrote in message 
news:hzbmfpsyzezjwzshx...@forum.dlang.org...
 How it come, that we build another abstartion level above strong typed 
 language?
 Onece we builded high level language above assembler. Are we now building 
 another more high level? Will temlate will become another language used as 
 complete language? Will generic prigramming become mainstream, like high 
 level languages today?

It's really just another tool in the toolbox. Like OO.

And there's always more abstractions on top of abstractions: High-level 
langauges are an abstration on top of low-level. Low level programming is an 
abstration on top of digital hardware. Digital hardware is an abstraction on 
top of analog hardware. Analog hardware is an abstraction on top of 
chemistry. Chemistry is an abstration on top of natural observations of 
interacting with various materials. Observations are an abstraction on top 
of our perceptions of reality and sensory input.

First we discover useful things to do with one abstraction. Then we make use 
of that abstraction to the point where it starts to get complex. So we look 
for patterns in the complexity and use those patterns as the foundation for 
a new abstraction to make these complicated new things simple. And it starts 
again. Sending a link to a document across the world is trivial today, but 
it would be unthinkably complex without the abstractions of high level code, 
low level code, digital hardware, etc.




virtual-by-default rant

2012-03-17 Thread Manu
The virtual model broken. I've complained about it lots, and people always
say stfu, use 'final:' at the top of your class.

That sounds tolerable in theory, except there's no 'virtual' keyword to
keep the virtual-ness of those 1-2 virtual functions I have... so it's no
good (unless I rearrange my class, breaking the logical grouping of stuff
in it).
So I try that, and when I do, it complains: Error: variable
demu.memmap.MemMap.machine final cannot be applied to variable, allegedly
a D1 remnant.
So what do I do? Another workaround? Tag everything as final individually?

My minimum recommendation: D needs an explicit 'virtual' keyword, and to
fix that D1 bug, so putting final: at the top of your class works, and
everything from there works as it should.


Re: Proposal: user defined attributes

2012-03-17 Thread Manu
On 18 March 2012 03:10, Walter Bright newshou...@digitalmars.com wrote:

 On 3/17/2012 2:55 PM, Manu wrote:

 I tend to think of 'struct's as 'passive', and compile-time annotations
 would
 provide me with every use case I can imagine for my own purposes in the
 case of
 structs. classes seem far more likely to need stateful attributes.


 I currently find the notion of runtime attribute state to be fraught with
 all kinds of unresolved and murky issues with no obvious answer:

 1. construction/destruction


After initialisation, before construction.

2. shared


How is this any different than for the class its self?

3. const/immutable


Inherit these properties.

4. thread locality


Same as class.

5. allocated statically or dynamically


I'd say dynamically if restricted to classes, but some suggested the syntax
'@attribute struct/class MyAttribute { }', which could clarify the intent.

6. shared library issues?


If extern(D), then there should be no problems. If extern(C), then the
attributes would just appear like structure members. Assuming the layout
was documented (ie, in-order of appearance, at the end of the class), C/C++
could include them at the end of the class definition, and access them
directly as if usual classes. All that would be lost is the implicit
(compile time) association between the attribute and its associated class
member.
I don't think it's fair to expect a novel language feature to be supported
by C/C++ though.


If the attribute is code, when does that code get run?

 1. on initialization
 2. on termination
 3. on read
 4. on write
 5. what about read/write?


I might go and read up on C# more thoroughly and get back to you... maybe
others here are already more familiar with C#'s attribute management?
I'm sure C# already answers all these questions. It has precisely the same
set of issues associated.


Re: virtual-by-default rant

2012-03-17 Thread Bernard Helyer

On Sunday, 18 March 2012 at 01:23:42 UTC, Manu wrote:
My minimum recommendation: D needs an explicit 'virtual' 
keyword, and to
fix that D1 bug, so putting final: at the top of your class 
works, and

everything from there works as it should.


Agreed. Final by default is a proposition long gone, but that 
seems reasonable.


Re: virtual-by-default rant

2012-03-17 Thread Simen Kjærås

On Sun, 18 Mar 2012 02:23:31 +0100, Manu turkey...@gmail.com wrote:

The virtual model broken. I've complained about it lots, and people  
always

say stfu, use 'final:' at the top of your class.

That sounds tolerable in theory, except there's no 'virtual' keyword to
keep the virtual-ness of those 1-2 virtual functions I have... so it's no
good (unless I rearrange my class, breaking the logical grouping of stuff
in it).
So I try that, and when I do, it complains: Error: variable
demu.memmap.MemMap.machine final cannot be applied to variable,  
allegedly

a D1 remnant.
So what do I do? Another workaround? Tag everything as final  
individually?


class Foo {
final {
// Final functions here.
}
// Virtual functions here.
}

Good?



My minimum recommendation: D needs an explicit 'virtual' keyword, and to
fix that D1 bug, so putting final: at the top of your class works, and
everything from there works as it should.


I agree that a virtual keyword would sometimes be a boon. With the solution
outlined above, I find it a minor nit, though.


Re: Proposal: user defined attributes

2012-03-17 Thread Walter Bright

On 3/17/2012 6:39 PM, Manu wrote:

I'm sure C# already answers all these questions. It has precisely the same set
of issues associated.


C# doesn't have RAII, immutable, nor the notion of threadlocal/shared types.


  1   2   >