String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread Lucas Burson via Digitalmars-d-learn
When creating a string from a ubyte[], I have an invalid length 
and string.strip() doesn't strip off all whitespace. I'm new to 
the language. Is this a compiler issue?



import std.string : strip;
import std.stdio  : writefln;

int main()
{
   const string ATA_STR =  ATA ;

   // this works fine
   {
  ubyte[] buffer = [' ', 'A', 'T', 'A', ' ' ];
  string test = strip(cast(string)(buffer));
  assert(test == strip(ATA_STR));
   }

   // This is where things breaks
   {
  ubyte[] buff = new ubyte[16];
  buff[0..ATA_STR.length] = cast(ubyte[])(ATA_STR);

  // read the string back from the buffer, stripping 
whitespace

  string stringFromBuffer = strip(cast(string)(buff[0..16]));
  // this shows strip() doesn't remove all whitespace
  writefln(StrFromBuff is '%s'; length %d, 
stringFromBuffer, stringFromBuffer.length);


  // !! FAILS. stringFromBuffer is length 15, not 3.
  assert(stringFromBuffer.length == strip(ATA_STR).length);

   }

   return 0;
}


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread thedeemon via Digitalmars-d-learn

On Friday, 17 October 2014 at 06:29:24 UTC, Lucas Burson wrote:


   // This is where things breaks
   {
  ubyte[] buff = new ubyte[16];
  buff[0..ATA_STR.length] = cast(ubyte[])(ATA_STR);

  // read the string back from the buffer, stripping 
whitespace
  string stringFromBuffer = 
strip(cast(string)(buff[0..16]));

  // this shows strip() doesn't remove all whitespace
  writefln(StrFromBuff is '%s'; length %d, 
stringFromBuffer, stringFromBuffer.length);


  // !! FAILS. stringFromBuffer is length 15, not 3.
  assert(stringFromBuffer.length == strip(ATA_STR).length);


Unlike C, strings in D are not zero-terminated by default, they 
are just arrays, i.e. a pair of pointer and size. You create an 
array of 16 bytes and cast it to string, now you have a 16-chars 
string. You fill first few chars with data from ATA_STR but the 
rest 10 bytes of the array are still part of the string, not 
initialized with data, so having zeroes. Since this tail of 
zeroes is not whitespace (tabs or spaces etc.) 'strip' doesn't 
remove it.




Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread thedeemon via Digitalmars-d-learn

You fill first few chars with data from
ATA_STR but the rest 10 bytes of the array are still part of 
the string


Edit: you fill first 5 chars and have 11 bytes of zeroes in the 
tail. My counting skill is too bad. ;)


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread spir via Digitalmars-d-learn

On 17/10/14 07:38, maarten van damme via Digitalmars-d-learn wrote:

While d can be complex, there's nothing preventing you from starting out
simple and not using all features at first.
I don't understand why it's not suitable for a beginner if you use this
approach...


For some reasons, in my view: A beginner has to learn programming in addition to 
a first lang. A beginner has to learn a first lang in addition to programming. 
We learn languages by understanding valid, meaningful input, ie here reading 
code. All static langs introduce tons of complication only due to their 
staticity. D is rather big  complex, in the field of static langs. Most code 
will use more than a theoretical minimal set of features. And this minimal set 
is far more in size, difficulty, complication than in langs partly designed  for 
ease of learning (Lua, Python, Scheme...). Even plain C is far more difficult 
than say, Lua.


d



Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread via Digitalmars-d-learn
On Friday, 17 October 2014 at 05:38:51 UTC, maarten van damme via 
Digitalmars-d-learn wrote:
While d can be complex, there's nothing preventing you from 
starting out

simple and not using all features at first.
I don't understand why it's not suitable for a beginner if you 
use this

approach...


Anything that keeps you motivated is suitable, but for a beginner 
the goal should not be to  learn a language, but to learn 
programming principles and learn how to write clean programs.


Using a more uniform language that is suitable for teaching is 
better, and provides more educational resources. Where would you 
go to find examples of clean programming in D/C++?


For the first few weeks getting instant feedback from a REPL is 
gratifying and being constrained by a functional/recursive 
paradigm is good. Getting instant visual feedback is motivating 
and makes it easy to see where you go wrong. Nice for the first 
steps if you are a visual person.


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread spir via Digitalmars-d-learn

On 17/10/14 03:05, ketmar via Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 00:52:14 +
MachineCode via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:


I don't understand. If at least it were C but java? why not D
itself?

C is *awful* as beginner's language. never ever let people start with
C if you don't hate 'em.

as for D... current version of D can be used, but with some
precautions. we now have excellent book by Ali. (it's great, really! i
believe that it must be featured on the front dlang.org page!) but java
has alot more books and tutorials.

not that D is bad for beginners, it's just has a smaller userbase. and
all that things with classes are reference types and structs are not,
empty array is not empty array but is empty array and so on D may be
confusing a little. it's good to have some CS background to understood
that things.


What you say here applies, I guess, to many other points. I applaud Ali for 
writing a tutorial like his but... Check it (just the first pages is enough) for 
literally the dozens of notions one must know and master for being able to 
understand, not only the features of D introduced, but even the tutorial itself. 
If I am not a programmer, and one who knows other static langs, and better of 
the mainstream procedural paradigm, if not D itself, then I do not understand 
more than few isolated words here and there. We are blind to the huge pile of 
concepts we know, I guess, because we know them, thus take them for granted...


d


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread spir via Digitalmars-d-learn

On 17/10/14 09:29, thedeemon via Digitalmars-d-learn wrote:

On Friday, 17 October 2014 at 06:29:24 UTC, Lucas Burson wrote:


   // This is where things breaks
   {
  ubyte[] buff = new ubyte[16];
  buff[0..ATA_STR.length] = cast(ubyte[])(ATA_STR);

  // read the string back from the buffer, stripping whitespace
  string stringFromBuffer = strip(cast(string)(buff[0..16]));
  // this shows strip() doesn't remove all whitespace
  writefln(StrFromBuff is '%s'; length %d, stringFromBuffer,
stringFromBuffer.length);

  // !! FAILS. stringFromBuffer is length 15, not 3.
  assert(stringFromBuffer.length == strip(ATA_STR).length);


Unlike C, strings in D are not zero-terminated by default, they are just arrays,
i.e. a pair of pointer and size. You create an array of 16 bytes and cast it to
string, now you have a 16-chars string. You fill first few chars with data from
ATA_STR but the rest 10 bytes of the array are still part of the string, not
initialized with data, so having zeroes. Since this tail of zeroes is not
whitespace (tabs or spaces etc.) 'strip' doesn't remove it.


Side-note: since your string has those zeroes at the end, strip only removes the 
space at start (thus, final size=15), instead of at both ends.


d



Re: Any dub tips and tricks

2014-10-17 Thread Atila Neves via Digitalmars-d-learn
Are you sure your package/dub.json is valid JSON? You can check 
it here:


http://jsonlint.com/

Atila

On Thursday, 16 October 2014 at 22:22:14 UTC, Joel wrote:
Any way of using dub (on Windows or OSX). I've been trying it 
lately, but not much success.


1. (In the command prompt or Terminal), I create a new folder.
2. Run 'dub init' in the new folder
3. I copy the dependency from a lib/app into the dub.json file.
4. Then I just enter 'dub'

In Windows I get this error (and others, but seems to go 
through): Failed to parse package description for dil  in 
C:\Users\Joel\AppData\Roaming\dub\packages\dil-master\.


I'm more interested in using OSX, for D.




Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread bearophile via Digitalmars-d-learn

Ola Fosheim Grøstad:


The IDE support is probably a bit better with Java/C#


The importance of the IDE for the first language is 
controversial. I think it's not so important.



and using a statically typed language as your first language 
has advantages,


While no one has determined scientifically that you are right, I 
too believe that static typing has some advantages for a first 
language. I think there are no perfect first languages.


Bye,
bearophile


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread Paulo Pinto via Digitalmars-d-learn
On Friday, 17 October 2014 at 01:05:37 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 00:52:14 +
MachineCode via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:

I don't understand. If at least it were C but java? why not D 
itself?
C is *awful* as beginner's language. never ever let people 
start with

C if you don't hate 'em.

as for D... current version of D can be used, but with some
precautions. we now have excellent book by Ali. (it's great, 
really! i
believe that it must be featured on the front dlang.org page!) 
but java

has alot more books and tutorials.

not that D is bad for beginners, it's just has a smaller 
userbase. and
all that things with classes are reference types and structs 
are not,
empty array is not empty array but is empty array and so on D 
may be
confusing a little. it's good to have some CS background to 
understood

that things.

just my cent and cent.



Better, go with FreePascal http://www.freepascal.org/ and 
discover all that those features that many C advocates spread as 
being close to the machine and other C only features, aren't 
exclusive of it.


Alongside support for real modules, OO and genericity.

Then with a head clean of bad C influences, jump into D.


--
Paulo


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread via Digitalmars-d-learn

On Friday, 17 October 2014 at 08:33:46 UTC, bearophile wrote:

The IDE support is probably a bit better with Java/C#


The importance of the IDE for the first language is 
controversial. I think it's not so important.


Perhaps it depends on the person and the language, but I would 
think autocompletion hints and getting visual cues of syntax 
errors important.


Error messages with line numbers can be overwhelming, hard to 
understand and discourage experimentation. Newbies often make 
many syntactical errors.


Even when doing interactive stuff in python I find ipython a lot 
more convenient than regular python. Insepecting a class by 
hitting tab is very useful for learning I think.


and using a statically typed language as your first language 
has advantages,


While no one has determined scientifically that you are right, 
I too believe that static typing has some advantages for a 
first language. I think there are no perfect first languages.


That's probably right, because motivation is the most important 
factor. So even matlab can be a nice environment for learning if 
it fits your interests.


In general I think Dart could turn into a nice language for 
beginners. It is dynamic and a bit forgiving, but has static 
checking and you can see the results right in your browser (and 
debug it). But I think the IDE should be mandatory…




Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread Chris via Digitalmars-d-learn

On Thursday, 16 October 2014 at 22:26:51 UTC, RBfromME wrote:
I'm a newbie to programming and have been looking into the D 
lang as a general purposing language to learn, yet the D 
overview indicates that java would be a better language to 
learn for your first programming language. Why?  Looks like D 
is easier than Java...


I agree with Ali. Give it a try, you don't need to use all the 
fancy features of D, features you only come to appreciate after 
years of programming (especially in other languages like Java, 
that are very restrictive).


In D you can start out with very simple code like

import std.stdio;

void main() {
  auto i = 5;
  auto j = 2;
  auto sum = 5 + 2;
  writeln(sum);  // prints 7 to console
}

In Java you already need a lot of boiler plate code for this (a 
class for main(), i.e. you have to understand object-orientation 
to begin with!).


If D is too difficult for you, because the tutorials etc. assume 
that you already know how to program (to a certain extent), you 
can either ask people on the forum or try a simpler language 
for which there are very basic tutorials, and come back to D 
later, once you've grasped enough of the concepts that are common 
to all programming languages.


An instantly rewarding language is Lua (lua.org). It was 
designed for people with no programming background, yet it is 
very fast and powerful (it's used in gaming a lot). It has some 
advanced features too (e.g. meta-programming), if you _choose_ to 
use them (it's not a scripting for dummies language).


Personally, I wouldn't recommend an IDE for beginners. It can be 
confusing at times and even worse, it may spoil you as regards 
coding habits. The best way to get familiar with a language or 
coding in general is to use a simple text editor, type everything 
yourself (at the beginning), and soon it will become second 
nature to you. It's like learning an instrument, on the one hand 
you have to practise scales and patterns, and on the other hand 
you have to learn concepts (chords, chord progressions, 
harmonies). In order to be able to grasp the concepts, your brain 
shouldn't be concerned with what your fingers are doing, the 
fingers should move automatically (so that you can listen to 
yourself).


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 10:10:09 +0200
spir via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 What you say here applies, I guess, to many other points. I applaud
 Ali for writing a tutorial like his but... Check it (just the first
 pages is enough) for literally the dozens of notions one must know
 and master for being able to understand, not only the features of D
 introduced, but even the tutorial itself. If I am not a programmer,
 and one who knows other static langs, and better of the mainstream
 procedural paradigm, if not D itself, then I do not understand more
 than few isolated words here and there. We are blind to the huge pile
 of concepts we know, I guess, because we know them, thus take them
 for granted...
that's why i'm sure that basic programming must be teached in school.
hey, the whole our civilization will collapse without computers!
computer programming is the literacy of the new age.


signature.asc
Description: PGP signature


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 04:51:14 +
via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 I personally think Logo, Processing and Scheme would be more fun 
 as learning tools, but they are throw-away languages.
yet Scheme will teach how to write functional code. it's a valuable
knowledge for D programmer.


signature.asc
Description: PGP signature


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 13:13:36 +
Kagamin via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 In IDE you press F5 and see the program running.
with REPL you typing code, pressing enter and see the code running.


signature.asc
Description: PGP signature


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread Jessica Rauth via Digitalmars-d-learn

On Friday, 17 October 2014 at 08:44:00 UTC, Paulo  Pinto wrote:
On Friday, 17 October 2014 at 01:05:37 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 00:52:14 +
MachineCode via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:

I don't understand. If at least it were C but java? why not D 
itself?
C is *awful* as beginner's language. never ever let people 
start with

C if you don't hate 'em.

as for D... current version of D can be used, but with some
precautions. we now have excellent book by Ali. (it's great, 
really! i
believe that it must be featured on the front dlang.org page!) 
but java

has alot more books and tutorials.

not that D is bad for beginners, it's just has a smaller 
userbase. and
all that things with classes are reference types and structs 
are not,
empty array is not empty array but is empty array and so on 
D may be
confusing a little. it's good to have some CS background to 
understood

that things.

just my cent and cent.



Better, go with FreePascal http://www.freepascal.org/ and 
discover all that those features that many C advocates spread 
as being close to the machine and other C only features, aren't 
exclusive of it.


Alongside support for real modules, OO and genericity.

Then with a head clean of bad C influences, jump into D.


--
Paulo


One of the problem when starting out with FPC resides in the fact 
that's a completely different family of language (Ada, Pascal, 
Modula vs the C family), syntax and philosophy (for example in 
the RTL).


Another one is that usually people use it in combination with 
Lazarus and as the RAD concept is no shit, people start building 
some applications very fastly. Then when they come to another 
lang. eg D or Cpp they take a big slap in the face. The fact is 
that Obj. Pascal and Delphi often give a wrong appreciation of 
its own skills and abilities.


You talk about genericity but the genericity in Object Pascal is 
currently almost inexistant and doesn't provide a good idea of 
what template-meta-programming is. Actually this looks more 
like a patch to the lang. and some simple things just like 
casting a generic type or global generic functions simply don't 
work at all. While D2 has been written with this idea, FPC will 
never be good with TMP. Even in the commercial version (Delphi 
XE7) they start to add some kind of patchs eg with a compiler 
instrasic which is equivalent to D static if (which means that 
the lang. is not designed for that at all).


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 16 October 2014 at 22:26:51 UTC, RBfromME wrote:
I'm a newbie to programming and have been looking into the D 
lang as a general purposing language to learn, yet the D 
overview indicates that java would be a better language to 
learn for your first programming language. Why?  Looks like D 
is easier than Java...


The answer is that teaching material for a very beginner is 
limited at the time of that writing we didn't have Ali's book.


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

Feel free to give it a try and let the community know things you 
struggled with.


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread eles via Digitalmars-d-learn
On Friday, 17 October 2014 at 13:59:03 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 10:10:09 +0200
spir via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:



computer programming is the literacy of the new age.


Let's say, computer knowledge. There are also database 
administrators, package maintainers, network administrators etc. 
Knowledge of all is useful, not only the knowledge of programmers.


Add builders, engineers, loggers (those with axes) and medics to 
the list...


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 14:33:57 +
eles via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 On Friday, 17 October 2014 at 13:59:03 UTC, ketmar via 
 Digitalmars-d-learn wrote:
  On Fri, 17 Oct 2014 10:10:09 +0200
  spir via Digitalmars-d-learn 
  digitalmars-d-learn@puremagic.com wrote:
 
  computer programming is the literacy of the new age.
 
 Let's say, computer knowledge.

yes, you are right. that was what i mean: not only programming, but
understanding of how computers works and how to control them.


signature.asc
Description: PGP signature


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread Lucas Burson via Digitalmars-d-learn
On Friday, 17 October 2014 at 08:31:04 UTC, spir via 
Digitalmars-d-learn wrote:

On 17/10/14 09:29, thedeemon via Digitalmars-d-learn wrote:

On Friday, 17 October 2014 at 06:29:24 UTC, Lucas Burson wrote:


  // This is where things breaks
  {
 ubyte[] buff = new ubyte[16];
 buff[0..ATA_STR.length] = cast(ubyte[])(ATA_STR);

 // read the string back from the buffer, stripping 
whitespace
 string stringFromBuffer = 
strip(cast(string)(buff[0..16]));

 // this shows strip() doesn't remove all whitespace
 writefln(StrFromBuff is '%s'; length %d, 
stringFromBuffer,

stringFromBuffer.length);

 // !! FAILS. stringFromBuffer is length 15, not 3.
 assert(stringFromBuffer.length == strip(ATA_STR).length);


Unlike C, strings in D are not zero-terminated by default, 
they are just arrays,
i.e. a pair of pointer and size. You create an array of 16 
bytes and cast it to
string, now you have a 16-chars string. You fill first few 
chars with data from
ATA_STR but the rest 10 bytes of the array are still part of 
the string, not
initialized with data, so having zeroes. Since this tail of 
zeroes is not

whitespace (tabs or spaces etc.) 'strip' doesn't remove it.


Side-note: since your string has those zeroes at the end, strip 
only removes the space at start (thus, final size=15), instead 
of at both ends.


d


Okay things are becoming more clear. The cast to string is 
nothing like the C++ string ctor, I made a bad assumption.


So given the below buffer would I use fromStringz (is this in the 
stdlib?) to cast it from a null-terminated buffer to a good 
string? Shouldn't the compiler give a warning about casting a 
buffer to a string without using fromStringz?


Buffer = [ 0x20, 0x41, 0x54, 0x41, 0x20, 0x00, 0x00, ...]?


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 15:24:21 +
Lucas Burson via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 So given the below buffer would I use fromStringz (is this in the 
 stdlib?) to cast it from a null-terminated buffer to a good 
 string? Shouldn't the compiler give a warning about casting a 
 buffer to a string without using fromStringz?
if you are really-really sure that your buffer is null-terminated, you
can use this trick:

  import std.conv;
  string s = to!string(cast(char*)buff.ptr);

please note, that this is NOT SAFE. you'd better doublecheck that your
buffer is not empty and is null-terminated.


signature.asc
Description: PGP signature


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 18:30:43 +0300
ketmar via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

  Shouldn't the compiler give a warning about casting a 
  buffer to a string without using fromStringz?
nope. such casting is perfectly legal, as D strings can contain
embedded '\0's.


signature.asc
Description: PGP signature


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread Chris via Digitalmars-d-learn
On Friday, 17 October 2014 at 14:38:39 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 14:33:57 +
eles via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:


On Friday, 17 October 2014 at 13:59:03 UTC, ketmar via 
Digitalmars-d-learn wrote:

 On Fri, 17 Oct 2014 10:10:09 +0200
 spir via Digitalmars-d-learn 
 digitalmars-d-learn@puremagic.com wrote:


 computer programming is the literacy of the new age.

Let's say, computer knowledge.


yes, you are right. that was what i mean: not only programming, 
but

understanding of how computers works and how to control them.


But then people won't trust them bloody machines an inch anymore! 
:-)


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 15:40:24 +
Chris via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 But then people won't trust them bloody machines an inch anymore! 
 :-)
most people believe that technology is magic. yes, maybe it's too cruel
to ruin their illusions...


signature.asc
Description: PGP signature


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread olivier henley via Digitalmars-d-learn


. D is pristine clean and immensely powerful.

. D is arguably the actual state-of-the-art programming language.

. Ali's book is a gem. Clear, concise and complete. 
http://ddili.org/ders/d.en/


. D is the best investment you can make for your career, right 
now.


. D has Java beans for breakfast. :D


your choice, my two cents.








Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread via Digitalmars-d-learn
On Friday, 17 October 2014 at 14:00:43 UTC, ketmar via 
Digitalmars-d-learn wrote:
yet Scheme will teach how to write functional code. it's a 
valuable knowledge for D programmer.


I think spending a few days with Scheme is valuable for all 
programmers.


By being a minimal language you get down to the essence of 
functional programming by reading some tutorials on Scheme and 
playing with the interpreter.


(and you can more easily configure some open source apps who use 
guile/elisp/scheme, so it has some practical value…)


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread Lucas Burson via Digitalmars-d-learn
On Friday, 17 October 2014 at 15:30:52 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 15:24:21 +
Lucas Burson via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

So given the below buffer would I use fromStringz (is this in 
the stdlib?) to cast it from a null-terminated buffer to a 
good string? Shouldn't the compiler give a warning about 
casting a buffer to a string without using fromStringz?
if you are really-really sure that your buffer is 
null-terminated, you

can use this trick:

  import std.conv;
  string s = to!string(cast(char*)buff.ptr);

please note, that this is NOT SAFE. you'd better doublecheck 
that your

buffer is not empty and is null-terminated.


The buffer is populated from a scsi ioctl so it should be only 
ascii and null-terminated but it's a good idea to harden the code 
a bit.

Thank you for your help!


Re: How to check i

2014-10-17 Thread Uranuz via Digitalmars-d-learn

This is



Recommended GUI library?

2014-10-17 Thread K.K. via Digitalmars-d-learn

I'm looking for suggestions for a GUI library, to create a
somewhat light GUI that can also be created without too much
fuss, and support for Windows  Linux.

The GUI I'm looking to make would be one that is just one window,
with support for tabs (just like the ones in the properties page
for items on Windows), and support for opening up file browsing
(just normal system one is good).
Then pretty much each of the tabs are just gonna be for setting
up info to send to a bunch of smaller programs.

Ive used Tcl/Tk with Python before, and I briefly tried out a D
version, with choppy results.
So what library would anyone suggest for what I'm looking to do,
or which library have you taken a liking to?

Thanks, for any suggestions!


Re: How to match string by word

2014-10-17 Thread Uranuz via Digitalmars-d-learn
I haven't touched any key on a keyboard and haven't pressed 
*Send* but message was posted somehow.


Thanks. Checking for UTF-8 continuation bytes is good idea. Also 
I agree that UTF-16 is more difficult. I will keep it for future 
release when implementation will start to work properly on UTF-8 
and UTF-32


Initializing D in C to use?

2014-10-17 Thread Jeremy DeHaan via Digitalmars-d-learn
I'm starting a new project, and I plan on creating a C interface 
in case other languages want to use it. I remember reading 
something(but my googlefu is weak today) about having to 
initialize the runtime if you are using D inside another 
language. Can anyone confirm this is the case?


I just wanted to make sure I make that explicit for users if they 
don't want to use the library with D.


Thanks all!
   Jeremy


Re: Recommended GUI library?

2014-10-17 Thread Jeremy DeHaan via Digitalmars-d-learn

I highly recommend gtkD.

It works on Windows, OSX, and Linux and provides a very nice OO 
interface to Gtk+.


http://gtkd.org/


Re: Recommended GUI library?

2014-10-17 Thread K.K. via Digitalmars-d-learn

On Friday, 17 October 2014 at 16:41:21 UTC, Jeremy DeHaan wrote:

I highly recommend gtkD.

It works on Windows, OSX, and Linux and provides a very nice OO 
interface to Gtk+.


http://gtkd.org/


ooo looks pretty good. I'll go try it out;

Thanks, Jeremy!


Why was scope for allocating classes on the stack marked for deprecation?

2014-10-17 Thread Jeremy DeHaan via Digitalmars-d-learn
I'm curious as to why using scope to allocate classes on the 
stack was marked for future deprecation.


I mean, sure it could be potentially unsafe, but the new library 
solution (using std.typecons.scoped) does the exact same thing 
and is just as unsafe for the same reasons, is it not? I would 
rather continue to use the keyword scope instead of having to 
import another module in order to use this feature.




Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread Paulo Pinto via Digitalmars-d-learn

Am 17.10.2014 um 16:14 schrieb Jessica Rauth:

On Friday, 17 October 2014 at 08:44:00 UTC, Paulo  Pinto wrote:

On Friday, 17 October 2014 at 01:05:37 UTC, ketmar via
Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 00:52:14 +
MachineCode via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:


I don't understand. If at least it were C but java? why not D itself?

C is *awful* as beginner's language. never ever let people start with
C if you don't hate 'em.

as for D... current version of D can be used, but with some
precautions. we now have excellent book by Ali. (it's great, really! i
believe that it must be featured on the front dlang.org page!) but java
has alot more books and tutorials.

not that D is bad for beginners, it's just has a smaller userbase. and
all that things with classes are reference types and structs are not,
empty array is not empty array but is empty array and so on D may be
confusing a little. it's good to have some CS background to understood
that things.

just my cent and cent.



Better, go with FreePascal http://www.freepascal.org/ and discover all
that those features that many C advocates spread as being close to the
machine and other C only features, aren't exclusive of it.

Alongside support for real modules, OO and genericity.

Then with a head clean of bad C influences, jump into D.


--
Paulo


One of the problem when starting out with FPC resides in the fact that's
a completely different family of language (Ada, Pascal, Modula vs the C
family), syntax and philosophy (for example in the RTL).

Another one is that usually people use it in combination with Lazarus
and as the RAD concept is no shit, people start building some
applications very fastly. Then when they come to another lang. eg D or
Cpp they take a big slap in the face. The fact is that Obj. Pascal and
Delphi often give a wrong appreciation of its own skills and abilities.



Although I am biased to the Pascal family of languages, this has been 
done in real world for a couple of decades.


When I joined the New University of Lisbon as a student in 1994, I was 
lucky that the professor heading the programming languages section, had 
a similar opinion as me in terms of programming languages.


The first year students had introduction to programming with P2C/GNU 
Pascal in the first semester, followed by C++ with gcc in the second 
semester.


There was no C, at all. It was expected that any student compent enough 
to use C++, would be able to code in straight C if asked to do so.


On my last year at the university (1998/9), I one of the teachers giving 
those lab classes to students. By then, we were using Delphi and Visual 
C++ instead.


The students didn't had much problems switching languages.

They got to learn that using pointers doesn't need to be the dragon that 
C makes out to be.


That there was a way to deal with strings, arrays and reference 
parameters without impact in the whole application. The most curious got 
to learn how to disable bounds checking.


They learned how to write modular applications without having to prefix 
all their identifiers.


They also learned that C wasn't the only way to touch the machine at all 
levels.






You talk about genericity but the genericity in Object Pascal is
currently almost inexistant and doesn't provide a good idea of what
template-meta-programming is. Actually this looks more like a patch to
the lang. and some simple things just like casting a generic type or
global generic functions simply don't work at all. While D2 has been
written with this idea, FPC will never be good with TMP. Even in the
commercial version (Delphi XE7) they start to add some kind of patchs eg
with a compiler instrasic which is equivalent to D static if (which
means that the lang. is not designed for that at all).



I just referenced it, because I saw it mentioned a few times in Delphi 
documentation, but never came to use it.


Since 2000 that I don't do anything in the Pascal world of languages, 
besides collecting Oberon related stuff.


--
Paulo


Re: Initializing D in C to use?

2014-10-17 Thread K.K. via Digitalmars-d-learn

On Friday, 17 October 2014 at 16:35:46 UTC, Jeremy DeHaan wrote:
I'm starting a new project, and I plan on creating a C 
interface in case other languages want to use it. I remember 
reading something(but my googlefu is weak today) about having 
to initialize the runtime if you are using D inside another 
language. Can anyone confirm this is the case?


I just wanted to make sure I make that explicit for users if 
they don't want to use the library with D.


Thanks all!
   Jeremy


Sorry if this isn't the most helpful answer but.. Do you have
Adam Ruppe's book?
On pg96, Writing part of a C program in D it sounds like he
does what you're asking.
I was gonna write more, but being I haven't tried it before, I
don't wanna start giving potentially false info
...I mean I could write more but it's probably a bad idea getting
help from me xD


Re: Recommended GUI library?

2014-10-17 Thread Gary Willoughby via Digitalmars-d-learn

On Friday, 17 October 2014 at 16:34:04 UTC, K.K. wrote:

I'm looking for suggestions for a GUI library, to create a
somewhat light GUI that can also be created without too much
fuss, and support for Windows  Linux.

The GUI I'm looking to make would be one that is just one 
window,

with support for tabs (just like the ones in the properties page
for items on Windows), and support for opening up file browsing
(just normal system one is good).
Then pretty much each of the tabs are just gonna be for setting
up info to send to a bunch of smaller programs.

Ive used Tcl/Tk with Python before, and I briefly tried out a D
version, with choppy results.
So what library would anyone suggest for what I'm looking to do,
or which library have you taken a liking to?

Thanks, for any suggestions!


If you want something small and simple you could try this:

https://github.com/nomad-software/tkd


Re: Why was scope for allocating classes on the stack marked for deprecation?

2014-10-17 Thread Adam D. Ruppe via Digitalmars-d-learn

On Friday, 17 October 2014 at 16:56:50 UTC, Jeremy DeHaan wrote:
I'm curious as to why using scope to allocate classes on the 
stack was marked for future deprecation.


It was never implemented correctly (it is supposed prove it never 
leaves the scope, and is thus safe to be on the stack), so rather 
than keep a half baked feature in the language, the gang wanted 
to move it to the library where at least the usage wouldn't look 
as normal given the memory safety problems.


Re: Initializing D in C to use?

2014-10-17 Thread Adam D. Ruppe via Digitalmars-d-learn

On Friday, 17 October 2014 at 16:35:46 UTC, Jeremy DeHaan wrote:
I remember reading something(but my googlefu is weak today) 
about having to initialize the runtime if you are using D 
inside another language. Can anyone confirm this is the case?


Yeah, unless the main() is in D, you need to run initialization 
functions.


The way I recommend doing it is to write your own extern(C) 
MyLib_Init and MyLib_Term functions. Then have their 
implementations call the import core.runtime; Runtime.initialize()


http://dlang.org/phobos/core_runtime.html#initialize

This way, you can do other init stuff for your lib too without 
the user worrying about those details. Furthermore, having to 
call a library init function is somewhat normal for C libs, so 
the user shouldn't think much of it.


Re: Initializing D in C to use?

2014-10-17 Thread Adam D. Ruppe via Digitalmars-d-learn

On Friday, 17 October 2014 at 17:14:30 UTC, K.K. wrote:

Sorry if this isn't the most helpful answer but.. Do you have
Adam Ruppe's book?


buy my book too, and write amazon reviews :P

A lot of the topics in there were chosen because there are 
questions that come up somewhat often on this forum or the D chat 
room. I answer a lot of questions here too, but the book is cool 
too!


Re: Initializing D in C to use?

2014-10-17 Thread bachmeier via Digitalmars-d-learn

On Friday, 17 October 2014 at 17:18:34 UTC, Adam D. Ruppe wrote:

On Friday, 17 October 2014 at 16:35:46 UTC, Jeremy DeHaan wrote:
I remember reading something(but my googlefu is weak today) 
about having to initialize the runtime if you are using D 
inside another language. Can anyone confirm this is the case?


Yeah, unless the main() is in D, you need to run initialization 
functions.


The way I recommend doing it is to write your own extern(C) 
MyLib_Init and MyLib_Term functions. Then have their 
implementations call the import core.runtime; 
Runtime.initialize()


http://dlang.org/phobos/core_runtime.html#initialize

This way, you can do other init stuff for your lib too without 
the user worrying about those details. Furthermore, having to 
call a library init function is somewhat normal for C libs, so 
the user shouldn't think much of it.


Just for completeness, here's an example for Googlers that come 
across this, taken from code I write all the time:


import core.runtime;

extern(C) {
  void R_init_libfoo() {
Runtime.initialize();
  }
}


Re: Using __traits to find functions in sub-modules

2014-10-17 Thread nrgyzer via Digitalmars-d-learn

On Thursday, 16 October 2014 at 19:19:21 UTC, John Colvin wrote:

On Thursday, 16 October 2014 at 18:39:50 UTC, nrgyzer wrote:

Hi,
I'm using structs to describe my functions:

struct example
{
  string name;
  uint someValue;
}

module mod.example1;

@example(example1, 1)
void myFunction()
{
// do something
}

module mod.example2;

@example(example2, 2)
void myFunction()
{
// do something
}

I'm using the struct to describe functions in different 
modules. Now, I want add all functions which are described 
using the example-struct to an array during compile time. But 
how can I do this? I know, I can use __trait(allMembers, 
mod.example1) and __trait(allMembers, mod.example2), but I 
only want specify the parent module (mod), for instance:


void main()
{
  foreach (member, __traits(allMembers, mod))
  {
 writeln(member);
  }
}

But this only shows object - nothing else. No sub-modules 
like mod.example1 or mod.example2. So, how can I find all 
functions that are described using my structure during compile 
time and add them to an array?


I already tried this:

void main()
{
  foreach (cmodule; ModuleInfo)
  {
 foreach (submodule; __traits(allMembers, cmodule))
 {
 // ... also tried: foreach (submodule; 
__traits(allMembers, mixin(cmodule.name))), cmodule.name is 
not available during compile time...

 }
  }
}

But it always stats that 'cmodule' has no members. Does anyone 
know how to solve the problem?


perhaps you could get somewhere by using a package.d in every 
package?


If it needs to work on packages you don't control then I don't 
really know :/


Hm, importing the package doesn't help :(
Okay, I see... I've to solve the problem using another idea...


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 16:08:04 +
Lucas Burson via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 The buffer is populated from a scsi ioctl so it should be only 
 ascii and null-terminated but it's a good idea to harden the code 
 a bit.
 Thank you for your help!
i developed a habit of making such buffers one byte bigger than
necessary and just setting the last byte to 0 before converting. this
way it's guaranteed to be 0-terminated.


signature.asc
Description: PGP signature


Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn
Basicly what I am trying to do is have a function template that 
will generate its parameters to be arrays of the types of a type 
tuple.


So for instance the parameters of f!(int, char) would be (int[], 
char[])...


No matter what I try, the compiler vomits all over me...


Re: Function parameters from TypeTuple

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 17:44:47 +
Tofu Ninja via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 Basicly what I am trying to do is have a function template that 
 will generate its parameters to be arrays of the types of a type 
 tuple.
 
 So for instance the parameters of f!(int, char) would be (int[], 
 char[])...
 
 No matter what I try, the compiler vomits all over me...
i don't really understand what you want, sorry. can you show some more
code with use case you want to have?


signature.asc
Description: PGP signature


Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn

On Friday, 17 October 2014 at 17:44:48 UTC, Tofu Ninja wrote:

Not sure if what I wrote made sense, instead I will just post the 
code that is vomiting on me...


template arrayType(T)
{
alias arrayType = T[];
}

template multiAccess(Args ...)
{
auto multiAccess(int i, staticMap!(arrayType, Args) args)
{
static if(args.length == 1) return Tuple!(args[0][i]);
		else return Tuple!(args[0][i], multiAccess!(Args[1 .. 
$])(args[1 .. $]));

}
}

void main(string[] args)
{
int[] a = [1,2];
int[] b = [5,6];
writeln(multiAccess!(int,int)(1, a,b));
}

but the compiler really does not like that at all... the error 
message are very unhelpful as well...


Generates 18 errors...

main.d(52): Error: variable _param_1 cannot be read at compile 
time
main.d(53): Error: variable _param_1 cannot be read at compile 
time
main.d(52): Error: variable _param_1 cannot be read at compile 
time
main.d(53): Error: variable _param_1 cannot be read at compile 
time

main.d(52): Error: tuple index 0 exceeds length 0
main.d(52): Error: tuple index 0 exceeds 0
main.d(52): Error: tuple index 0 exceeds length 0
main.d(52): Error: tuple index 0 exceeds 0
main.d(52): Error: tuple index 0 exceeds 0
main.d(53): Error: tuple index 0 exceeds length 0
main.d(53): Error: tuple index 0 exceeds 0
main.d(53): Error: tuple index 0 exceeds length 0
main.d(53): Error: tuple index 0 exceeds 0
main.d(53): Error: tuple index 0 exceeds 0
main.d(53): Error: slice [1..0] is out of range of [0..0]
main.d(53): Error: template instance main.multiAccess!() error 
instantiating

main.d(53):instantiated from here: multiAccess!int
main.d(25):instantiated from here: multiAccess!(int, int)
main.d(53): Error: template instance main.multiAccess!int error 
instantiating

main.d(25):instantiated from here: multiAccess!(int, int)
main.d(25): Error: template instance main.multiAccess!(int, int) 
error instantiating


Re: Function parameters from TypeTuple

2014-10-17 Thread Ali Çehreli via Digitalmars-d-learn

On 10/17/2014 10:44 AM, Tofu Ninja wrote:

Basicly what I am trying to do is have a function template that will
generate its parameters to be arrays of the types of a type tuple.

So for instance the parameters of f!(int, char) would be (int[], char[])...

No matter what I try, the compiler vomits all over me...


Perhaps string does not match cha[]? I made the elements const in the 
following code but you don't need them if you don't need to pass string:


void f(A, B)(const(A)[] as, const(B)[] bs)
{}

void main()
{
f!(int, char)([42], s);

// And you don't need to specify the template parameters yourself:
f([42], s);
}

Ali



Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn

On Friday, 17 October 2014 at 17:55:14 UTC, Ali Çehreli wrote:
Yeah.. I dont think I was clear the first time...


Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn

On Friday, 17 October 2014 at 17:57:58 UTC, Tofu Ninja wrote:

Also my inability to get this working is probably rooted in my 
lack of understanding of the differences between tuple vs Tuple 
vs TypeTuple vs expression tuples ...


Re: Function parameters from TypeTuple

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 17:57:57 +
Tofu Ninja via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 On Friday, 17 October 2014 at 17:44:48 UTC, Tofu Ninja wrote:
 
 Not sure if what I wrote made sense, instead I will just post the 
 code that is vomiting on me...
still can't grasp what you want to achieve. do you want to build
accessor function, or template that returns another template, or what?


signature.asc
Description: PGP signature


Re: Function parameters from TypeTuple

2014-10-17 Thread Justin Whear via Digitalmars-d-learn
On Fri, 17 Oct 2014 17:44:47 +, Tofu Ninja wrote:

 Basicly what I am trying to do is have a function template that will
 generate its parameters to be arrays of the types of a type tuple.
 
 So for instance the parameters of f!(int, char) would be (int[],
 char[])...
 
 No matter what I try, the compiler vomits all over me...

This what you're thinking of?
http://dpaste.dzfl.pl/724bd2573e98


Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn
On Friday, 17 October 2014 at 18:22:12 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 17:57:57 +
Tofu Ninja via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:


On Friday, 17 October 2014 at 17:44:48 UTC, Tofu Ninja wrote:

Not sure if what I wrote made sense, instead I will just post 
the code that is vomiting on me...

still can't grasp what you want to achieve. do you want to build
accessor function, or template that returns another template, 
or what?


I am not even sure any more, I am starting to get lost in the 
tuple madness...


I think I am trying to create an expression tuple for multiple 
array accesses but I am starting to think that it is not even 
possible...


First let me ask another question... is it possible to create an 
expression tuple from an array access? TypeTyple!(a[1]) clearly 
does not work even though a[1] is an expression. It tries to 
evaluate the expression a[1] instead of creating an expression 
tuple from it.


Re: Function parameters from TypeTuple

2014-10-17 Thread Ali Çehreli via Digitalmars-d-learn

On 10/17/2014 11:35 AM, Tofu Ninja wrote:

 I am not even sure any more, I am starting to get lost in the tuple
 madness...

You want to write a function that takes an index and a number of arrays; 
and returns an N-ary Tuple where N matches the number arrays passed to 
the function: :p


  assert(multiAccess(0, [42], s) == Tuple!(int, char)(42, 's'));

And it should work with any number of parameters. Second elements of 
three arrays:


  assert(multiAccess(1, [42, 100], hello, world)
 == Tuple!(int, char, char)(100, 'e', 'o'));

Ali



Re: Function parameters from TypeTuple

2014-10-17 Thread anonymous via Digitalmars-d-learn

On Friday, 17 October 2014 at 17:57:58 UTC, Tofu Ninja wrote:

On Friday, 17 October 2014 at 17:44:48 UTC, Tofu Ninja wrote:

Not sure if what I wrote made sense, instead I will just post 
the code that is vomiting on me...


You forgot the imports.


template arrayType(T)
{
alias arrayType = T[];
}

template multiAccess(Args ...)
{
auto multiAccess(int i, staticMap!(arrayType, Args) args)
{
static if(args.length == 1) return Tuple!(args[0][i]);


`Tuple` is a type template. Use `tuple(foo, bar)` to build a
`Tuple!(typeof(foo), typeof(bar))`.

= return tuple(args[0][i]);

		else return Tuple!(args[0][i], multiAccess!(Args[1 .. 
$])(args[1 .. $]));


`Tuple!` - `tuple` again. Also, `multiAccess` needs `i` again.
And you want to `expand` the sub-result into the tuple so that
it's flat.

= return tuple(args[0][i], multiAccess!(Args[1 .. $])(i, args[1
.. $]).expand);


}
}

void main(string[] args)
{
int[] a = [1,2];
int[] b = [5,6];
writeln(multiAccess!(int,int)(1, a,b));
}

but the compiler really does not like that at all... the error 
message are very unhelpful as well...


Generates 18 errors...

main.d(52): Error: variable _param_1 cannot be read at compile 
time

[...]

This is about you trying to instantiate `Tuple` with the runtime
value that is `args[0][1]`.


main.d(52): Error: tuple index 0 exceeds length 0

[...]

I don't know where these come from. They don't show up for me.

main.d(53): Error: template instance main.multiAccess!() error 
instantiating

[...]

These are due to previous errors.


For style points you could

* Use the short form for function templates:

 auto multiAccess(Args ...)(int i, staticMap!(arrayType, Args)
args) {...}

* Take array types as template arguments instead of constructing
them. This allows them to be inferred (IFTI - Implicit Function
Template Instantiation):

 auto multiAccess(Args ...)(int i, Args args)
 /* Maybe put a template constraint here that forces Args
to be all arrays. */
 {
 import std.typecons: tuple;
 static if(args.length == 1) return tuple(args[0][i]);
 else return tuple(args[0][i], multiAccess(i, args[1 ..
$]).expand);
 }
 void main()
 {
 int[] a = [1,2];
 int[] b = [5,6];
 import std.stdio;
 writeln(multiAccess(1, a,b));
 }


Re: How to match string by word

2014-10-17 Thread eles via Digitalmars-d-learn

On Friday, 17 October 2014 at 16:39:38 UTC, Uranuz wrote:
I haven't touched any key on a keyboard and haven't pressed 
*Send* but message was posted somehow.


Scan for rootkits...



Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn

On Friday, 17 October 2014 at 19:03:42 UTC, anonymous wrote:

On Friday, 17 October 2014 at 17:57:58 UTC, Tofu Ninja wrote:

On Friday, 17 October 2014 at 17:44:48 UTC, Tofu Ninja wrote:

Not sure if what I wrote made sense, instead I will just post 
the code that is vomiting on me...


You forgot the imports.


template arrayType(T)
{
alias arrayType = T[];
}

template multiAccess(Args ...)
{
auto multiAccess(int i, staticMap!(arrayType, Args) args)
{
static if(args.length == 1) return Tuple!(args[0][i]);


`Tuple` is a type template. Use `tuple(foo, bar)` to build a
`Tuple!(typeof(foo), typeof(bar))`.

= return tuple(args[0][i]);

		else return Tuple!(args[0][i], multiAccess!(Args[1 .. 
$])(args[1 .. $]));


`Tuple!` - `tuple` again. Also, `multiAccess` needs `i` again.
And you want to `expand` the sub-result into the tuple so that
it's flat.

= return tuple(args[0][i], multiAccess!(Args[1 .. $])(i, args[1
.. $]).expand);


}
}

void main(string[] args)
{
int[] a = [1,2];
int[] b = [5,6];
writeln(multiAccess!(int,int)(1, a,b));
}

but the compiler really does not like that at all... the error 
message are very unhelpful as well...


Generates 18 errors...

main.d(52): Error: variable _param_1 cannot be read at compile 
time

[...]

This is about you trying to instantiate `Tuple` with the runtime
value that is `args[0][1]`.


main.d(52): Error: tuple index 0 exceeds length 0

[...]

I don't know where these come from. They don't show up for me.

main.d(53): Error: template instance main.multiAccess!() error 
instantiating

[...]

These are due to previous errors.


For style points you could

* Use the short form for function templates:

 auto multiAccess(Args ...)(int i, staticMap!(arrayType, 
Args)

args) {...}

* Take array types as template arguments instead of constructing
them. This allows them to be inferred (IFTI - Implicit Function
Template Instantiation):

 auto multiAccess(Args ...)(int i, Args args)
 /* Maybe put a template constraint here that forces 
Args

to be all arrays. */
 {
 import std.typecons: tuple;
 static if(args.length == 1) return tuple(args[0][i]);
 else return tuple(args[0][i], multiAccess(i, args[1 ..
$]).expand);
 }
 void main()
 {
 int[] a = [1,2];
 int[] b = [5,6];
 import std.stdio;
 writeln(multiAccess(1, a,b));
 }


I had the imports, I just didn't post them. My problem is most 
likely that I used Tuple! instead of tuple... which is probably 
because the differences between the like 20(exaggeration) 
different types of tuples in D are confusing as hell...


Re: How to match string by word

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 19:13:51 +
eles via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 On Friday, 17 October 2014 at 16:39:38 UTC, Uranuz wrote:
  I haven't touched any key on a keyboard and haven't pressed 
  *Send* but message was posted somehow.
 
 Scan for rootkits...
or touchpad. ;-)


signature.asc
Description: PGP signature


Re: Function parameters from TypeTuple

2014-10-17 Thread anonymous via Digitalmars-d-learn

On Friday, 17 October 2014 at 19:18:29 UTC, Tofu Ninja wrote:
I had the imports, I just didn't post them. My problem is most 
likely that I used Tuple! instead of tuple... which is probably 
because the differences between the like 20(exaggeration) 
different types of tuples in D are confusing as hell...


You've seen the rest of my message, right?


Re: Function parameters from TypeTuple

2014-10-17 Thread Justin Whear via Digitalmars-d-learn
On Fri, 17 Oct 2014 11:56:31 -0700, Ali Çehreli wrote:

 You want to write a function that takes an index and a number of arrays;
 and returns an N-ary Tuple where N matches the number arrays passed to
 the function: :p

http://dlang.org/phobos/std_range.html#transversal


Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn

On Friday, 17 October 2014 at 19:32:40 UTC, anonymous wrote:

On Friday, 17 October 2014 at 19:18:29 UTC, Tofu Ninja wrote:
I had the imports, I just didn't post them. My problem is most 
likely that I used Tuple! instead of tuple... which is 
probably because the differences between the like 
20(exaggeration) different types of tuples in D are confusing 
as hell...


You've seen the rest of my message, right?


Yeah, the part that fixed it was Tuple! to tuple. Thanks for the 
help. I think this fixes my problem.


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread Joakim via Digitalmars-d-learn
On Friday, 17 October 2014 at 13:59:03 UTC, ketmar via 
Digitalmars-d-learn wrote:
that's why i'm sure that basic programming must be teached in 
school.

hey, the whole our civilization will collapse without computers!
computer programming is the literacy of the new age.


This is nonsense and I see it repeated all the time, with 
code.org and other efforts.  Do you know how to fix your car, 
washing machine, or refrigerator?  No, yet your life would likely 
collapse far faster without those.  You hire somebody to do the 
job if any of those mechanical systems breaks.  Similarly, most 
people hire programmers to do the software work they don't want 
to do.


I will agree that basic computer literacy is important, ie people 
should know their way around a computer or tablet, how to open 
and turn off apps, mouse or touch your way around the UI, etc.  
But beyond that it's a matter of interest: some people like 
Walter want to work on their car or computer, but most people 
don't.


On Friday, 17 October 2014 at 14:00:43 UTC, ketmar via 
Digitalmars-d-learn wrote:
yet Scheme will teach how to write functional code. it's a 
valuable

knowledge for D programmer.


My first programming language was Scheme in my freshman year of 
college (I wasn't one of those kids programming since middle 
school).  Scheme was fine for the time, though the scads of 
parentheses were annoying, but I think we can do better decades 
later.  D would work fine if it's presented at a level 
appropriate to a beginner, ie not assuming they know anything 
about programming to begin with.


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 20:40:37 +
Joakim via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 On Friday, 17 October 2014 at 13:59:03 UTC, ketmar via 
 Digitalmars-d-learn wrote:
  that's why i'm sure that basic programming must be teached in 
  school.
  hey, the whole our civilization will collapse without computers!
  computer programming is the literacy of the new age.
 
 This is nonsense and I see it repeated all the time, with 
 code.org and other efforts.  Do you know how to fix your car, 
 washing machine, or refrigerator?
i have no car, i know how to fix my wahing machine, i know how to fix
my refrigerator.

 No, yet your life would likely collapse far faster without those.
my life is not the whole human civilization.

 You hire somebody to do the 
 job if any of those mechanical systems breaks.  Similarly, most 
 people hire programmers to do the software work they don't want 
 to do.
...and pretty sure that computers are magical devices. oh, how many
times i've seen people doing tedious repetetive work for hours, that
kind of work that can be done in seconds by the simple script.

actually, that's why people so love their pads: no-brain-required.
not only that, but no easy way to made it do what i want too. i still
can't understant that kind of attitude.

 I will agree that basic computer literacy is important, ie people 
 should know their way around a computer or tablet, how to open 
 and turn off apps, mouse or touch your way around the UI, etc.  
 But beyond that it's a matter of interest: some people like 
 Walter want to work on their car or computer, but most people 
 don't.
inability to write a simple script to automate some task is not
different from inability to write some words on a piece of paper.
yet i see how the argument oh, well, i hire someone to write that for
me fits here.


signature.asc
Description: PGP signature


Re: Any dub tips and tricks

2014-10-17 Thread Joel via Digitalmars-d-learn

On Friday, 17 October 2014 at 08:32:13 UTC, Atila Neves wrote:
Are you sure your package/dub.json is valid JSON? You can check 
it here:


http://jsonlint.com/

Atila

On Thursday, 16 October 2014 at 22:22:14 UTC, Joel wrote:
Any way of using dub (on Windows or OSX). I've been trying it 
lately, but not much success.


1. (In the command prompt or Terminal), I create a new folder.
2. Run 'dub init' in the new folder
3. I copy the dependency from a lib/app into the dub.json file.
4. Then I just enter 'dub'

In Windows I get this error (and others, but seems to go 
through): Failed to parse package description for dil  in 
C:\Users\Joel\AppData\Roaming\dub\packages\dil-master\.


I'm more interested in using OSX, for D.


It does pass.

Here's more information:

C:\jpro\dpro2\meldtestdub
Failed to parse package description for dil  in 
C:\Users\Joel\AppData\Roaming\du

b\packages\dil-master\.
Failed to load package in 
C:/Users/Joel/AppData/Roaming/dub/packages/dil-master/

: Got .excludedSourceFiles of type string - expected array.
Failed to parse package description for dil  in 
C:\Users\Joel\AppData\Roaming\du

b\packages\dil-master\.
Failed to load package in 
C:/Users/Joel/AppData/Roaming/dub/packages/dil-master/

: Got .excludedSourceFiles of type string - expected array.
Failed to parse package description for dil  in 
C:\Users\Joel\AppData\Roaming\du

b\packages\dil-master\.
Failed to load package in 
C:/Users/Joel/AppData/Roaming/dub/packages/dil-master/

: Got .excludedSourceFiles of type string - expected array.
Target derelict-util 1.0.3 is up to date. Use --force to rebuild.
Target derelict-glfw3 ~master is up to date. Use --force to 
rebuild.

Target derelict-gl3 ~master is up to date. Use --force to rebuild.
Building meld 0.0.1 configuration library, build type debug.
Running pre-build commands...
'pwd' is not recognized as an internal or external command,
operable program or batch file.
Error executing command run: Command failed with exit code 1


Re: Any dub tips and tricks

2014-10-17 Thread John Colvin via Digitalmars-d-learn

On Friday, 17 October 2014 at 22:01:22 UTC, Joel wrote:

On Friday, 17 October 2014 at 08:32:13 UTC, Atila Neves wrote:
Are you sure your package/dub.json is valid JSON? You can 
check it here:


http://jsonlint.com/

Atila

On Thursday, 16 October 2014 at 22:22:14 UTC, Joel wrote:
Any way of using dub (on Windows or OSX). I've been trying it 
lately, but not much success.


1. (In the command prompt or Terminal), I create a new folder.
2. Run 'dub init' in the new folder
3. I copy the dependency from a lib/app into the dub.json 
file.

4. Then I just enter 'dub'

In Windows I get this error (and others, but seems to go 
through): Failed to parse package description for dil  in 
C:\Users\Joel\AppData\Roaming\dub\packages\dil-master\.


I'm more interested in using OSX, for D.


It does pass.

Here's more information:

C:\jpro\dpro2\meldtestdub
Failed to parse package description for dil  in 
C:\Users\Joel\AppData\Roaming\du

b\packages\dil-master\.
Failed to load package in 
C:/Users/Joel/AppData/Roaming/dub/packages/dil-master/

: Got .excludedSourceFiles of type string - expected array.
Failed to parse package description for dil  in 
C:\Users\Joel\AppData\Roaming\du

b\packages\dil-master\.
Failed to load package in 
C:/Users/Joel/AppData/Roaming/dub/packages/dil-master/

: Got .excludedSourceFiles of type string - expected array.
Failed to parse package description for dil  in 
C:\Users\Joel\AppData\Roaming\du

b\packages\dil-master\.
Failed to load package in 
C:/Users/Joel/AppData/Roaming/dub/packages/dil-master/

: Got .excludedSourceFiles of type string - expected array.
Target derelict-util 1.0.3 is up to date. Use --force to 
rebuild.
Target derelict-glfw3 ~master is up to date. Use --force to 
rebuild.
Target derelict-gl3 ~master is up to date. Use --force to 
rebuild.

Building meld 0.0.1 configuration library, build type debug.
Running pre-build commands...
'pwd' is not recognized as an internal or external command,
operable program or batch file.
Error executing command run: Command failed with exit code 1


There is a mistake in the dil package.json
excludedSourceFiles should be an array of strings, not just a 
string.


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread Joakim via Digitalmars-d-learn
On Friday, 17 October 2014 at 21:20:29 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Fri, 17 Oct 2014 20:40:37 +
Joakim via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:
This is nonsense and I see it repeated all the time, with 
code.org and other efforts.  Do you know how to fix your car, 
washing machine, or refrigerator?
i have no car, i know how to fix my wahing machine, i know how 
to fix

my refrigerator.


You do realize that most people are clueless about how to fix 
those also, right?  Would you require that how to fix all that 
mechanical stuff be taught in schools too?  Kids would never 
leave school if they had to learn all the stuff everybody says 
they should be forced to learn. ;)


No, yet your life would likely collapse far faster without 
those.

my life is not the whole human civilization.


Yet, civilization is made up of people like you, who would all 
miss those mechanical systems far more than computers.


You hire somebody to do the job if any of those mechanical 
systems breaks.  Similarly, most people hire programmers to do 
the software work they don't want to do.
...and pretty sure that computers are magical devices. oh, how 
many
times i've seen people doing tedious repetetive work for hours, 
that

kind of work that can be done in seconds by the simple script.


They should use tools like Automator instead, no programming 
needed:


http://en.wikipedia.org/wiki/Automator_(software)

actually, that's why people so love their pads: 
no-brain-required.
not only that, but no easy way to made it do what i want too. 
i still

can't understant that kind of attitude.


Tablets are optimized for basic usage, not saving files and 
document editing and whatever else you might want to do on a PC.  
Most people just need a basic appliance that isn't going to catch 
viruses or require registry hacks.


I will agree that basic computer literacy is important, ie 
people should know their way around a computer or tablet, how 
to open and turn off apps, mouse or touch your way around the 
UI, etc.  But beyond that it's a matter of interest: some 
people like Walter want to work on their car or computer, but 
most people don't.

inability to write a simple script to automate some task is not
different from inability to write some words on a piece of 
paper.


It is completely different, because there are tools like 
Automator to help you automate your workflow without needing to 
write anything.  If you need to communicate something on paper- 
well, nobody uses paper these days so let's say in text ;) - 
that's more basic and fundamental.


yet i see how the argument oh, well, i hire someone to write 
that for

me fits here.


For most people, that is a better route, particularly if they 
don't need to modify the script as they go and just need it 
written once.


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Fri, 17 Oct 2014 23:31:45 +
Joakim via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 You do realize that most people are clueless about how to fix 
 those also, right?
most people are stupid.

 Would you require that how to fix all that 
 mechanical stuff be taught in schools too?
but it is! or at least it was. it's all simple physics, you know. not a
rocket science.

 Kids would never 
 leave school if they had to learn all the stuff everybody says 
 they should be forced to learn. ;)
nobody should be *forced* to learn: it's pointless. yet kids are very
curious, and they can be taught *alot* of things if they think that
they are just playing. make it interesting, and you'll be amazed how
much kids can learn almost without problems.

 Yet, civilization is made up of people like you, who would all 
 miss those mechanical systems far more than computers.
it's a huge difference between i miss my washing machine and all our
communication and data processing systems are foobared.

 They should use tools like Automator instead, no programming 
 needed:
 
 http://en.wikipedia.org/wiki/Automator_(software)
i wasn't talking about sorting out file mess. i was talking about
tabular data processing, for example, with some logics and calculations
that can't be done automatically without programming.

 Tablets are optimized for basic usage
what is basic usage? i really don't know what tablets are for. what i
can do with it? watching movie? listening music? reading book? yes,
tablets can do this... badly. what else?

i can listen music with my N900, and it fits in my pocket.

movies? on tablet screen? no, thanks.

books? electronic books are better.

tablets are like XML: bad for everything.

 Most people just need a basic appliance that isn't going to catch 
 viruses or require registry hacks.
give 'em wooden board with painting. it's great!

 It is completely different, because there are tools like 
 Automator to help you automate your workflow without needing to 
 write anything.
oh, please. i can do batch renaming with wildcards, and for any
task that is more complex than that there *is* a need to write
logic. scripts. graphic programming is a dead end. people drop icons
in favor of alphabet 'cause alphabet is just better.

 If you need to communicate something on paper- 
 well, nobody uses paper these days
i wish that the goverment of my country knows about that. and banking.
somehow they still insist to have everything written on paper.

 For most people, that is a better route, particularly if they 
 don't need to modify the script as they go and just need it 
 written once.
so instead of spending ten minutes to write the script they'll spend a
day searching for someone to hire and pay him money. great. thanks to
such people we have don't put your pet into microwave-like
instructions. and that instructions are pointless 'cause such people
never reads any instructions anyway.

most people are stupid, but that's not what scares me alot. what really
scare me is that most people *love* to be stupid and fight for the
right to be stupid with passion.

p.s. me too. i can't force myself to take English courses for five
damned years!


signature.asc
Description: PGP signature


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Sat, 18 Oct 2014 03:05:58 +0300
ketmar via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

p.p.s. just in case: i'm not talking about personalities here, sorry if
i was offencive.


signature.asc
Description: PGP signature


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread Lucas Burson via Digitalmars-d-learn
On Friday, 17 October 2014 at 17:40:09 UTC, ketmar via 
Digitalmars-d-learn wrote:



i developed a habit of making such buffers one byte bigger than
necessary and just setting the last byte to 0 before 
converting. this

way it's guaranteed to be 0-terminated.


Perfect, great idea. Below is my utility method to pull strings 
out of a buffer.



/**
 * Get a string from buffer where the string spans [offset_start, 
offset_end).

 * Params:
 *buffer = Buffer with an ASCII string to obtain.
 *offset_start = Beginning byte offset within the buffer 
where the string starts.
 *offset_end = Ending byte offset which is not included in 
the string.

 */
string bufferGetString(ubyte[] buffer, ulong offset_start, ulong 
offset_end)

in
{
   assert(buffer != null);
   assert(offset_start  offset_end);
   assert(offset_end = buffer.length);
}
body
{
   ulong bufflen = offset_end - offset_start;

   // add one to the lenth for null-termination
   ubyte[] temp = new ubyte[bufflen+1];
   temp[0..bufflen] = buffer[offset_start..offset_end];
   temp[bufflen] = '\0';

   return strip(to!string(cast(const char*) temp.ptr));
}

unittest
{
   ubyte[] no_null = [' ', 'A', 'B', 'C', ' '];
   assert(ABC == bufferGetString(no_null, 0, no_null.length));
   assert(ABC == bufferGetString(no_null, 1, no_null.length-1));
   assert(A == bufferGetString(no_null, 1, 2));
}


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Sat, 18 Oct 2014 00:32:09 +
Lucas Burson via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 On Friday, 17 October 2014 at 17:40:09 UTC, ketmar via 
 Digitalmars-d-learn wrote:
 
  i developed a habit of making such buffers one byte bigger than
  necessary and just setting the last byte to 0 before 
  converting. this
  way it's guaranteed to be 0-terminated.
 
 Perfect, great idea. Below is my utility method to pull strings 
 out of a buffer.
 
 
 /**
   * Get a string from buffer where the string spans [offset_start, 
 offset_end).
   * Params:
   *buffer = Buffer with an ASCII string to obtain.
   *offset_start = Beginning byte offset within the buffer 
 where the string starts.
   *offset_end = Ending byte offset which is not included in 
 the string.
   */
 string bufferGetString(ubyte[] buffer, ulong offset_start, ulong 
 offset_end)
 in
 {
 assert(buffer != null);
 assert(offset_start  offset_end);
 assert(offset_end = buffer.length);
 }
 body
 {
 ulong bufflen = offset_end - offset_start;
 
 // add one to the lenth for null-termination
 ubyte[] temp = new ubyte[bufflen+1];
 temp[0..bufflen] = buffer[offset_start..offset_end];
 temp[bufflen] = '\0';
 
 return strip(to!string(cast(const char*) temp.ptr));
 }
 
 unittest
 {
 ubyte[] no_null = [' ', 'A', 'B', 'C', ' '];
 assert(ABC == bufferGetString(no_null, 0, no_null.length));
 assert(ABC == bufferGetString(no_null, 1, no_null.length-1));
 assert(A == bufferGetString(no_null, 1, 2));
 }

note that you can make your code slightly simplier (and more correct):

  size_t bufflen = offset_end-offset_start;

  // add one to the lenth for null-termination
  auto temp = new ubyte[bufflen+1]; // compiler knows the type ;-)
  temp[0..$-1] = buffer[offset_start..offset_end];
  // this is not necessary, as 'temp' is initialized with zeroes
  //temp[$-1] = '\0';

   return strip(to!string(cast(const char*) temp.ptr));

also note that this allocates like crazy. ;-) this can be tolerable,
but good to remember anyway.

besides, slices rocks, so you can just pass a slice there. so:

  string bufferGetString (const(ubyte)[] buffer) {
import std.conv : to;
import std.string : strip;
if (buffer.length == 0) return null; // or 
if (buffer[$-1] == 0) return to!string(cast(char*)buffer.ptr).strip;
auto temp = new ubyte[](buffer.length+1);
temp[0..$-1] = buffer[];
return to!string(cast(char*)temp.ptr).strip;
  }

  unittest {
ubyte[] no_null = [' ', 'A', 'B', 'C', ' '];
immutable ubyte[] no_nullI = [' ', 'A', 'B', 'C', ' '];
assert(ABC == bufferGetString(no_null[0..$]));
assert(ABC == bufferGetString(no_null[1..$-1]));
// look, we can use const/immutable buffers too!
assert(A == bufferGetString(no_nullI[1..2]));
  }

slices are cheap, and you'll get range checking at the call site.


signature.asc
Description: PGP signature


Re: String created from buffer has wrong length and strip() result is incorrect

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Sat, 18 Oct 2014 00:32:09 +
Lucas Burson via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

p.s. it's ok to take '.length' from 'null' array. compiler is smart
enough.


signature.asc
Description: PGP signature


Does the grammar allow an alias statement without a semicolon?

2014-10-17 Thread Solomon E via Digitalmars-d-learn
Hi, everyone, first post here. I'm trying to learn to parse D 
code.


The line alias StorageClassesopt BasicType Declarator in 
http://dlang.org/grammar#AliasDeclaration is apparently missing a 
semicolon after Declarator.


If that line is not missing a semicolon, could someone please 
explain how it's possible to parse D, given that according to the 
grammar with that line taken literally, some statements may come 
after each other without a semicolon, and some statements may end 
with one of the keywords const, immutable, inout, or 
shared, which are keywords that come at the beginning of some 
other statements?


Re: Does the grammar allow an alias statement without a semicolon?

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Sat, 18 Oct 2014 00:52:22 +
Solomon E via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 The line alias StorageClassesopt BasicType Declarator in 
 http://dlang.org/grammar#AliasDeclaration is apparently missing a 
 semicolon after Declarator.
this line should be removed altogether to stop people using this
syntax. ;-) 'alias a = int;' is much better and clearer.

and yes, this is a bug, semicolon is not optional there.


signature.asc
Description: PGP signature


Re: Initializing D in C to use?

2014-10-17 Thread Jeremy DeHaan via Digitalmars-d-learn

On Friday, 17 October 2014 at 17:21:11 UTC, Adam D. Ruppe wrote:

On Friday, 17 October 2014 at 17:14:30 UTC, K.K. wrote:

Sorry if this isn't the most helpful answer but.. Do you have
Adam Ruppe's book?


buy my book too, and write amazon reviews :P

A lot of the topics in there were chosen because there are 
questions that come up somewhat often on this forum or the D 
chat room. I answer a lot of questions here too, but the book 
is cool too!


I actually do own it!

I just haven't had as much time as I would like to go through it.


Thanks for the answers everyone!


Re: Does the grammar allow an alias statement without a semicolon?

2014-10-17 Thread thedeemon via Digitalmars-d-learn

On Saturday, 18 October 2014 at 00:52:23 UTC, Solomon E wrote:
Hi, everyone, first post here. I'm trying to learn to parse D 
code.


Just in case, I'll remind these two projects that might be 
helpful:

https://github.com/Hackerpilot/libdparse
https://github.com/Hackerpilot/DGrammar


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread RBfromME via Digitalmars-d-learn

On Thursday, 16 October 2014 at 22:26:51 UTC, RBfromME wrote:
I'm a newbie to programming and have been looking into the D 
lang as a general purposing language to learn, yet the D 
overview indicates that java would be a better language to 
learn for your first programming language. Why?  Looks like D 
is easier than Java...


Thank you for taking the time to respond to my inquiry.  I've 
been reading up on different languages for some time now. I have 
experimented with python some and have  created a few minor 
scripts. It's fairly easy to get going with the basics , but i 
don't find the basics any easier to  learn than D's.  The biggest 
issue i personal find in getting deeper into  a language is the 
docs and examples. The python examples, beyond the basics usually 
get write into OO so you find your self trying to figure out OO 
while trying to sift through the examples.  Makes it a little 
harder to get going and figure out the available libraries while 
trying to figure OO at the same time.
The second thing that would help a beginner move forward is the 
documentation  on the libraries. I see D has  standard libraries 
along with third parties. And I believe , if i read it properly, 
D can us C libraries. It would be helpful to see examples on how 
to use C libs with D since D is still new and its library 
packages is still small.
Summing it up, I personally think the hardest part in learning to 
use a specific language is the docs and and examples because they 
all throw you write into OO and you spend more time trying to 
figure out OO instead of how to use the standard lib or third 
party lib to get a basic task done.


Thank you Ali Cehreli for taking the time to write the D 
tutorial. It's appreciated by people like me.


Re: Beginner ?. Why does D suggest to learn java

2014-10-17 Thread Rikki Cattermole via Digitalmars-d-learn

On 18/10/2014 3:00 p.m., RBfromME wrote:

On Thursday, 16 October 2014 at 22:26:51 UTC, RBfromME wrote:

I'm a newbie to programming and have been looking into the D lang as a
general purposing language to learn, yet the D overview indicates that
java would be a better language to learn for your first programming
language. Why?  Looks like D is easier than Java...


Thank you for taking the time to respond to my inquiry.  I've been
reading up on different languages for some time now. I have experimented
with python some and have  created a few minor scripts. It's fairly easy
to get going with the basics , but i don't find the basics any easier
to  learn than D's.  The biggest issue i personal find in getting deeper
into  a language is the docs and examples. The python examples, beyond
the basics usually get write into OO so you find your self trying to
figure out OO while trying to sift through the examples.  Makes it a
little harder to get going and figure out the available libraries while
trying to figure OO at the same time.
The second thing that would help a beginner move forward is the
documentation  on the libraries. I see D has  standard libraries along
with third parties. And I believe , if i read it properly, D can us C
libraries. It would be helpful to see examples on how to use C libs with
D since D is still new and its library packages is still small.


If you want to see shared libraries with a c interface bound to D 
DerelictOrg is a great place to look[0].



Summing it up, I personally think the hardest part in learning to use a
specific language is the docs and and examples because they all throw
you write into OO and you spend more time trying to figure out OO
instead of how to use the standard lib or third party lib to get a basic
task done.


I and I'm sure others, will be happy to talk with you about any concepts 
and ideas that you have trouble understanding. Just let us know.



Thank you Ali Cehreli for taking the time to write the D tutorial. It's
appreciated by people like me.


[0] https://github.com/DerelictOrg


Re: Does the grammar allow an alias statement without a semicolon?

2014-10-17 Thread Solomon E via Digitalmars-d-learn
Thank you both. That DGrammar project has some different names 
for the nonterminals in its grammar, and a different arrangement, 
but it confirms there should be a semicolon with any alias 
statement. I'm just trying to parse D when I read it myself so 
far, and figure out how the grammar works a little. I'm not 
trying to write a parser for it, at least not yet.


Re: Does the grammar allow an alias statement without a semicolon?

2014-10-17 Thread ketmar via Digitalmars-d-learn
On Sat, 18 Oct 2014 02:54:21 +
Solomon E via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 Thank you both. That DGrammar project has some different names 
 for the nonterminals in its grammar, and a different arrangement, 
 but it confirms there should be a semicolon with any alias 
 statement. I'm just trying to parse D when I read it myself so 
 far, and figure out how the grammar works a little. I'm not 
 trying to write a parser for it, at least not yet.
btw, you can fill a bug report for this.


signature.asc
Description: PGP signature