Re: question as to when a new command gets executed

2020-11-11 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 11 November 2020 at 22:29:00 UTC, SealabJaster 
wrote:
On Wednesday, 11 November 2020 at 22:10:38 UTC, WhatMeWorry 
wrote:
Thanks.  Would you or anyone reading this know if this is 
unique to D or does C++ also behave like this?  Also, where is 
the memory, that new allocates? Is it in the heap (thought 
heap was available only at runtime) or some other place? 
(Certainly not the stack, right?)



I'm pretty sure this is the way it works in C# as well.


C# isn't compile time, it is more a pre-constructor generated by 
the compiler.


Re: Return values from auto function

2020-11-07 Thread Jesse Phillips via Digitalmars-d-learn

On Saturday, 7 November 2020 at 15:49:13 UTC, James Blachly wrote:


```
return i > 0 ? cast(Result) Success!int(i) : cast(Result) 
Failure("Sorry");

```



I don't know about the SumType but I would expect you could use a 
construction instead of cast.


import std;
alias Result = Algebraic!(int, string) ;
void main()
{
    auto x = true? Result("fish") : Result(6);

}


Re: Return values from auto function

2020-11-06 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 6 November 2020 at 15:06:18 UTC, Andrey Zherikov wrote:
On Friday, 6 November 2020 at 14:58:40 UTC, Jesse Phillips 
wrote:
On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov 
wrote:
This issue seems hit the inability to implicitly convert 
custom types. May be it makes more sense to ask in a separate 
thread.


The return type must be the same for all execution paths.

Result!void is a different type from Result!int. You aren't 
passing a 'Result' because that doesn't exist as a type.


To clarify my statement:
Yes, Result!void and Result!int are different types but I 
couldn't find a way to implicitly convert one to another.


Putting aside D not providing implicit conversion to custom types.

I'm curious what your semantics would be.

# Result!void => Result!int

How does the type know it can convert to int, or string, or Foo?

What does it mean for a void to be an int?

# Result!int => Result!void

If you have something, what does it mean to go to not having that 
something. Would you really want to implicitly lose that 
something?




Re: Return values from auto function

2020-11-06 Thread Jesse Phillips via Digitalmars-d-learn
On Friday, 6 November 2020 at 20:05:36 UTC, Ferhat Kurtulmuş 
wrote:
On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov 
wrote:
I have auto function 'f' that might return either an error 
(with some text) or a result (with some value). The problem is 
that the type of the error is not the same as the type of 
result so compilation fails.


[...]


Sounds like Andrei's "Expected". Here is an implementation for 
d. https://github.com/tchaloupka/expected


Hmmm, I wonder how that is different from the idea of 'option'


Re: Return values from auto function

2020-11-06 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov wrote:

On Friday, 6 November 2020 at 12:03:01 UTC, Paul Backus wrote:
You can't. Both return values have to have the same type, 
which means the failure function has to be able to return more 
than one type, which means it has to be a template.


This issue seems hit the inability to implicitly convert custom 
types. May be it makes more sense to ask in a separate thread.


The return type must be the same for all execution paths.

Result!void is a different type from Result!int. You aren't 
passing a 'Result' because that doesn't exist as a type.


Hopefully one of these captures a misunderstanding.


Re: Why is vibe.d json serializer/deserializer so complex?

2020-10-31 Thread Jesse Phillips via Digitalmars-d-learn

On Saturday, 31 October 2020 at 22:42:20 UTC, James Blachly wrote:

So I've been meaning to ask this as I have been learning Rust 
off-and-on recently for web development, and was impressed by 
the traits functionality. In particular, with traits and some 
agreed upon API, many packages are interchangeable in terms of 
various functionalities, including JSON 
serialization/deserialization.


What would be the nearest analog facility in D -- supposing we 
could agree on a standard API -- to facilitate pluggable 
serializers?


I am a big fan of asdf (and Steve, haven't tried iopipejson 
yet, but will do). It would be nice to not rewrite code to try 
a different serializer, and Rust is really neat in this regard.


Well I was putting this together, but didn't want to attempt 
submission until I felt I would be able to put in the time for 
the review process


https://github.com/JesseKPhillips/DIPs/blob/serialize/attribute/DIPs/1NNN-jkp.md


Re: I think Associative Array should throw Exception

2020-09-03 Thread Jesse Phillips via Digitalmars-d-learn
On Thursday, 3 September 2020 at 15:12:14 UTC, Steven 
Schveighoffer wrote:

int[int] aa;
aa[4] = 5;
auto b = aa[4];

How is this code broken? It's valid, will never throw, and 
there's no reason that we should break it by adding an 
exception into the mix.




int foo() nothrow {
return "1".to!int;
}

The following code is valid, will never throw, why does the 
compiler prevent it?


Re: I think Associative Array should throw Exception

2020-09-03 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 1 September 2020 at 18:55:20 UTC, Steven 
Schveighoffer wrote:

On 9/1/20 2:20 PM, Jesse Phillips wrote:

Using RangeError is nice as it allows code to use array index 
inside `nothrow.`


This is the big sticking point -- code that is nothrow would no 
longer be able to use AAs. It makes the idea, unfortunately, a 
non-starter.


What is wrong with using `in`? I use this mostly:

if(auto v = key in aa) { /* use v */ }



I think that actually might be my point. If you need nothrow then 
this is what you need to do.


For breaking nothrow code using the [] syntax, I'd say it is 
already broken because the behavior is to throw and the above is 
how you would check that it won't.


The issue is, associative arrays throw an "uncatchable" error. 
Meaning code is written to catch the error (because it works). 
And correctly written `nothrow` code needs to use `in` to be 
properly nothrow.


I think Associative Array should throw Exception

2020-09-01 Thread Jesse Phillips via Digitalmars-d-learn
This is going to be a hard one for me to argue but I'm going to 
give it a try.


Today if you attempt to access a key from an associative array 
(AA) that does not exist inside the array, a RangeError is 
thrown. This is similar to when an array is accessed outside the 
bounds.


```
string[string] dict;
dict["Hello"] // RangeError

string[] arr;
arr[6] // RangeError
```

There are many things written[1][2] on the difference between 
Exception and Error.


* Errors are for programming bugs and Exceptions are environmental
* Exceptions can be caught, Errors shouldn't be (stack may not 
unwind)

* Exceptions are recoverable, Errors aren't recoverable
* Errors can live in nothrow, Exceptions can't
* Always verify input

I don't have an issue with the normal array RangeError, there is 
a clear means for claiming your access is a programming bug. 
However associative arrays tend to have both the key and value as 
"input."


Trying to create a contract for any given method to validate the 
AA as input becomes cumbersome. I would say it is analogous to 
`find` throwing an error if it didn't find the value requested.


Using RangeError is nice as it allows code to use array index 
inside `nothrow.` But again, can we really review code and say 
this will be the case? We'd  have to enforce all access to 
associative arrays to be done using `in` and checked for null. 
Then what use is the [] syntax?


Is it recoverable? I would say yes. We aren't actually trying to 
access memory outside the application ownership, we haven't put 
the system state into a critical situation (out of memory). And a 
higher portion of the code could easily decide to take a 
different path due to the failure of its call.


"if exceptions are thrown for errors instead, the programmer has 
to deliberately add code if he wishes to ignore the error."


1. 
https://stackoverflow.com/questions/5813614/what-is-difference-between-errors-and-exceptions

2. https://forum.dlang.org/thread/m8tkfm$ret$1...@digitalmars.com


Re: Installing D on Fresh Windows 10 machine is a pain

2020-08-31 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 28 August 2020 at 14:36:57 UTC, rikki cattermole wrote:

On 28/08/2020 3:59 AM, Jesse Phillips wrote:


DMD installer still is unable to find "VS installed"


One of the reasons for this is that the environment variables 
have not been updated.


You need to restart to do this.


This might have been the issue, I don't recall it requesting a 
restart and I don't know if I restarted when I had gotten it 
fixed (I don't think I did).


I unistalled everything (VS and C++ redistributables) then 
restarted. Installed the C++ development environment with VS and 
restarted. Seems that it builds now.


Re: Installing D on Fresh Windows 10 machine is a pain

2020-08-27 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 27 August 2020 at 15:59:51 UTC, Jesse Phillips wrote:



Upon compiling a 64bit hello world I get

helloworld> dmd -m64 .\hello.d
LINK : fatal error LNK1104: cannot open file 'libucrt.lib'
Error: linker exited with status 1104


I solved this by either installing c++ development tools from 
Community or by switching my path to the 64bit DMD.


Installing D on Fresh Windows 10 machine is a pain

2020-08-27 Thread Jesse Phillips via Digitalmars-d-learn
Installing D isn't new to me but I haven't really had to do a 
fresh install for awhile and come from a time when I was 
installing VS from 2010 and up.


VS 2019 Professional is installed on the system.

I have installed the C++ desktop development for VS.

DMD installer still is unable to find "VS installed"

I've also installed the C++ 2010 redistributables to try and use 
the MinGW install path.


I've also utilized the developer command prompt
---

Upon compiling a 64bit hello world I get

helloworld> dmd -m64 .\hello.d
LINK : fatal error LNK1104: cannot open file 'libucrt.lib'
Error: linker exited with status 1104

This appears to have been a library moved around VS 2015 release, 
and I don't want to do the copying around solution the internet 
suggests.


I understand that as a compiler it is important to support 
systems of an older nature and so updating to the latest C++ 
runtimes might hinder usage of D.


It is just sad that at one point the install really did just take 
care of things and now it can't find things.


Re: Send empty assoc array to function

2020-07-09 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 9 July 2020 at 20:08:47 UTC, Anonymouse wrote:

On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote:

void foo(int[int] bar)
{
// ...
}



Is it possible to send an empty array literal?

foo( [ 0 : 2 ] ) works
foo( [] ) doesn't

int[int] empty;
foo(empty);
works but it's two lines


I always did foo((int[int]).init);


Isn't that just 'null'.

I want to make note that you cannot pass null, modify the aa, and 
expect the parent stack to see those changes. Since you aren't 
using a variable that is null you are fine.


Re: Why is there no std.stream anymore?

2020-06-18 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 18 June 2020 at 14:53:58 UTC, aberba wrote:
On Tuesday, 12 December 2017 at 20:51:30 UTC, Steven 
Schveighoffer wrote:

On 12/11/17 6:33 PM, Seb wrote:

[...]
Since iopipe was mentioned several times, I will say a couple 
things:


[...]



I should really try iopipe this time round. I think I avoided 
toying with it because the making conventions put me off. Don't 
remember about the docs and available examples though.


I too was trying to utilize iopipe and asked questions earlier 
this year[1] and I made a file writer util[2]. I haven't really 
taken advantage of the power yet, though it does appear that be a 
really nice abstraction.


1. 
https://forum.dlang.org/thread/faawejguebluwodfl...@forum.dlang.org
2. 
https://gitlab.com/jessephillips/devarticlator/-/blob/master/source/util/file.d


Re: Why is there no range iteration with index by the language?

2020-06-10 Thread Jesse Phillips via Digitalmars-d-learn

On Tuesday, 9 June 2020 at 23:53:16 UTC, Q. Schroll wrote:
Is there any particular reason why std.range : enumerate is a 
thing


Someone already mentioned dictionary.

Consider that most ranges don't actually have an index. In this 
case you aren't actually asking to add indexes, but a count of 
iteration.


For those ranges which do have indexing, what if the range is 
iterating from a location in the middle. Now you have an 
iteration count but not the true index. `enumerate` allows for 
specifying a starting number but this still isn't sufficient 
since a filter could easily jump to any index.


Now none of this may come as a surprise to you, but having an 
iteration counter and an array index using the same api does open 
the door for confusion.


Re: Alpine support for D

2020-06-10 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 10 June 2020 at 01:06:30 UTC, aberba wrote:

On Tuesday, 9 June 2020 at 14:23:34 UTC, Jesse Phillips wrote:
I notice that in the new release for Alpine Linux it mentions 
support for D.


I was curious what was meant by this and thought someone here 
would know. Just high level, like druntime was ported or 
packages added to the repo?


Tradionally you'd run D on something like Ubuntu, etc but 
Alpine is lightweight which is a good thing when building 
docker containers. Alpine uses a different C runtime musl?? 
among other things whilst D uses use libc. So I believe we now 
have bindings musl too to get D to work on Alpine.


Thank you. So it sounds like there are D compiler packages, and 
you can use alpine to execute programs written in D.


Alpine support for D

2020-06-09 Thread Jesse Phillips via Digitalmars-d-learn
I notice that in the new release for Alpine Linux it mentions 
support for D.


I was curious what was meant by this and thought someone here 
would know. Just high level, like druntime was ported or packages 
added to the repo?


Re: Array fill performance differences between for, foreach, slice

2020-04-01 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 1 April 2020 at 12:22:48 UTC, Adam D. Ruppe wrote:
On Wednesday, 1 April 2020 at 06:48:09 UTC, Jacob Carlborg 
wrote:
You have not enabled optimizations. You should compile with 
`-O -release -inline` to enable all optimizations.


-release should *never* be used. You're trading memory safety 
and security holes for a few microseconds of execution time. 
Not worth the risk.




It is nice that bounds checks remain in place when using release 
and the code is @safe.


Re: Converting Lua source to D

2020-03-08 Thread Jesse Phillips via Digitalmars-d-learn

On Saturday, 7 March 2020 at 01:14:14 UTC, Jesse Phillips wrote:


Now I should look at getting the CI up and Test failure fixed.


Test failures were my local system and related to the stack 
overflow tests.


I have the build pipeline up and running but hit a couple of 
snags.

https://github.com/JesseKPhillips/lua/runs/493866555?check_suite_focus=true

* Couldn't use dpp in the build because I couldn't install 
libclang-dev on the runner (ubuntu repository issue)

* The compiler couldn't locate libphobos

I think I'll be able to make use of dpp locally though.


Re: How to use sets in D?

2020-03-08 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 7 February 2020 at 19:37:08 UTC, mark wrote:
I am porting code from other languages to D as part of learning 
D, and I find I've used sets quite a lot. AFAIK D doesn't have 
a built-in set type or one in the std. lib.


However, I've been perfectly successfully using int[E] where E 
is my ElementType, and adding with set[element] = 0. I mostly 
only need add, remove, iteration, and in, with uniqueness what 
I care most about.


I know I could use bool[E] and set[element] = false, or I 
suppose container.rbtree. Would either of these--or something 
else built-in or in the std. lib.--be better?


I think I've usually used the associative arrays, but I also 
think I tend to avoid using this approach but couldn't quite 
remember what I do instead.


I believe I have started just using an array.

arr ~= addMyData;
arr.sort.uniq

Then I make use of the algorithms here.

https://dlang.org/phobos/std_algorithm_setops.html


Re: Converting Lua source to D

2020-03-06 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 5 March 2020 at 16:54:35 UTC, AB wrote:

I am only guessing, but I think the problem is line 87.
Arrays and slices in D contain a length field and thus do not 
need to be null terminated.
The foreach at line 96 iterates on all valid indices and thus 
in the last iteration you call luaL_requiref(L, null, null, 1).


Try changing

static const luaL_Reg[] loadedlibs = [
  ...
  {LUA_DBLIBNAME, _debug},
  {null, null}
];

to

static const luaL_Reg[] loadedlibs = [
  ...
  {LUA_DBLIBNAME, _debug}
];


I knew I was blind, thank you. Segfault is gone.

Now I should look at getting the CI up and Test failure fixed.



Converting Lua source to D

2020-03-04 Thread Jesse Phillips via Digitalmars-d-learn
I am making an attempt convert Lua to D. This is less about the 
conversion and more about exploring the tooling to make it happen.


I have chosen to do this file by file and attempting to start 
with linint. I wanted to make use of dpp, however I hit a 
segmentation fault and reduced dependency.


https://github.com/JesseKPhillips/lua/blob/dpp/init/linit.d

I wasn't able to get a core dump for debugging. Anyone willing to 
give some advice or solution? I have gone through a number of 
compilers and better.


I have implemented a build pipeline but didn't incorporate the D 
portion at this time.


Re: iopipe: Writing output to std.io File

2020-01-29 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 28 January 2020 at 16:09:55 UTC, Steven Schveighoffer 
wrote:


Everything is pulled with iopipe, even output, so it's just a 
matter of who is pulling and when. Pushing is a matter of 
telling the other end to pull.


-Steve


That statement I think will be very helpful to me.

The push would control the buffer, creating that value concept, 
where the buffer is flush which creates a pull, specified in the 
delegate.


Pusher(buffer) <- put(content)

An output range wrapper would provide a push interface which 
would fill in the buffer of the Pusher. When the buffer fills the 
range wrapper would ask to release which Pusher does by calling 
the delegate.


Hopefully I'm following this correctly.






Re: iopipe: Writing output to std.io File

2020-01-27 Thread Jesse Phillips via Digitalmars-d-learn
On Monday, 27 January 2020 at 18:12:40 UTC, Steven Schveighoffer 
wrote:
Before I show you what to do, let me explain what the above 
actually does.


1. You constructed a buffer of characters. Good, this is the 
first step.
2. You used encodeText to convert the data to ubyte. Note that 
for char buffer, this basically is just a cast. Other encodings 
might do byteswapping. But you have done this step a bit early. 
At this point now, the window type is ubyte[]. You want to put 
data into the buffer as char[].
3. You appended an outputPipe, which is a pass through while 
writing the data to a file (which is fed a stream of 
uninitialized data I think, so you probably got a file with 
garbage in it). Writing to this pipe's buffer is kind of 
pointless because the writing has already happened (pretty much 
all effects and actions performed on the buffer happen in the 
.extend function).


What you need is to access the buffer for writing BEFORE 
encoding and streaming to the file. For this, you need the push 
[1] mechanism, which wraps up everything you want to happen to 
data you have written to the buffer into a lambda template:


auto outputBuffered = bufd!char
   .push!(p => p
  .encodeText
  .outputPipe(output()));

[1] http://schveiguy.github.io/iopipe/iopipe/valve/push.html


I really feel like this is all very well thought out and clean, I 
don't appear to have a previous model to help visualize this 
output approach. Right now something like tee is coming to mind. 
Thank you for explaining with the answer.


Re: iopipe: Writing output to std.io File

2020-01-26 Thread Jesse Phillips via Digitalmars-d-learn

On Monday, 27 January 2020 at 01:50:00 UTC, Jesse Phillips wrote:

Just as I'm hitting send the part I'm missing clicked:

I needed to add the text encoding because my buffer is `char` 
but File writes `ubyte`


```dlang
auto output() {
return std.io.File("somefile.txt", mode!"w").refCounted;
}
auto outputBuffered = bufd!char
.encodeText // Missing This part
.outputPipe(output());
}
```


Unfortunately this did not write a text file as I expected.


Re: iopipe: Writing output to std.io File

2020-01-26 Thread Jesse Phillips via Digitalmars-d-learn

Just as I'm hitting send the part I'm missing clicked:

I needed to add the text encoding because my buffer is `char` but 
File writes `ubyte`


```dlang
/+ dub.sdl:
name "iobuftofile"
dependency "iopipe" version="~>0.1.7"
dependency "io" version="~>0.2.4"
+/

void main() {
import iopipe.valve;
import iopipe.textpipe;
import iopipe.bufpipe;
import iopipe.buffer;
import std.io;
import std.typecons;
auto output() {
return std.io.File("somefile.txt", mode!"w").refCounted;
}
auto outputBuffered = bufd!char
.encodeText // Missing This part
.outputPipe(output());
}
```




iopipe: Writing output to std.io File

2020-01-26 Thread Jesse Phillips via Digitalmars-d-learn
I'd like to start utilizing IOPipe[1] more. Right now I have an 
interest in utilizing it for buffering output (actually I don't 
have a need for buffering, I just want to utilize iopipe)


Looking through some different examples[2][3] I thought I would 
have something with this:


```dlang
/+ dub.sdl:
name "iobuftofile"
dependency "iopipe" version="~>0.1.7"
dependency "io" version="~>0.2.4"
+/

void main() {
import iopipe.valve;
import iopipe.textpipe;
import iopipe.bufpipe;
import iopipe.buffer;
import std.io;
import std.typecons;
auto output() {
return std.io.File("somefile.txt", mode!"w").refCounted;
}
auto outputBuffered = bufd!char
.outputPipe(output());
}
```

1. https://code.dlang.org/packages/iopipe
2. 
https://github.com/schveiguy/iopipe/blob/master/examples/convert/convert.d#L13

3. https://youtu.be/9fzttyj4JCs?t=1210


Re: CTFE, string mixins & code generation

2020-01-24 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 24 January 2020 at 16:21:48 UTC, Jan Hönig wrote:
I am looking for a detailed explanation or showcase regarding 
CTFE and string mixins.

I want to play with D a little bit regarding code generation.
I would like to have a pseudo-AST, consisting of a few classes, 
to represent some calculation. Think of a loop, some 
statements, and expressions.


To do that, I want to be certain that this AST can be computed 
and generated during compile-time, with CTFE and string mixins.


Are there limitations regarding CTFE (GC, global variables, 
static variables, templates, )?
Are there any limitations regarding string mixins (which are 
not already included int the CTFE limitations)?


Back in the day I had written CTFE unittests for Protobuf 
generation.


https://github.com/JesseKPhillips/ProtocolBuffer/blob/master/source/dprotobuf/generator/dlang.d#L740

IIRC the mixin was because it needed to compile in a D1 compiler.

I don't recall why I needed these.

https://github.com/JesseKPhillips/ProtocolBuffer/blob/master/source/dprotobuf/generator/dlang.d#L20


Re: Reading a file of words line by line

2020-01-15 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 15 January 2020 at 19:50:31 UTC, mark wrote:
I really do need a set for the next part of the program, but 
taking your code and ideas I have now reduced the function to 
this:


WordSet getWords(string filename, int wordsize) {
WordSet words;
File(filename).byLine
.map!(line => line.until!(not!isAlpha))
.filter!(word => word.count == wordsize)
.each!(word => words[word.to!string.toUpper] = 0);
return words;
}

This is also 4x faster than my version that used a regex -- 
thanks!


Why did you use string.count rather than string.length?


Your solution is fine, but also



void main () {

auto file = ["word one", "my word", "word"] ;
writeln (uniqueWords(file, 4));
}

auto uniqueWords(string[] file, uint wordsize) {
import std.algorithm, std.array, std.conv, std.functional, 
std.uni;


return file
.map!(line => line.until!(not!isAlpha))
.filter!(word => word.count == wordsize)
.map!(word => word.to!string.toUpper)
.array
.sort
.uniq
.map!(x => tuple (x, 0))
.assocArray ;
}




Re: Problem with std.algorithm.iteration::substitute

2020-01-11 Thread Jesse Phillips via Digitalmars-d-learn

You can also turn your function into a fold.

auto searches = ["1", "2"];
writeln (searches.fold!((a, b)  => a.substitute(b, 
"number").to!string)("come 1 come 2")) ;





Re: Problem with std.algorithm.iteration::substitute

2020-01-11 Thread Jesse Phillips via Digitalmars-d-learn

On Saturday, 11 January 2020 at 17:10:02 UTC, Martin Brezl wrote:

Hi,

i have a function like this:
```
import std.algorithm.iteration : substitute;
//...
string replace(string content, string[] searches , string 
replace) {


if(searches.empty) return content;

auto result = content.substitute(searches.front,replace);
for(size_t i=1; i < searches.length; i++) {
searches.popFront();
result = result.substitute(searches.front,replace);
}
//...
return "example return";
}
```


The issue is the double assigned result.

auto result = content.substitute(searches.front,replace);
result = result.substitute(searches.front,replace);

`substitute` is going to return a template range typed off 
`content` then it uses that type to perform another substitution.


`content` and `result` don't have the same type.




Re: D's equivalent List Comprehension

2019-12-14 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 13 December 2019 at 15:35:24 UTC, mipri wrote:


It might help your blog posts to use drepl in your examples:

https://code.dlang.org/packages/drepl



That is nice. Is there a web frontend? Rightnow I am using 
run.dlang.io from my phone. Prior to that I didn't compile 
anything.


D's equivalent List Comprehension

2019-12-13 Thread Jesse Phillips via Digitalmars-d-learn

I had mentioned my take on list comprehension here:

https://forum.dlang.org/post/qslt0q$2dnb$1...@digitalmars.com#post-ycbohbqaygrgmidyhjma:40forum.dlang.org

However someone put together a more comprehensive tutorial of its 
power. So I took the opportunity to demonstrate the parallel in D.


https://dev.to/jessekphillips/list-comprehension-in-d-4hpi

D is like writing English. Wait I thought that was supposed to be 
Python, maybe I am thinking ruby.


Re: How to simulate Window's "Press any key to continue..."

2019-11-22 Thread Jesse Phillips via Digitalmars-d-learn
On Friday, 22 November 2019 at 04:10:23 UTC, FireController#1847 
wrote:
I'm an extreme beginner to DLang (just started using it.. oh, 
an hour ago?), and I already can't figure out a, what I'd 
consider, fairly simplistic thing.


This is my current code:

module DTestApp1;

import std.stdio;

int main() {
write("Press any key to continue...");
stdin.read();
return 0;
}

I am using Visual Studio to write it, and no matter what I do I 
cannot get it to work. I attempted to import std.stream;, but 
it said that while it could find the file, it cannot be read. 
Am I using the wrong function?


For those who don't know, what I'm trying to do is pause the 
program until literally any key is pressed while in the console.


execute(["pause"]);


Re: Which is the active fork in DFL gui library ?

2019-11-03 Thread Jesse Phillips via Digitalmars-d-learn
On Sunday, 3 November 2019 at 16:48:52 UTC, Vinod K Chandran 
wrote:

On Sunday, 3 November 2019 at 14:01:03 UTC, Jesse Phillips



https://github.com/Rayerd/dfl


@Jesse Phillips,
Thank you for the reply.  Does DWT is built upon Java's SWT ? I 
heard that SWT is somewhat slower in windows. Anyhow, what 
about the easiness of DWT ? Actually, i just want to make GUI 
for Windows only. I dont need a cross platform GUI.


DTW is a translation of swt, I can speak to speed comparisons but 
I don't think you could apply anything out their related to 
comparing dfl and dwt.


You can write windows only apps in dwt, don't compile for Linux, 
it uses native drawing.


Re: Which is the active fork in DFL gui library ?

2019-11-03 Thread Jesse Phillips via Digitalmars-d-learn
On Saturday, 2 November 2019 at 20:01:27 UTC, Vinod K Chandran 
wrote:

Hi all,
I just found that DFL gui library very interesting. But after 
some searching, i can see that DFL is inactive and there is few 
other forks for it. So this is my question - Which fork is good 
for a gui development in windows platform.
BTW, i just tested the gtkD and successfully compiled a hello 
app. How do i avoid the console window when compiling gtkD app ?

Thanks in advance.


The last one I used was from rayerd. But even that is behind. I 
switched my app to dwt.


https://github.com/Rayerd/dfl


Re: Permission to Use Comments?

2019-10-14 Thread Jesse Phillips via Digitalmars-d-learn

On Monday, 14 October 2019 at 11:14:50 UTC, Ron Tarrant wrote:

Hi all,

I've been thinking about how to take GtkDcoding to the next 
level and one idea is to use (favourable) comments made here on 
the forum to help promote the blog.


So, since I'm not clear on copyright law and how it affects 
forum posts, I decided to ask...


1) Does anyone know how copyright laws stand regarding reuse of 
comments on a forum?


2) Does anyone object to me quoting them for promotional 
purposes?


Pretty sure since this is a public forum, legally you just need 
to reference your sources (if even that). Asking permission is 
just polite.


I don't say anything good, but you're free to use mine.


Simplifying process piping

2019-09-22 Thread Jesse Phillips via Digitalmars-d-learn
As noted in this announcement, I started writing some basic 
tutorials for D.


https://forum.dlang.org/post/efpyegvrezybdrmug...@forum.dlang.org

At a post a week, I've got 10 weeks of backlog posts. One of 
these is a post on input output piping.


https://github.com/JesseKPhillips/std.process-example/

I'm wondering if there are any thoughts for simplification. I 
don't mean simplify to perform the same end result, but is the 
threading and data copies as simple as they could be? Did I 
misrepresent anything?


Re: Question about generation of template functions

2019-08-29 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 28 August 2019 at 20:56:25 UTC, Machine Code wrote:
I was writing a recursive function that uses template, I 
thought it would generate the proper template function on the 
fly to match the type in the parameter but it seems to not so 
so and try to use the called function, resulting in the error:


Error: function foo.serialize!(B).serialize(ref B output) is 
not callable using argument types (A)
   cannot pass argument output of type A to parameter ref 
B output
Error: template instance `foo.serialize!(A)` error 
instantiating


Code:



void serialize(T)(ref T output)
{
import std.traits : hasUDA, getUDAs, isAggregateType;
import std.meta : Alias;

foreach(fieldName; __traits(derivedMembers, T))
{
alias field = Alias!(__traits(getMember, T, fieldName));
static if(isAggregateType!(typeof(field)))
{
serialize!(typeof(field))(output);
}
static if(hasUDA!(field, Attr))
{
enum className = getUDAs!(field, Attr)[0];
writefln("className = [%s]", className);
}
}
}


You're asking it to be the field type but passing it output.


serialize!(typeof(field))(output);



Re: Executing a D script without an [extension in the filename] leads to an error

2019-03-01 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 1 March 2019 at 11:38:51 UTC, BoQsc wrote:
"And indeed rdmd won't call your script if it doesn't have the 
proper extension."


Then why does Dlang Tour includes shebang: #!/usr/bin/env rdmd

Instead of the one you mentioned, that is fool proof. 
(#!/bin/dmd -run)


Is that an error/mistake in Dlang Tour guide?


You may want to change that too:

#!/bin/dmd -i -run

DMD doesn't automatically compile imported files (at least not 
until -i came along), rdmd existed to solve that problem... I 
don't know what value it brings with the -i switch existing.


Re: Am I missing with ref in this code?

2019-01-26 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 24 January 2019 at 15:28:19 UTC, Suliman wrote:
I am doing very small link-checker. Here is' code 
https://run.dlang.io/is/p8whrA


I am expecting that on line:
writefln("url: %s, status: %s", url.url, url.status);

I will print link and it's status. But I am getting only:
url: http://127.0.0.1:8081/hck, status:
url: http://127.0.0.1:8081/hck2, status:
url: http://127.0.0.1:8081/hck3, status:

It's seems that I missed something with refs? Could you help me 
find error?


You're writing asynchronous code and expecting it to process 
synchronized. Just make a synchronous call. If you need async use 
message passing with concurrency, probability on each call to the 
url so you can do the slow operations in parallel.


Re: Co-developing application and library

2019-01-06 Thread Jesse Phillips via Digitalmars-d-learn

On Saturday, 5 January 2019 at 13:01:24 UTC, Russel Winder wrote:
Dub seems to have the inbuilt assumption that libraries are 
dependencies that do not change except via a formal release 
when you developing an application. Clearly there is the 
workflow where you want to amend the library but not release as 
a part of developing an application. Does Dub have a way of 
doing this, I haven't been able to infer one to date. But I am 
a beginner at Dub.


I use submoduals in git and then subpackage in dub. That doesn't 
help with packages I don't maintain but want to contribute back 
to because I don't submodual those in.


I actually wish submoduals got more attention and was the 
expected way to manage dependencies.


Re: 9999999999999999.0 - 9999999999999998.0

2019-01-05 Thread Jesse Phillips via Digitalmars-d-learn

On Sunday, 6 January 2019 at 00:20:40 UTC, Samir wrote:


[1] https://news.ycombinator.com/item?id=18832155
[2] https://en.wikipedia.org/wiki/IEEE_754


Since you got your answer you may also like
http://dconf.org/2016/talks/clugston.html


Re: dub doesn't work with dmd 1:2.082.0-1.0?

2018-09-14 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 14 September 2018 at 05:41:41 UTC, rmc wrote:

I do wonder if `dmd` by itself on the command line works. Could 
it be some sort of 32 bit bug in the latest release of dmd? 
Relating to argc/argv.



"source/dub/compilers/compiler.d(127)"

That doesn't look like DMD source code.


Re: dub doesn't work with dmd 1:2.082.0-1.0?

2018-09-13 Thread Jesse Phillips via Digitalmars-d-learn

On Monday, 10 September 2018 at 09:23:19 UTC, SuperPrower wrote:
dub was working nice until I updated my system (I run 
ArchLinux32) just now. dmd was updated from version 
1:2.081.2-1.0 to 1:2.082.0-1.0 (according to pacman package 
manager). After that, I couldn't invoke dub for anything. Here 
is the attempt to run `dub --vverbose`:


Can you find /usr/bin/dmd or run dmd?


Re: [Unit tests] Mocking D objects

2018-08-23 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 22 August 2018 at 08:33:36 UTC, Andrey wrote:

Hello,
I know that D has build-in unit tests. If so, what mechanism D 
provides for mocking objects?


I'd like to pose the question, what are you testing. This looks 
like you are testing that your mocked object returns 10. I 
usually try to make functions more pure like.


Re: D need an ORM library!

2018-08-20 Thread Jesse Phillips via Digitalmars-d-learn

On Monday, 20 August 2018 at 02:30:16 UTC, binghoo dang wrote:

hi,

I thinks D need an ORM library for Sqlite/Mysql/PostgreSQL, 
entity currently support all the three targets, but entity's 
API is too complex and cumbersome for using.


Is there a more light-weight and simpler implementation like 
ActiveAndroid ?


Thanks!


---

Binghoo Dang


There are a number of things out there, but personally don't know 
there state or simplicity.


2016 there was a talk: http://dconf.org/2016/talks/nowak.html

But personally I preferred this one: 
http://dconf.org/2016/talks/smith.html

https://github.com/cruisercoder/dstddb


Re: Dependency injection pattern

2018-05-13 Thread Jesse Phillips via Digitalmars-d-learn

On Sunday, 13 May 2018 at 07:42:10 UTC, Suliman wrote:
Could anybody give small example of Dependency injection 
pattern? I googled about it, but found only C# examples and I 
am not quite sure how to use them.


Also I would like get some explanation/comments for code.


Here is a quick example of the difference, myProgram.execute 
utilizes a database connection.
dInjection.execute utilizes a dependency injected database 
connection.



class dbConnection {}

class myProgram {
void execute() {
auto db = new dbConnection();
//...
}
}

class dInjection {
void execute(dbConnection db) {
//...
}
}


What you should notice from the first execute function is that 
the dependency, in this case dbConnection, is created as part of 
the application execution. While the second the dependency is 
declared at the function's arguments allowing the caller to 
inject the needed dependency.


This could go a step further and accept an interface for DB 
connections, but is not necessary to meat dependency injection.


Dependency injection also applies to magic numbers.

enum maxProcessingTime = 3582;

If this were declared inside a function rather than taken as a 
parameter, then the function would not correctly use dependency 
injection.


Additionally, you could inject the dbConnection as part of the 
class constructor:


--
class preInjection {
dbConnection db;
this(dbConnection data) { db = data}
void execute() {
//...
}
}

--

Now I think what trips a lot of people up is that frameworks are 
created to help you do this. They try to make it easy to define 
all your dependencies in a single location and then you request 
the object you need and the DI framework will do whatever it 
needs to for building that object.


Re: "Start a Minimal web server" example do not work.

2018-05-08 Thread Jesse Phillips via Digitalmars-d-learn

On Tuesday, 8 May 2018 at 18:38:10 UTC, BoQsc wrote:

Tested with these versions so far, and had all the same errors:
C:\Users\Vaidas>dmd --version
DMD32 D Compiler v2.079.1

C:\Users\Vaidas>dub --version
DUB version 1.8.1, built on Apr 14 2018

C:\Users\Vaidas>dmd --version
DMD32 D Compiler v2.080.0

C:\Users\Vaidas>dub --version
DUB version 1.9.0, built on May  1 2018


Well I'm pretty sure the primary reason for my success is having 
Visual Studio installed and using the ms linker.


Re: "Start a Minimal web server" example do not work.

2018-05-08 Thread Jesse Phillips via Digitalmars-d-learn

On Tuesday, 8 May 2018 at 16:34:53 UTC, BoQsc wrote:

On Tuesday, 8 May 2018 at 16:18:27 UTC, bachmeier wrote:

On Tuesday, 8 May 2018 at 12:13:56 UTC, BoQsc wrote:


This is the code example, that was presented on the 
https://dlang.org frontpage:


Maybe that isn't the best choice of beginner example if even 
the D experts can't figure out how to get it to run.


Might be a bug, I have already reported it and saw some bug 
duplicates like mine.
However, since 2017 report, it seems to be - still not going 
well.
If I have a chance I'll try to download latest dlang 
distribution and install on a completely clean Windows 10 
Operating system. But I'm not hoping for any luck, but still in 
need of try trial.


So I gave this a try and this command worked:

 >dub --arch=x86_64 --single start_minimal_server.d

I'm on Windows 8 with All the visual studio versions installed
DMD32 D Compiler v2.080.0-beta.1
DUB version 1.9.0-beta.1, built on Apr 17 2018


Re: dxml behavior after exception: continue parsing

2018-05-08 Thread Jesse Phillips via Digitalmars-d-learn

On Monday, 7 May 2018 at 22:24:25 UTC, Jonathan M Davis wrote:

I've been considering adding more configuration options where 
you say something like you don't care if any invalid characters 
are encountered, in which case, you could cleanly parse past 
something like an unescaped &, but you'd then potentially be 
operating on invalid XML without knowing it and could get 
undesirable results depending on what exactly is wrong with the 
XML. I haven't decided for sure whether I'm going to add any 
such configuration options or how fine-grained they'd be, but 
either way, the current behavior will continue to be the 
default behavior.


- Jonathan M Davis


I'm not going to ask for that (configuration). I may look into 
cloning dxml and changing it to parse the badly formed XML.


Re: dxml behavior after exception: continue parsing

2018-05-07 Thread Jesse Phillips via Digitalmars-d-learn

On Monday, 7 May 2018 at 19:46:00 UTC, Jesse Phillips wrote:
So I have an XML like document which fails to adhere completely 
to XML. One of these such events is that & is used without 
escaping.


My observation is that after the exception it is possible to 
move to the next element without issue. Is this something 
expected and will be maintained?



try {
range.popFront();
} catch (Exception e) {
range.popFront;
}


Ok so this worked when inside a quoted attribute value but not a 
normal tag body. Clearly I'm not parsing valid XML so I'm going 
outside the bounds of valid parameters. But rather than writing a 
custom parser to handle this, it would be nice to have:


 try {
 range.popFront();
 } catch (Exception e) {
 range.moveToNextTag();
 }

Which would make front a MalformedParse containing the content up 
to the next <.


dxml behavior after exception: continue parsing

2018-05-07 Thread Jesse Phillips via Digitalmars-d-learn
So I have an XML like document which fails to adhere completely 
to XML. One of these such events is that & is used without 
escaping.


My observation is that after the exception it is possible to move 
to the next element without issue. Is this something expected and 
will be maintained?



try {
range.popFront();
} catch (Exception e) {
range.popFront;
}


As an aside, here is a snippet for skipping over the BOM since 
dxml doesn't expect the BOM to be there:


import std.encoding;
import std.algorithm;
auto fileContent = cast(ubyte[])read(file);
if(getBOM(fileContent).schema != BOM.none)
fileContent.skipOver(getBOM(fileContent).sequence);



Re: Is HibernateD dead?

2018-05-07 Thread Jesse Phillips via Digitalmars-d-learn
You should get a hold of Vadim Lopatin and see if he would give 
you commit rights to the main repo.


There was a great article I can't find by someone who would add 
contributors if they made good pull requests. It helped to keep 
his work living on and didn't need to keep involved.


So I push for people to follow this model (remove contributors if 
it isn't working out.


Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-07 Thread Jesse Phillips via Digitalmars-d-learn

On Monday, 7 May 2018 at 14:31:23 UTC, Jesse Phillips wrote:
I wouldn't use time created. It can be newer than last modified 
this wholey inacurate. Last accessed could be a much more 
appopriate choice if trying to determine what is important.


Sorry, to answer your actual question, I do believe that using 
the OS version specification to select the function is correct.


Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-07 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 4 May 2018 at 11:49:24 UTC, Vino wrote:

Hi All,

  Request your help, I have a D program written on Windows 
platform and the program is working as expected, now i am 
trying to port the same program to Linux, my program use the 
function "timeCreated" from std.file for Windows hugely where 
as in Linux we do not have the same function hence planned to 
use the function "timeLastAccessed" from std.file, so what is 
the best approach to port the program. I tried the below code 
but not working, so can you one please guide me on the right 
method to port the program to linux, below is the example code.


I wouldn't use time created. It can be newer than last modified 
this wholey inacurate. Last accessed could be a much more 
appopriate choice if trying to determine what is important.


Re: Get files from directory sorted by name

2018-04-27 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 26 April 2018 at 16:59:45 UTC, Dr.No wrote:
On Wednesday, 25 April 2018 at 19:25:11 UTC, Jesse Phillips 
wrote:

On Wednesday, 25 April 2018 at 17:34:41 UTC, Dr.No wrote:
Is there something implemented already to get the files from 
directory by name using D or I'm on my own and I have to 
write it myself? I didn't find how do that with dirEntries()


I want to add that sorting can be done, if you just call 
std.algorithm.sort you'll find that file names with numbers in 
them will be sorted as a well strings.


Newfile1.txt
Newfile10.txt
Newfile2.txt


I've had realized that then implemented natural sort


Thats what it was called. Looks like Rosetta Code has an 
implementation.


https://rosettacode.org/wiki/Natural_sorting#D


Re: Get files from directory sorted by name

2018-04-25 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 25 April 2018 at 17:34:41 UTC, Dr.No wrote:
Is there something implemented already to get the files from 
directory by name using D or I'm on my own and I have to write 
it myself? I didn't find how do that with dirEntries()


I want to add that sorting can be done, if you just call 
std.algorithm.sort you'll find that file names with numbers in 
them will be sorted as a well strings.


Newfile1.txt
Newfile10.txt
Newfile2.txt


Re: unittests, dub and libraries

2018-03-28 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 28 March 2018 at 21:29:22 UTC, Jesse Phillips wrote:
And a note on the reverse, if you have an executable project $ 
dub test won't build in the app.d file since it contains main 
and dub test wants to avoid running your main function.


For reference:

https://github.com/dlang/dub/issues/1118


Re: unittests, dub and libraries

2018-03-28 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 03:07:23 UTC, Jonathan M Davis 
wrote:

Run

dub test

The problem is that an executable needs a main, and a library 
doesn't have one, whereas when you're testing a library, you 
need an executable. So, a main must be inserted - e.g. with the 
-main flag to dmd. Just building the unittest build doesn't 
insert one. However, dub test _does_ deal with that for you.


- Jonathan M Davis


And a note on the reverse, if you have an executable project $ 
dub test won't build in the app.d file since it contains main and 
dub test wants to avoid running your main function.


Re: How to use an associative array with array values.

2018-03-21 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 21 March 2018 at 18:31:29 UTC, tipdbmp wrote:

I see. I guess the other would be:

{
int[8192] bar;
int[8192][string] foo;
foo["a"] = bar;
foo["a"][8191] = -1;
}


https://run.dlang.io/is/AK2X2t

Are you looking to use static arrays or dynamic? You can't use 
the new keyword if it static.


Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote:
I creating one simple desktop application using dlang. I need 
to display some html file in my desktop application. How can 
make it works ?


I believe on is available in dtw.
http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fbrowser%2FBrowser.html


Re: Vibe.d rest & web service?

2018-02-07 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 7 February 2018 at 17:04:13 UTC, Nicholas Wilson 
wrote:
Is it possible to have some urls routed to serve content and 
some to receive JSON in the same class?


This seems unlikely to me, the function signature doesn't provide 
a way to distinguish between REST and not.


I'm also not sure it is necessary, you can certainly have 
multiple class which provide REST and Web endpoints. You can even 
dynamically build routes within a route.


Re: invalid or corrupt file: duplicate COMDAT / Previous Definition Different

2018-01-10 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 10 January 2018 at 19:32:28 UTC, Anonymouse wrote:

/usr/bin/ld: Warning: size of symbol


I think your case is this bug:
https://issues.dlang.org/show_bug.cgi?id=15324

Another COMDAT error is: 
https://issues.dlang.org/show_bug.cgi?id=16687


Re: git workflow for D

2017-12-05 Thread Jesse Phillips via Digitalmars-d-learn
I'm going to answer with something that others may not agree 
with, maybe they can enlighten me, but let me first get a generic 
principle of git and answer some questions.


Git has 2 types of branches, local branches (you know them as 
just branches) and remotes (which have their own local branches). 
I say this to remove the confusion with having an original 
repository, a forked repository, and a cloned repository. When it 
comes to interactions with these repositories the only difference 
from your local branches is that you can't interact directly with 
them (i.e. you can't commit to them) and the interactions require 
specifying the remote location of the branch.


Some of your other questions are about GitHub and Forking. Git 
doesn't know what a fork is, but GitHub ties a pull request to a 
branch. This means you can update/change your pull request by 
updating/changing your branch. From that you should realize each 
pull request needs its own branch.


Back to git remotes. I'm sure you're aware of the commonly named 
"origin" remote and possible the second common "upstream." When 
you're dealing with many remotes your local branches can get 
complicated. For example many people utilize 'master' as a 
*tracking* branch to "origin" well, "upstream" if there is one. 
I'm to the point that in this situation my recommendation is just 
delete your 'master' branch both local and "origin." Don't worry 
you can bring it back if you need it, you won't need it.


Here is the thing, you already have two, maybe 3 master branches 
'master' 'origin/master' 'upstream/master' these are local 
branches (they are special in that you can't commit to them). And 
these are also your true tracking branches, whenever you 
fetch/pull from your remote these branches are updated, they will 
always reflect the branch of the remote and they will never 
conflict during updates. You can always create your own master $ 
git branch master upstream/master


I want to note that 'origin/master' is different from such 
commands as `$ git push origin master` because in the first you 
are referring to a local branch and the second you reference your 
remote followed by your remotes local branch (actually I could be 
wrong here because the full syntax is `$ git push origin 
master:master` where the left: is your local and :right is the 
remote local branch [and note that `push origin :master` would 
delete the remote master branch because you're push no branch to 
it.).


I hope that this along with answers other have given will help 
you to answer all of your questions.


Re: Object oriented programming and interfaces

2017-12-05 Thread Jesse Phillips via Digitalmars-d-learn

On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote:

Hi!

I defined an interface:

interface Medoid {
float distance( Medoid other );
uint id() const @property;
}

and a class implementing that interface:

class Item : Medoid {
float distance( Item i ) {...}
uint id() const @property {...}
}

The compiler says:
Error: class Item interface function 'float distance(Medoid 
other)' is not implemented


Is there a way to implement the Item.distance() member function 
taking any object whose class is Item?


I think everyone here has missed the reason.

The problem is that a derived type can do more, the interface 
only allows for two method calls while the class could 
theoretically do more.


If the compiler allowed the class it would let you access 
functions and members not available to the interfaces, and the 
function would still be passed a Medoid.


You could make a cast within your function, but then you're still 
really not handling the interface but that at least would be 
clear in the code rather than the compiler hiding it by ignoring 
the problem.


Re: Basic questions about D lang?

2017-11-29 Thread Jesse Phillips via Digitalmars-d-learn

On Tuesday, 28 November 2017 at 13:39:11 UTC, Jayam wrote:

Can we compile our program to multi program ?


Based on your C# reference you must be referring to the "Mixed 
Platform" build option. No, that is a .NET thing and D is not on 
.NET (that project has died).


D requires a more traditional approach to multiple platforms, 
you'll need to write your code with the needs of your supported 
platforms in mind. Luckily in pure D this is like no work, but 
when you interface to C/C++ libraries you'll hit sizes of types 
and structures changing almost randomly (ok it isn't that bad).


Re: "version" private word

2017-10-31 Thread Jesse Phillips via Digitalmars-d-learn

On Tuesday, 31 October 2017 at 14:25:19 UTC, Igor Shirkalin wrote:
On Tuesday, 31 October 2017 at 14:22:37 UTC, Jesse Phillips 
wrote:
On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin 
wrote:

Hello!



You goal should be to describe features.

Version x86
... Version = I can stand on my head
...


pardon?


Sorry I hate writing code on mobile.

You can create an arbitrary version by assigning a symbol to it, 
use that symbol to describe a feature, assign that symbol for 
each architecture that supports it. Then write code in a version 
block of that symbol.


Re: "version" private word

2017-10-31 Thread Jesse Phillips via Digitalmars-d-learn

On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:

Hello!



You goal should be to describe features.

Version x86
... Version = I can stand on my head
...



Re: CSV with empty values for integer fields

2017-10-29 Thread Jesse Phillips via Digitalmars-d-learn
Not really you'll need to parse it out as a string and do the 
conversion later.


It probably would be good to support nullable!int pretty sure it 
doesn't currently.


Re: Assert and undefined behavior

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

On Saturday, 14 October 2017 at 09:32:32 UTC, Timon Gehr wrote:
The compiler can easily prove that the value of data.length 
does not change between the two points in the program. 
According to the specification, the behavior of the program is 
undefined in case the assertion fails, not just the behavior of 
the program after the assertion would have failed if it had not 
been removed.


You are right, in this example proving that there is no change 
between the condition and the assert is easy and possible. In 
fact there was an example of this in C I think with a function 
pointer which was uninitialized. Where the optimizer identified 
that there was only one valid function which could have been 
assigned and made lowered the indirect call to a direct one.


My statement was more around if the compiler/optimizer can't 
determine the value


void test(int[] data, bool goboom)
{
if (data.length == 0) {
writeln("Not enough data!");
} else {
control_nuclear_reactor(data);
}

assert(goboom);
}

The optimizer can generate code to match:


void test(int[] data, bool goboom)
{
if(!goboom) {
launch_nuclear_missile();
return;
}

if (data.length == 0) {
writeln("Not enough data!");
} else {
control_nuclear_reactor(data);
}
}


Also, UB can and does sometimes mean that the program can 
execute arbitrary code. It's called "arbitrary code execution": 
https://en.wikipedia.org/wiki/Arbitrary_code_execution


That article is about attacks not optimizers.



Re: Assert and undefined behavior

2017-10-13 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 12 October 2017 at 15:37:23 UTC, John Burton wrote:


This is an example of what I mean :-

undefined what it is meant to do anyway, so the compiler can 
"optimize" out the if condition as it only affects the case 
where the language doesn't define what it's supposed to do 
anyway, and compiles the code as if it was :-


void test(int[] data)
{
control_nuclear_reactor();
}



Yeah the C/C++ community/haters love to talk about all the code 
the compiler can inject because of undefined behavior. But that 
is not what it means.


The compiler does not know the value of data.length so it could 
not make such a transformation of the code. Now had the assert 
been written before the if, you're telling the compiler some 
properties of data.length before you check it and it could make 
such optimizations.


The point is assert tells the compiler something it can use to 
reason about its job, not that it can insert additional runtime 
checks to see if you code is invalid an then add new jumps to 
execute whatever the hell it wants.




Re: CSV crash: "Quote located in unquoted token"

2017-10-13 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 13 October 2017 at 08:53:12 UTC, Dmitry wrote:

Hi there.
When I load csv, it crashes ("Quote located in unquoted token") 
on lines with quotes, like this:


ResourceNode_RemoveFromView_Confirm,You are about to remove 
""{0}"" from view ""{1}"". Continue?,You are about to remove 
""{0}"" from view ""{1}"". Continue?,,Resource Tree - 
confirmation of removal from the current view


The problem is that a generic CSV parser can't tell what the 
expected data should look like if the data doesn't follow defined 
rules. std.csv is not filled with custom parsing rules.


You can use Malformed.ignore[1], but your data will come out like:

You are about to remove ""{0}"" from view ""{1}""

This would leave you needing to modify the "".

1. https://dlang.org/phobos/std_csv.html#.Malformed


Re: Undo?

2017-10-12 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 12 October 2017 at 02:18:49 UTC, Mr. Jonse wrote:

A simple(incomplete) undo system.


I'd think that for D you'd want to do type wrapping where a new 
type is created which saves changes and can manage an Undo tree.


__gshared Data data = new Data();
auto undoable = Undo!data

undoable.x = 5;
assert(data.x == 5);

undoable.undo();
assert(data.x == 0);
undoable.redo();
assert(data.x == 5);

This would be done by monitoring the members which contain 
storage, available with:

https://dlang.org/phobos/std_traits.html#Fields

This is of course specific to a single object and plan for 
handling order across multiple objects along with creating an 
"Edit" where many data points could change and be undone with a 
single undo.


Re: Does D have an equivalent to C#'s String.IsNullOrWhiteSpace?

2017-10-12 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 12 October 2017 at 18:17:54 UTC, Adam D. Ruppe wrote:

On Thursday, 12 October 2017 at 18:11:55 UTC, Nieto wrote:
Does D have an equivalent to C#'s String.IsNullOrWhiteSpace() 
in the standard library?


import std.string;

if(str.strip().length == 0) {
  // is null, empty, or all whitespace
}


Also

   if(str.strip().empty)

std.array.empty() works essentially the same as IsNullOrEmpty()


Re: For fun: Expressive C++ 17 Coding Challenge in D

2017-10-04 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 4 October 2017 at 15:26:02 UTC, Ali Çehreli wrote:

On 10/04/2017 02:04 AM, Biotronic wrote:

...

Hey where is the list of features used e.g: ranges, ufcs...




Re: Looking for a mentor in D

2017-10-04 Thread Jesse Phillips via Digitalmars-d-learn

On Tuesday, 3 October 2017 at 06:54:01 UTC, eastanon wrote:
I would like to choose D as my go to language and to do that I 
realise I need a mentor, someone who will walk and guide me and 
not get irritated by basic questions. I am pretty much a DIY 
person, so don't worry about mundane issues.  I want to have 
someone with whom I can discuss some practical choices and 
algorithms. I am a self-taught programmer and never took CS 
classes. I am good in R, Python and Ruby.


Please let  me know if you would like to be a D mentor.


I haven't seen anyone blasted for asking programming questions on 
these forms as long as they were using D to solve them. Though 
maybe that wouldn't be true if the forum was consumed by such 
questions.


Feel free to shoot me an email though jesse.k.phill...@gmail.com 
and we can see how it goes.


Re: Vibe.d using Windows Certificate binding, possible?

2017-10-04 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 4 October 2017 at 03:39:22 UTC, rikki cattermole 
wrote:

On 04/10/2017 3:54 AM, Jesse Phillips wrote:

https://msdn.microsoft.com/en-us/library/windows/desktop/cc307220(v=vs.85).aspx



"Application program source files include the Http.h header 
file to access function prototypes and structure definitions 
for the HTTP Server API. Developers can use the Httpapi.lib 
library file to build applications that use the HTTP Server 
API. At runtime, applications link to the Httpapi.dll."


So no, vibe.d can't work with it. This a special snow flake 
feature from 2k3 server days.


Thank you, and it looks like core.sys.windows doesn't have this 
header file defined either.


And now I've learned something new about MSDN docs.


Re: Vibe.d using Windows Certificate binding, possible?

2017-10-03 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 23:29:49 UTC, rikki cattermole 
wrote:

On 03/10/2017 4:52 PM, Jesse Phillips wrote:
I'm pretty sure this isn't possible, but maybe someone 
understands Windows better.


Windows provides a means no bind a certificate to a port using 
netsh.exe. This means (at least for standard Windows 
networking calls) connections to that port will be given the 
bound cert.


The Vibe.d documents state that a Certificate chain and key 
needs to be provided. I'm pretty sure that the port binding 
requires very specific Network API calls, possible .NET only. 
Can any confirm or deny?


Perhaps you could reference the command (aka the args with an 
example)?
Otherwise, its a lot harder to figure out what it is doing 
under the hood.


Here is the command docs

https://msdn.microsoft.com/en-us/library/windows/desktop/cc307220(v=vs.85).aspx


Vibe.d using Windows Certificate binding, possible?

2017-10-03 Thread Jesse Phillips via Digitalmars-d-learn
I'm pretty sure this isn't possible, but maybe someone 
understands Windows better.


Windows provides a means no bind a certificate to a port using 
netsh.exe. This means (at least for standard Windows networking 
calls) connections to that port will be given the bound cert.


The Vibe.d documents state that a Certificate chain and key needs 
to be provided. I'm pretty sure that the port binding requires 
very specific Network API calls, possible .NET only. Can any 
confirm or deny?


Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 16:35:54 UTC, DreadKyller 
wrote:
My question is about overloading, several operators can be 
overloaded in D, one of the ones that can't apparently is the 
address of operator (). My question is have I simply 
missed it or does it actually not exist, and if it's not 
overloadable, is there any reason why this was decided? Because 
there's been numerous times that it'd be useful to me, just 
recently with how much I use the operator because of OpenGL I 
decided to ask.


My answer is that & is a defined operation on all addressable 
memory. Unlike other operators which don't exist until you 
"overload" them.


For example, if you store your Matrix in a custom container it 
could try to store pointer rather than the struct itself, if & is 
overloaded the generic implementation would be broken because it 
would no longer be a pointer to Matrix but to the inner element.


Whereas generic code which utilizes addition or append can assume 
the type appropriately defined the behavior to semantically match 
the desired use, generic code would be broken if the type changed 
& to do something different from what the language defines it to 
do.


Communication was [Re: What the hell is wrong with D?]

2017-09-20 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 20 September 2017 at 02:34:50 UTC, EntangledQuanta 
wrote:
When they then make up excuses to try to justify the wrong and 
turn it in to a right, they deserved to be attacked.


That isn't how it went down, you attacked then justification was 
provided.


for someone that programs in about 20 different languages 
regularly, having logical consistency is important.


Could you imagine if D didn't allow you to learn how ternary is 
implemented? when you switched to one of those 19 other languages 
you'd expect it to work like D and make that catastrophic life 
threatening mistake you speak of.


But at last D followed logical consistency across languages so 
you can make the mistake once, learn, and apply it to all the 
other environments you're using.



No, it doesn't logic is not based on circumstances, it's based 
on something that is completely independent of us... which is 
why it is called logic... because it is something we can all 
agree on regardless of our circumstances or environment... it 
is what math and hence all science is based on and is the only 
real thing that has made steady progress in the world. Illogic 
is what all the insanity is based on... what wars are from, and 
just about everything else, when you actually spend the time to 
think about it, which most people don't.


I will claim that it is illogical to make decisions ignoring 
environment and circumstances. For example, science heavily 
leverages environment (e.g. all objects fall at the same rate; 
environment: vacuum) (e.g. matter can neither be created nor 
destroyed; environment: not within a atomic explosion) (e.g. ...; 
environment: anything not quantum mechanics) (e.g. this satellite 
will follow this trajectory; environment: forces acting upon the 
satellite)


Again, two wrongs don't make a right. What is the point of 
reimplementing C exactly as C is done?


I don't think there were any unjust or dishonest actions being 
done. Just an FYI the phrase isn't intended to be applied to all 
meanings of 'wrong'.


If you're a C(C++,C#,Java,...) programmer (environment) then when 
you are reading D code you will understanding the semantics and 
the semantics will remain the same if you copy code from your 
language into D.


e.g., my attack is on the claims that D attempts to be *safe* 
and a *better C* and yet this(the ternary if) is just another 
instance of them contradicting themselves. Presenting something 
as safer when it is not gives the perception of safety and can 
actually be more dangerous than the original.


Safe to Walter has always been 'memory safe' but to you point of 
broader safety lets take my ()?: syntax and breaking backwards 
compatibility here is unsafe.


q > a / (3 + 4) ? 0 : q;

This compiles today, it will also compile with the new syntax; 
the semantics would be completely different. This is a 
calculation running in production for a space shuttle to Mars. 
Before the launch they upgrade the compiler and this new 
calculation causes the shuttle to land in Florida off the coast 
of Minneapolis.


Backwards compatibility is important to safety just as following 
the majority. To ignore the environment you're working is 
illogical.


Re: What the hell is wrong with D?

2017-09-19 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 19 September 2017 at 19:16:05 UTC, EntangledQuanta 
wrote:
The D community preaches all this safety shit but when it comes 
down to it they don't seem to really care(look at the other 
responses like like "Hey, C does it" or "Hey, look up the 
operator precedence"... as if those responses are meaningful).



jmh530 points out why you're met with such non-agreement of the 
issue. You're not open do discussion of why it is implemented in 
the fashion it is. Instead it is an attack on the community and 
Walter as though there is no logical reason it is implemented in 
the way that it is.


Sure you can express that it is illogical to have made that 
choice, but that requires first know what used to make that 
decision.


For example one of the original principles for D was:
If it looks like C it should have the same semantics or be a 
compiler error (note this was not completely achieved)


Now if we look at other languages we see, they implement it the 
same as C or they don't implement it at all. Just based on this 
it would make sense to choose to implement it like C if it is 
desired to have.


The suggestion I made fulfills this, but it also slightly defeats 
one purpose of the operator, being terse.


We also now need to keep backwards compatibility, this fails.


Re: What the hell is wrong with D?

2017-09-19 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 19 September 2017 at 17:40:20 UTC, EntangledQuanta 
wrote:
I assume someone is going to tell me that the compiler treats 
it as


writeln((x + (_win[0] == '@')) ? w/2 : 0);

Yeah, that is really logical!


Yeah, I've been bitten by that in languages like C#. I wish D 
didn't follow in C#'s footsteps and chosen a different syntax: 
`()? :`


That way if there aren't any parentheses the compiler could throw 
out an error until you specify what the operating is working 
with. It would make for a little overhead but these complex 
ternary expressions can be confusing.


Re: Ranges seem awkward to work with

2017-09-11 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 12 September 2017 at 01:18:21 UTC, Nicholas Wilson 
wrote:

On Tuesday, 12 September 2017 at 01:13:29 UTC, Hasen Judy wrote:

Is this is a common beginner issue?


if `range.save` works use that, otherwise


std.csv does not, IIRC.



`range.dup` will duplicate the range


That isn't a range property.


or `range.array` (from std.array) will enumerate the range into 
an array (which is pretty much the same as your solution above.


This. Ranges are great in part because they are often lazy, a 
sequence of operations can be defined but only executed when 
used. Some operations need the whole collection, eg sort.


Re: Little app using gtkD, how to make it well?

2017-09-11 Thread Jesse Phillips via Digitalmars-d-learn

On Monday, 11 September 2017 at 20:19:28 UTC, Romain wrote:

Hello,

I started an application using gtkD and libusb-d. I would love 
to get some hints about how to make good use of D since I'm a 
java developper and maybe use too much of it in D code or doing 
wrong things.


The program will only work with msi laptop that have a 
steelseries keyboard, but it may work with other hardware and 
is untested.


I think the program leak (or don't release the usb handle) when 
exiting using ctrl+c for example, so I may move the Keyboard 
and all libusb object in the global scope and use them by using 
a kind of sigterm handler. Initially I used the "scope(exit){}" 
but it don't work :)



Thanks you


scope(exit) isn't going to handle a ctrl+c on the program. Your 
OS should handle resource acquisition once the program has been 
killed.


Re: One path skips constructor - is this a bug?

2017-09-07 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 7 September 2017 at 16:08:53 UTC, Piotr Mitana wrote:

Code:

===
import std.conv;
import std.regex;

struct A



This throws a compilation error:

main.d(17): Error: one path skips constructor
main.d(15): Error: return without calling constructor

Why do I need the constructor call, if I throw the exception 
anyway? Is this a bug?


This seems likely a bug, my understanding of this error is for 
class inheritance, where it must call the super constructor for 
all code paths to create the base class. With a struct the 
compiler always has the means to create the base and so it just 
seems to be be saying, "hey you called the constructor maybe you 
still want to do that here."


And it would be a nice improvement to have control flow, but you 
may get away with it if you add assert(0); to the end of the 
constructor.


Re: New programming paradigm

2017-09-07 Thread Jesse Phillips via Digitalmars-d-learn
On Monday, 4 September 2017 at 03:26:23 UTC, EntangledQuanta 
wrote:
To get a feel for what this new way of dealing with dynamic 
types might look like:


void foo(var y) { writeln(y); }

var x = "3"; // or possibly var!(string, int) for the explicit 
types used

foo(x);
x = 3;
foo(x);

(just pseudo code, don't take the syntax literally, that is not 
what is important)


While this example is trivial, the thing to note is that there 
is one foo declared, but two created at runtime. One for string 
and one for and int. It is like a variant, yet we don't have to 
do any testing. It is very similar to `dynamic` in C#, but 
better since actually can "know" the type at compile time, so 
to speak. It's not that we actually know, but that we write 
code as if we knew.. it's treated as if it's statically typed.


It is an interesting thought but I'm not sure of its utility. 
First let me describe how I had to go about thinking of what this 
means. Today I think it would be possible for a given function 
'call()' to write this:


alias var = Algebraic!(double, string);

void foo(var y) {
mixin(call!writeln(y));
}

Again the implementation of call() is yet to exist but likely 
uses many of the techniques you describe and use.


Where I'm questioning the utility, and I haven't used C#'s 
dynamic much, is with the frequency I'm manipulating arbitrary 
data the same, that is to say:


auto m = var(4);
mixin(call!find(m, "hello"));

This would have to throw a runtime exception, that is to say, in 
order to use the type value I need to know its type.


A couple of additional thoughts:

The call() function could do something similar to pattern 
matching but args could be confusing:


mixin(call!(find, round)(m, "hello"));

But I feel that would just get confusing. The call() function 
could still be useful even when needing to check the type to know 
what operations to do.


if(m.type == string)
mixin(call!find(m, "hello"));

instead of:
if(m.type == string)
m.get!string.find("hello");


Re: Bug in D!!!

2017-09-02 Thread Jesse Phillips via Digitalmars-d-learn
On Saturday, 2 September 2017 at 00:00:43 UTC, EntangledQuanta 
wrote:
Regardless of the implementation, the idea that we should throw 
the baby out with the bathwater is simply wrong. At least there 
are a few who get that. By looking in to it in a serious manner 
an event better solution might be found. Not looking at all 
results in no solutions and no progress.


Problem is that you didn't define the problem. You showed some 
code the compiler rejected and expressed that the compiler needed 
to figure it out. You did change it to having the compiler 
instantiate specified types, but that isn't defining the problem.


You didn't like the code needed which would generate the 
functions and you hit a Visual D with the new static foreach.


All of these are problems you could define, and you could have 
evaluated static foreach as a solution but instead stopped at 
problems with the tooling.


You also don't appear to care about the complexity of the 
language. I expressed three required changes some of which may 
not play nicely with least surprise. You went straight to, we 
just need to define a syntax for that instead of expressing 
concern that the compiler will also need to handle errors to the 
use, such that the user understands that a feature they use is 
limited to very specific situations.


Consider if you have a module defined interface, is that 
interface only available for use in that module? If not, how does 
a different model inherent the interface, does it need a 
different syntax.


There is a lot more to a feature then having a way to express 
your desires. If your going to stick to a stance that it must 
exist and aren't going to accept there are problems with the 
request why expect others to work through the request.


Re: Bug in D!!!

2017-09-01 Thread Jesse Phillips via Digitalmars-d-learn
I've love being able to inherit and override generic functions in 
C#. Unfortunately C# doesn't use templates and I hit so many 
other issues where Generics just suck.


I don't think it is appropriate to dismiss the need for the 
compiler to generate a virtual function for every instantiated T, 
after all, the compiler can't know you have a finite known set of 
T unless you tell it.


But lets assume we've told the compiler that it is compiling all 
the source code and it does not need to compile for future 
linking.


First the compiler will need to make sure all virtual functions 
can be generated for the derived classes. In this case the 
compiler must note the template function and validate all derived 
classes include it. That was easy.


Next up each instantiation of the function needs a new v-table 
entry in all derived classes. Current compiler implementation 
will compile each module independently of each other; so this 
feature could be specified to work within the same module or new 
semantics can be written up of how the compiler modifies already 
compiled modules and those which reference the compiled modules 
(the object sizes would be changing due to the v-table 
modifications)


With those three simple changes to the language I think that this 
feature will work for every T.


Re: std.algorithm.joiner unexpected behavior

2017-08-31 Thread Jesse Phillips via Digitalmars-d-learn
On Thursday, 31 August 2017 at 18:26:33 UTC, Sergei Degtiarev 
wrote:

Hi,
I tried to create a simple range concatenating several files, 
something like this:


File[] files;

foreach(ln; joiner(files.map!(a => a.byLine)))
writeln(ln);

and I see every first line of each file is missing.
However, when I do same thing with separator:

char[][] separator=[" new file ".dup];
foreach(ln; joiner(files.map!(a => a.byLine), separator))
writeln(ln);

everything works fine, both separator and first lines are 
printed.
It looks pretty much as a bug for me, but I'm not sure I use it 
correctly.


Doesn't byLine() reuse a buffer, joiner probably caches the first 
line and calls .popFront()


Re: It makes me sick!

2017-07-27 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 27 July 2017 at 03:34:19 UTC, FoxyBrown wrote:
Knowing that every time I upgrade to the latest "official" D 
compiler I run in to trouble:


I recompiled gtkD with the new compiler, same result.  My code 
was working before the upgrade just fine and I did not change 
anything.


I've had to delete my previous install at least 2 times before. 
It is an infrequent headache I hit because I'm not following 
appropriate install steps. I cannot expect upstream to support a 
DMD folder which has additional files from what they have 
provided.


Here is my attempt to explain the problem.

* std/datetime.d has a different mangled name than 
std/datetime/package.d.
* The phobos.lib contains the std.datetime.package module and no 
longer contains the std.datetime module.
* When the compiler is reading your code it sees imports for 
std.datetime and looks at the import location 
/install/directory/dmd2/src/std and it writes a reference to the 
std/datetime.d file.
* The linker takes over, loads up phobos.lib and barfs since the 
referenced symbol was not compiled into your obj file nor the 
released phobos.lib.


More recently the headache I've been hitting with upgrades is 
improvements to @safe and such. The bug fixes around this cause 
libraries I'm using to fail compilation. Even this isn't so bad, 
but the library that files is a dependent of a dub package I'm 
using. This means I have to wait for the dependent package to 
update and release followed by the dub package I'm actually 
referencing. So even if I create the needed patches, I have to 
wait at each step for the author to merge and tag their release. 
(or create a branch of the project and throw it in dub so I can 
control all the updates)


Re: Implementing interfaces using alias this

2017-06-16 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 16 June 2017 at 08:34:21 UTC, Biotronic wrote:

On Thursday, 15 June 2017 at 18:49:58 UTC, Jesse Phillips wrote:

wrap!IDuck


Ah, so it does exist in Phobos. I thought it should be there, 
but didn't find it. Thanks!


--
  Biotronic


Yeah, when Andrei introduced the wrap function I was disappointed 
it only wrapped classes. But in truth I haven't really been using 
it for structs either. That may partly be because it can't wrap 
to the range interface.


Re: Implementing interfaces using alias this

2017-06-15 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 09:34:27 UTC, Balagopal Komarath 
wrote:
Why doesn't this work? The Test!Duck type has a void quack() 
method but the compiler says it is not implemented.


You question was answered, but you can do this:

--
interface IDuck
{
void quack();
}

struct Duck
{
void quack()
{
import std.stdio : writeln;
writeln("Quack");
}
}


void main()
{
Duck d;
import std.experimental.typecons : wrap;
IDuck i = wrap!IDuck(d);
i.quack();
}
-

Please note that you can't wrap to an interface which returns 
itself


interface IDuck {
IDuck clone();
}

It fails because the struct would return a Duck and wouldn't wrap 
it to an IDuck. This is only a limitation on wrap because I 
haven't written the detection and appropriate wrapping function 
call.


Re: Can assumeSafeAppend() grab more and more capacity?

2017-06-06 Thread Jesse Phillips via Digitalmars-d-learn

On Monday, 5 June 2017 at 23:17:46 UTC, Ali Çehreli wrote:

auto a = [ 1, 2, 3, 4 ];
auto b = a;

Both of those slices have non-zero capacity yet one of them 
will be the lucky one to grab it. Such semantic issues make me 
unhappy. :-/


Ali


You have to remember that slices don't own their memory. So while 
capacity show a guaranteed reserved memory, it is reserved for 
the dynamic array the slice has a window into.


Remove probably shouldn't try to reclaim capacity, while it is 
destructive for any other slice, it shouldn't make string 
appending also destructive.


untested:

 auto a = [ 1, 2, 3, 4 ];
 auto b = a[$-1, $];
 a.remove(2);
 assert(b == [4]);
 a ~= 6;
 assert(b == [4]);


Re: Access specifiers and visibility

2017-05-10 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 10 May 2017 at 13:29:40 UTC, Andrew Edwards wrote:

On Wednesday, 10 May 2017 at 13:13:46 UTC, Jesse Phillips wrote:
On Wednesday, 10 May 2017 at 01:42:47 UTC, Andrew Edwards 
wrote:
Attempting to update a git repo to current D, I encounter the 
following deprecation messages:


src/glwtf/signals.d-mixin-256(256,2): Deprecation: 
glwtf.input.BaseGLFWEventHandler._on_key_down is not visible 
from module glwtf.signals


Thanks,
Andrew


This comes from:
http://dlang.org/changelog/2.071.0.html#dip22

The module glwtf.signals needs to import glwtf.input. One of 
the other imports was contaminating the namespace.


I actually attempted solve the issue with selective import as 
such::


import glwtf.input : BaseGLFWEventHandler;

but it did not work. Importing the entire module does not work 
either.


I'm not sure the library you're using but this like the one:
https://github.com/Dav1dde/glwtf/blob/master/glwtf/input.d#L163

This code says that the function is protected.

https://github.com/Dav1dde/glwtf/blob/master/glwtf/signals.d#L254

This line is probably mixing in a call to that function into a 
struct


https://github.com/Dav1dde/glwtf/blob/master/glwtf/signals.d#L229

But that struct doesn't inherit from the class so it can't access 
protected fields.


Re: Processing a gzipped csv-file by line-by-line

2017-05-10 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 10 May 2017 at 22:20:52 UTC, Nordlöw wrote:
What's fastest way to on-the-fly-decompress and process a 
gzipped csv-fil line by line?


Is it possible to combine

http://dlang.org/phobos/std_zlib.html

with some stream variant of

File(path).byLineFast

?


You can't really parse a CSV file line-by-line.

H.S. Teoh mentioned fastcsv but requires all the data to be in 
memory.


If you can get the zip to decompress into a range of dchar then 
std.csv will work with it. It is by far not the fastest, but much 
speed is lost since it supports input ranges and doesn't 
specialize on any other range type.


Re: Error writing file a *.obj

2017-05-10 Thread Jesse Phillips via Digitalmars-d-learn

On Tuesday, 9 May 2017 at 02:33:06 UTC, dummy wrote:

On Monday, 8 May 2017 at 12:29:27 UTC, bachmeier wrote:

On Monday, 8 May 2017 at 11:56:10 UTC, dummy wrote:


When i build some application with dub, i got this error:


I'm not a Dub user, but it has its own forum, so you might 
want to try there:

http://forum.rejectedsoftware.com/


Oh, i solve this problem my self...
because, the 'Ransomeware Protection' feature of Bitdefender 
InternetSecurity 2017.

dub and dmd working pretty when i turn off this feature.

Very sorry for noob question :/


Not at all, I got hit by Bitdefender when upgrading the compiler 
and took a while to find why my files weren't extracting. I 
submitted the DMD zip to them to fix it since I couldn't submit 
the files the AV was deleting. Definitely submit your 
executables/libs/objects.


https://www.bitdefender.com/submit/


Re: Access specifiers and visibility

2017-05-10 Thread Jesse Phillips via Digitalmars-d-learn

On Wednesday, 10 May 2017 at 01:42:47 UTC, Andrew Edwards wrote:
Attempting to update a git repo to current D, I encounter the 
following deprecation messages:


src/glwtf/signals.d-mixin-256(256,2): Deprecation: 
glwtf.input.BaseGLFWEventHandler._on_key_down is not visible 
from module glwtf.signals


Thanks,
Andrew


This comes from:
http://dlang.org/changelog/2.071.0.html#dip22

The module glwtf.signals needs to import glwtf.input. One of the 
other imports was contaminating the namespace.


Re: Generating switch at Compile Time

2017-04-17 Thread Jesse Phillips via Digitalmars-d-learn

On Thursday, 13 April 2017 at 21:33:28 UTC, ag0aep6g wrote:
That's not a static foreach. It's a normal run-time foreach. 
The switch jumps into the loop body without the loop head ever 
executing. The compiler is correct when it says that 
initialization of li is being skipped.


Good good. I did miss that as I was trying different things.

Make `list` an enum or alias instead. Then the foreach is 
unrolled at compile time, you don't get a deprecation message, 
and it works correctly.


Yes it did.

By the way, in my opinion, `case li[0]:` shouldn't compile with 
the static immutable `list`. `list` and `li[0]` are dynamic 
values. The compiler only attempts (and succeeds) to evaluate 
them at compile time because they're typed as immutable. The 
way I see it, that only makes things more confusing.


This is very interesting. I wonder if the compiler is still 
unrolling the loop at compile time since it functions as 
expected; It certainly needs that deprecation though.


  1   2   3   4   5   6   7   >