Re: Help me decide D or C

2019-08-01 Thread Aurélien Plazzotta via Digitalmars-d-learn

On Thursday, 1 August 2019 at 16:23:51 UTC, Alexandre wrote:

On Thursday, 1 August 2019 at 15:42:08 UTC, a11e99z wrote:

On Thursday, 1 August 2019 at 15:17:11 UTC, a11e99z wrote:



Right now, job is not a good criteria for me. I work in a not 
related field and I doubt I would get any job working with CS. 
That would be great, but I doubt it anyway, so it is more a 
hobby thing.


If penetrating a job segment-market is not a requirement, perhaps 
you would take pleasure in learning F*. It is a pure functional 
programming language based on logical-mathematical thought. It 
meant to be a replacement for Coq, a proof-assistant turned into 
general-purpose language.


In my opinion, this kind of paradigm would fit quite well in the 
near-future RISCV technological and commercial market since their 
technical specifications have been feature-ready.


Here is the official tutorial for F* language:
https://www.fstar-lang.org/tutorial/

I hope this kind of project is the last step before entering the 
realm of quantum programming because it is time to embrace the 
change.
Quantum mechanics are known since the 1930's, quantum physics 
since 50's, quantum information since 70's, quantum computation 
since 2000's. What are we waiting for quantum programming? Again 
the same and always pathological syndromes remain: "not invented 
here" and "it's if not broken, don't fix it."


But don't fool yourself, D is not for beginners. Ali Çehreli is a 
very skilled programmer, ergo, he can't reason like a 
new/starting programmer anymore, regardless of his patience and 
kindness.




Re: Why does choose not work here

2019-08-01 Thread ag0aep6g via Digitalmars-d-learn

On 01.08.19 22:23, Matt wrote:
Version 4 does not work when PairedA.previous is null. I'd love to 
understand why.



[...]


auto myFilter(R1, R2)(R1 a, R2 b)
{
 import std.algorithm : filter, canFind;
 return a.filter!(c => b.canFind(c));
}

struct A
{
 uint[] starts, stops;

 import std.range : ForwardRange, inputRangeObject;
 import std.typecons : Tuple;
 ForwardRange!(Tuple!(uint,uint)) intervalRange() @property
 {
     import std.algorithm : map;
     import std.range : zip;
     import std.typecons : tuple;
     return zip(starts,stops).map!(a => 
tuple(a[0],a[1])).inputRangeObject;

 }
}

struct PairedA
{

[...]

 //version 4
 auto uniqIntervals() @property
 {
     import std.range : choose;
     import std.algorithm : filter, canFind;
     return choose(previous is null,
     primary.intervalRange,
     primary.intervalRange
     .myFilter(previous.intervalRange));
 }

 A primary;
 A* previous;
}


`choose`'s parameters aren't lazy. So the second argument is evaluated 
even when `previous is null`. That means `intervalRange` is called on a 
null `previous`. And that fails, of course, because `intervalRange` 
can't access `starts` or `stops` when `this` is null.


Why does choose not work here

2019-08-01 Thread Matt via Digitalmars-d-learn
I'm having some trouble with a "Program exited with code 
-1073741819" error in some code I'm writing and I would 
appreciate any help/insight.


The problem stems from some incompatibility between the Phobos 
function "choose" and the template function "myFilter" which 
returns a range. The code below is a simplified version of what 
I'm trying to do. myFilter is a dummy/stand-in function that 
highlights the error in my program (i.e. My function is not 
simply a filter; it is much more complicated but unnecessary to 
highlight my problem). In PairedA, sometimes previous will be 
null. I need the uniqIntervals member function to do the right 
thing depending on if previous is null or not. In an ideal 
situation uniqIntervals would return a forward range where the 
work would be done in a lazy fashion.


Version 1 works but is not lazy and does not use choose.
Version 2 works but requires converting the ranges to 
ForwardRange classes, (I'd prefer to not use an unnecessary level 
of indirection).
Version 3 uses the Phobos function filter which works inside 
choose (but there is no Phobos function that can actual do why 
myFilter stands in for. It's just interesting that the Phobos 
function works where myFilter doesn't as they are both template 
functions.
Version 4 does not work when PairedA.previous is null. I'd love 
to understand why.


I'd also love to some one to show me what the best way to do this 
would be. If version 2 is the best I can do, I'll live with it.


Thanks so much, the code is below:

auto myFilter(R1, R2)(R1 a, R2 b)
{
import std.algorithm : filter, canFind;
return a.filter!(c => b.canFind(c));
}

struct A
{
uint[] starts, stops;

import std.range : ForwardRange, inputRangeObject;
import std.typecons : Tuple;
ForwardRange!(Tuple!(uint,uint)) intervalRange() @property
{
import std.algorithm : map;
import std.range : zip;
import std.typecons : tuple;
		return zip(starts,stops).map!(a => 
tuple(a[0],a[1])).inputRangeObject;

}
}

struct PairedA
{
//version 1
// auto uniqIntervals() @property
// {
//  import std.array : array;
//  if (previous is null) return primary.intervalRange.array;
//  return primary.intervalRange
//  .myFilter(previous.intervalRange).array;
// }

//version 2
// import std.range : ForwardRange, inputRangeObject;
// import std.typecons : Tuple;
// ForwardRange!(Tuple!(uint,uint)) uniqIntervals() @property
// {
	// 	if (previous is null) return 
primary.intervalRange.inputRangeObject;

//  return primary.intervalRange
//  .myFilter(previous.intervalRange).inputRangeObject;
// }

//version 3
// auto uniqIntervals() @property
// {
//  import std.range : choose;
//  import std.algorithm : filter, canFind;
//  return choose(previous is null,
//  primary.intervalRange,
//  primary.intervalRange
//  .filter!(a => 
previous.intervalRange.canFind(a)));
// }

//version 4
auto uniqIntervals() @property
{
import std.range : choose;
import std.algorithm : filter, canFind;
return choose(previous is null,
primary.intervalRange,
primary.intervalRange
.myFilter(previous.intervalRange));
}

A primary;
A* previous;
}

unittest
{
uint[] startsA = [1,100,1000,1];
uint[] stopsA = [2,200,2000,2];
uint[] startsB = [1,100];
uint[] stopsB = [2,200];

auto a1 = A(startsA, stopsA);
auto a2 = A(startsB, stopsB);

auto p = PairedA(a1, );
auto p2 = PairedA(a1, null);

import std.stdio : writeln;
writeln(p.uniqIntervals);//always works
	writeln(p2.uniqIntervals);//Program exited with code -1073741819 
for version 4

}


Re: Why does choose not work here

2019-08-01 Thread Matt via Digitalmars-d-learn

On Thursday, 1 August 2019 at 21:12:51 UTC, ag0aep6g wrote:
`choose`'s parameters aren't lazy. So the second argument is 
evaluated even when `previous is null`. That means 
`intervalRange` is called on a null `previous`. And that fails, 
of course, because `intervalRange` can't access `starts` or 
`stops` when `this` is null.


I forgot about lazy parameters. I tried changes myFilters second 
parameter to lazy, but that didn't help. So I guess I'm stuck 
with the "if" version using the ForwardRange interface (version 
2)? Anyone have any other thoughts?


Re: Help me decide D or C

2019-08-01 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 22:30:52 UTC, Alexandre wrote:

1) Improve as a programmer
2) Have fun doing programs

Thats it basically. I am planning to study all "free" time I 
have. I am doing basically this since last year.


Try Basic. It has builtin graphics, seeing you program draw is 
quite fascinating.


Re: Help me decide D or C

2019-08-01 Thread Murilo via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote:

Hi everyone,

I would like an honest opinion.
I have a beginner level (able to do very small programs) in a 
few languages  such as python, go, C, guile(scheme) and common 
lisp. I want to pick a language and go deep with it and focus 
on only one for at least the next 2 years or so.


Should I go for C and then when I become a better programmer 
change to D?

Should I start with D right now?


Here goes something that may help you. A multimedia tutorial in D 
with a lib called arsd. I am nearly done with the tutorial and it 
is now very complete, it now teaches how to use the arsd library 
to draw all sorts of stuff and to receive mouse and keyboard 
input. I think you will like it. If you use it and like it please 
let me know because I would be very happy to see my work being 
spread. Cheers. Here is the GitHub page: 
https://github.com/MuriloMir/arsd_multimedia_tutorial


Re: Help me decide D or C

2019-08-01 Thread Russel Winder via Digitalmars-d-learn
On Thu, 2019-08-01 at 14:49 +, bachmeier via Digitalmars-d-learn wrote:
[…]
> There's nothing wrong with Haskell if you want to take a deep 
> dive into pure functional programming. I personally find Haskell 
> to be more of a religion than a programming language. You can 
> learn the same perspective from functional-first languages like 
> Clojure, Scala, Ocaml, and F#.
[…]

Whilst I agree that most "this is the one true programming language" people
are quasi-religious, programming languages are not: Haskell is a just a lazy,
pure functional programming language, some adherents show quasi-religious
fervour, just as some adherents of C++, Java, C, Go, Rust, D, etc. do.

I am not sure about F# (I do not know anything of it), but Clojure, Scala, and
OCaml are very different from Haskell for various reasons, cf. lazy vs. eager,
pure vs. impure. Haskell is a programming language worth learning for all
programmers,along with Lisp, Prolog, and Erlang.

I'll bet (but I have no experimental data, just a hypothesis) that any D
programmer that knows Haskell writes better D than a D programmer who doesn't
know Haskell.

-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk



signature.asc
Description: This is a digitally signed message part


Re: Help me decide D or C

2019-08-01 Thread ryuo via Digitalmars-d-learn
I have spent the better part of 10 years with C, and it was my 
first serious language. I would say go with D if you just want to 
work on higher level projects and forego the low level details to 
an extent. C is very low level and very unforgiving. The 
inexperienced will run into things like segmentation faults or 
other memory errors until they understand how pointers and memory 
works.


Also, while D has fewer available resources than C does, C is 
also an entirely different beast. The C standard library is very 
limited, only providing some very basic functionality. Advanced 
data structure implementations are not provided by it so you 
would be forced to either write your own or use a suitable third 
party library. Contrast this with C++ or D where such things are 
likely already provided by their standard libraries.


In short, C is generally used to implement a foundation of sorts 
for higher level programs or other ventures where low level 
control is a requirement. For example, it is common to implement 
general purpose libraries for things like compression or 
encryption in C for performance reasons and also for reusable 
code. Libraries written in C can generally be used by any 
language that runs natively, usually through a binding or a 
translation of the library API.




Re: Help me decide D or C

2019-08-01 Thread Alexandre via Digitalmars-d-learn

On Thursday, 1 August 2019 at 15:42:08 UTC, a11e99z wrote:

On Thursday, 1 August 2019 at 15:17:11 UTC, a11e99z wrote:

[...]


imo better choice is (with criteria to find best job)
- Qt:
C++ with any library that u need in one style
- C#:
web, graphics, mobiles, command tools with nice language.
- Java/Kotlin:
same as C# but in top-3. C# is top-5 with more comfort 
language than Java. Kotlin same comfort as C#, but JVM (Virtual 
Machine of Java and Kotlin) still does not support value types, 
that is sucks.

- JavaScript/TypeScript:
web-browser language with node.js that allows to program 
server side too.

- You can try Python too.
another dynamic language (as JavaScript). I don't like 
langs that based on space/tabs so I can not say anything about 
it.


[...]


Right now, job is not a good criteria for me. I work in a not 
related field and I doubt I would get any job working with CS. 
That would be great, but I doubt it anyway, so it is more a hobby 
thing.


Re: Help me decide D or C

2019-08-01 Thread bachmeier via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 23:42:10 UTC, SashaGreat wrote:


About Mike's book, you're talking about this one:

https://www.amazon.com/Learning-D-Michael-Parker/dp/1783552484/ref=as_li_ss_tl?ie=UTF8=1448974911=8-1=learning+d=sl1=aldacron-20=d696b771c78030fc272e9b853986a708


Yep. It provides a lot of detail on a lot of topics. We're lucky 
to have a number of good books.


Re: Help me decide D or C

2019-08-01 Thread JN via Digitalmars-d-learn

On Thursday, 1 August 2019 at 09:43:20 UTC, Kagamin wrote:

On Wednesday, 31 July 2019 at 22:30:52 UTC, Alexandre wrote:

1) Improve as a programmer
2) Have fun doing programs

Thats it basically. I am planning to study all "free" time I 
have. I am doing basically this since last year.


Try Basic. It has builtin graphics, seeing you program draw is 
quite fascinating.


What variant of Basic? Visual Basic?

I think https://processing.org/ is the best if you want to "code 
with drawing"


Re: Help me decide D or C

2019-08-01 Thread matheus via Digitalmars-d-learn

On Thursday, 1 August 2019 at 09:43:20 UTC, Kagamin wrote:

On Wednesday, 31 July 2019 at 22:30:52 UTC, Alexandre wrote:

1) Improve as a programmer
2) Have fun doing programs

Thats it basically. I am planning to study all "free" time I 
have. I am doing basically this since last year.


Try Basic. It has builtin graphics, seeing you program draw is 
quite fascinating.


In that case I'd recommend EvalDraw: 
http://advsys.net/ken/download.htm with a C-like syntax with draw 
things while you type.


Description:

"A complete programming environment with built-in compiler, text 
editor, and functions to allow for quick prototyping. With 
Evaldraw, you can make graphs in any dimension (1D, 2D, 3D), 
animations, custom musical instruments, voxel models, and general 
purpose applications. I've included a lot of examples, so even if 
you're not a programmer, you can look at the demos"


It was written by Ken Silverman (Creator of Build Engine - Duke 
Nukem 3D).


Matheus.


Re: Example uses "volatile"; compiler says "undefined identifier volatile"

2019-08-01 Thread Paul via Digitalmars-d-learn

Thank you.  I'll try that.




Re: Help me decide D or C

2019-08-01 Thread a11e99z via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote:

Hi everyone,

I would like an honest opinion.
I have a beginner level (able to do very small programs) in a 
few languages  such as python, go, C, guile(scheme) and common 
lisp. I want to pick a language and go deep with it and focus 
on only one for at least the next 2 years or so.




program bouncing ball on few languages and choose that more liked.
learning language with numbers and strings only is boring.

also you can program tasks from 
https://www.codingame.com/training/easy with dozen languages in 
web browser before install to local machine.
some of them contains graphics 
https://www.codingame.com/ide/puzzle/power-of-thor-episode-1 when 
u run tests.
read data from stdin, print result to stdout, and use stderr for 
debugging with diagnostics messages.


Re: Help me decide D or C

2019-08-01 Thread bachmeier via Digitalmars-d-learn

On Thursday, 1 August 2019 at 03:59:23 UTC, Bert wrote:

But if you really want to learn to program I suggest you go 
with Haskell. You can do them all together too but Haskell is 
like learning Alien while D is learning German.


There's nothing wrong with Haskell if you want to take a deep 
dive into pure functional programming. I personally find Haskell 
to be more of a religion than a programming language. You can 
learn the same perspective from functional-first languages like 
Clojure, Scala, Ocaml, and F#.


The most common reason I hear for learning C is that you learn 
the foundation on which everything is built. And in one sense 
that's kind of true. It's portable assembly. The problem is that 
you don't learn much about programming, because C has so few 
features, and that limits you to (a) working on a narrow set of 
problems or (b) very slowly writing bug-ridden solutions to a 
wider group of problems.


A big part of programming is learning about all the different 
ways to attack problems. You can go a long way with D, unlike C 
or Haskell.


Re: Help me decide D or C

2019-08-01 Thread a11e99z via Digitalmars-d-learn

On Thursday, 1 August 2019 at 15:17:11 UTC, a11e99z wrote:

On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote:

Hi everyone,

I would like an honest opinion.
I have a beginner level (able to do very small programs) in a 
few languages  such as python, go, C, guile(scheme) and common 
lisp. I want to pick a language and go deep with it and focus 
on only one for at least the next 2 years or so.




program bouncing ball on few languages and choose that more 
liked.

learning language with numbers and strings only is boring.

also you can program tasks from 
https://www.codingame.com/training/easy with dozen languages in 
web browser before install to local machine.
some of them contains graphics 
https://www.codingame.com/ide/puzzle/power-of-thor-episode-1 
when u run tests.
read data from stdin, print result to stdout, and use stderr 
for debugging with diagnostics messages.


imo better choice is (with criteria to find best job)
- Qt:
C++ with any library that u need in one style
- C#:
web, graphics, mobiles, command tools with nice language.
- Java/Kotlin:
same as C# but in top-3. C# is top-5 with more comfort 
language than Java. Kotlin same comfort as C#, but JVM (Virtual 
Machine of Java and Kotlin) still does not support value types, 
that is sucks.

- JavaScript/TypeScript:
web-browser language with node.js that allows to program 
server side too.

- You can try Python too.
another dynamic language (as JavaScript). I don't like langs 
that based on space/tabs so I can not say anything about it.


C is too low level language. and many resources is not best 
criteria for it.
(like people says "there's definitely something in the shit, a 
million flies can't be wrong").


D is stuck in some middle ages with subsistence economy, they 
still have stone tools but now they found iron/steel :)