Re: What kind of Editor, IDE you are using and which one do you like for D language?

2019-12-22 Thread Soulsbane via Digitalmars-d-learn

On Sunday, 22 December 2019 at 17:20:51 UTC, BoQsc wrote:
There are lots of editors/IDE's that support D language: 
https://wiki.dlang.org/Editors


What kind of editor/IDE are you using and which one do you like 
the most?


VSCode with this extension:
https://marketplace.visualstudio.com/items?itemName=LaurentTreguier.vscode-dls


Re: Are there any DUB packages for displaying an ascii table?

2019-12-08 Thread Soulsbane via Digitalmars-d-learn

On Sunday, 8 December 2019 at 08:12:49 UTC, mipri wrote:

On Sunday, 8 December 2019 at 08:01:32 UTC, Soulsbane wrote:
Been playing with Golang lately and it has quite a few modules 
for terminal tables. For example this one: 
github.com/brettski/go-termtables.


Is there a D equivalent package? Can't seem to find any via 
search(which by the ways seems to give bad results or I just 
can't find the right word to search with).


Thanks!


This exists and was updated as recently as the first of 
December:


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

I don't see any other dub packages that look related.


Thanks! I'll try it. The search seems to be really strict. Didn't 
show up when I searched 'table'. LOL doesn't show up with 'ascii' 
either. Put them together and it finds it.


Thanks again though, I appreciate it!


Are there any DUB packages for displaying an ascii table?

2019-12-08 Thread Soulsbane via Digitalmars-d-learn
Been playing with Golang lately and it has quite a few modules 
for terminal tables. For example this one: 
github.com/brettski/go-termtables.


Is there a D equivalent package? Can't seem to find any via 
search(which by the ways seems to give bad results or I just 
can't find the right word to search with).


Thanks!


Re: Distinguish float and integer types from string

2019-03-11 Thread Soulsbane via Digitalmars-d-learn

On Saturday, 9 March 2019 at 18:11:09 UTC, Jacob Shtokolov wrote:

Hi,

Recently, I was trying to solve some funny coding challenges 
(https://www.techgig.com).
The questions were really simple, but I found it interesting 
because the website allows to use D.


One of the task was to take a string from STDIN and detect its 
type.
There were a few options: Float, Integer, string and "something 
else" (which, I think, doesn't have any sense under the scope 
of the task).


Anyway, I was struggling to find a built-in function to 
distinguish float and integer types from a string.


I came to the following solution:

```
import std.stdio;
import std.range;
import std.conv;
import std.string;
import std.format;

immutable msg = "This input is of type %s";

void main()
{
string type;
auto data = stdin.byLine.takeOne.front;

if (data.isNumeric) {
type = data.indexOf(".") >= 0 ? "Float" : "Integer";
}
else {
type = "string";
}

writeln(msg.format(type));
}
```

But I think that's ugly. The thing is that in PHP, for example, 
I would do that like this:


```
if (is_integer($data)) {
//...do smth
}
else if (is_float($data)) {
//...do smth
}
else {
//...do smth
}
```

I tried to use std.conv.to and std.conv.parse, but found that 
they can't really do this. When I call `data.to!int`, the value 
of "123.45" will be converted to int!


Is there any built-in way to detect these types?

Thanks!


Unless I'm missing something perhaps two functions like this:

bool isInteger(string value) pure nothrow @safe
{
import std.string : isNumeric;
	return (isNumeric(value) && value.count(".") == 0) ? true : 
false;

}

bool isDecimal(string value) pure nothrow @safe
{
import std.string : isNumeric;
	return (isNumeric(value) && value.count(".") == 1) ? true : 
false;

}




Re: How do I the temlate parameter name as string?

2018-11-26 Thread Soulsbane via Digitalmars-d-learn

On Tuesday, 27 November 2018 at 02:00:44 UTC, PacMan wrote:
ParameterIdentifierTuple from std.traits did work fine for 
regular functions but not for template functions:


Error: template instance 
`std.traits.ParameterIdentifierTuple!(f)` does not match 
template declaration `ParameterIdentifierTuple(func...) if 
(func.length == 1 && isCallable!func)` (foo)


f is defined as:


void f(T)(T t, string p)
if(is(T == A) || is(T == B))
{
// ...
}


my goal is get "p" as string.
If I'm understanding right I need this quite frequently so I 
wrote this:


template nameOf(alias nameType)
{
enum string nameOf = __traits(identifier, nameType);
}

unittest
{
immutable int name;
assert(nameOf!name == "name");
}


Re: Windows Service

2018-11-14 Thread Soulsbane via Digitalmars-d-learn

On Wednesday, 14 November 2018 at 19:38:08 UTC, Thomas wrote:

Hi,

I want to run a D program as a Windows service. After googl'in, 
I only found a very old project on github:

https://github.com/tylerjensen/WindowsServiceInD

Unfortunately, I wasn't able to compile it successfully.
Does anybody know of newer approaches or even a template to 
start from?


Thanks in advance,
Thomas


There is https://code.dlang.org/packages/daemonize
I've only played with it a little on the Linux side so I'm not 
sure how good the windows service implementation is.


Re: Where do I learn to use GtkD

2018-10-30 Thread Soulsbane via Digitalmars-d-learn

On Tuesday, 30 October 2018 at 04:22:21 UTC, helxi wrote:

On Sunday, 13 March 2016 at 19:28:57 UTC, karabuta wrote:
https://gitlab.com/9898287/gtkdnotes


Oh Wow! That's really nice. Thanks for putting this together! 
Much appreciated.


Re: Is it bad form to put code in package.d other than imports?

2018-01-03 Thread Soulsbane via Digitalmars-d-learn
On Wednesday, 3 January 2018 at 07:43:52 UTC, Jonathan M Davis 
wrote:
On Wednesday, January 03, 2018 06:10:10 Soulsbane via 
Digitalmars-d-learn wrote:

[...]


The entire reason that the package.d feature was added was so 
that it would be possible to split a module into a package 
without breaking code. Anything beyond that was beyond the 
scope of the purpose of the feature, albeit not necessarily in 
conflict with its original purpose.


[...]


Wow! Thanks Johnathan for the thorough explanation!


Is it bad form to put code in package.d other than imports?

2018-01-02 Thread Soulsbane via Digitalmars-d-learn
I've only understood that imports should go in package.d. I'm 
seeing more and more packages on code.dlang.org using it for the 
packages primary code. Is this alright? As far as I can tell it's 
just bad form. It would be nice to have one of the maintainers 
higher up the food chain comment on this!


Thanks!


Re: html fetcher/parser

2017-08-12 Thread Soulsbane via Digitalmars-d-learn

On Saturday, 12 August 2017 at 19:53:22 UTC, Faux Amis wrote:
I would like to get into D again by making a small program 
which fetches a website every X-time and keeps track of all 
changes within specified dom elements.


fetching: should I go for std curl, vibe.d or something else?
parsing: I could only find these dub packages: htmld & 
libdominator.

And they don't seem overly active, any recommendations?

As I haven't been using D for some time I just don't want to 
get off with a bad start :)

thx


I've the requests module nice to work with: 
http://code.dlang.org/packages/requests


Re: DDox and filters.

2017-07-27 Thread Soulsbane via Digitalmars-d-learn

On Thursday, 27 July 2017 at 03:01:50 UTC, Danni Coy wrote:
I am trying to build my projects documentation via the ddox 
system via dub. It seems that my modules are being documented 
and then filtered out.


Ironically for a documentation system there isn't a lot of 
documentation.
What is the minimum I need in order for documentation to show 
up?

how do I control the filter options.


I think I had this problem and solved it by adding a comment 
block at the top describing the module.


Re: Recommend: IDE and GUI library

2017-03-26 Thread Soulsbane via Digitalmars-d-learn

On Wednesday, 1 March 2017 at 20:23:57 UTC, aberba wrote:

On Friday, 24 February 2017 at 22:44:55 UTC, XavierAP wrote:

[...]


Gtkd is obviously defacto for Linux ONLY, dlangui for cross 
platform app without native feel. But if you want something 
easy and flexible with native look and feel on all platforms, 
well tested, use LibUI (http://code.dlang.org/packages/libuid). 
Look inside the "examples" folder in their Github repository to 
see example usage.


More like:
 auto hbox = new Box(false).setPadded(1);
 vbox.append(hbox);

hbox.append(new Button("Button"))
.append(new Checkbox("Checkbox"))
...

Examples:
https://github.com/mogud/libuid/blob/master/examples/example1.d
https://github.com/mogud/libuid/blob/master/examples/example2.d


I second this. I've been playing with this recently and it's 
really easy to use.


Re: Using filter with std.container.Array.

2017-03-22 Thread Soulsbane via Digitalmars-d-learn
On Thursday, 23 March 2017 at 03:02:54 UTC, Jonathan M Davis 
wrote:
On Thursday, March 23, 2017 02:53:40 Soulsbane via 
Digitalmars-d-learn wrote:

[...]


find just iterates to the first element that matches. It 
doesn't affect the range beyond that. It works basically the 
same way that find would work with iterators in that it 
iterates until it finds the element you're looking for. 
However, since ranges then refer to more than one element at a 
time, the rest of the range beyond that element is still there.


[...]


Thanks a lot for the explanation. It's much clearer to me now! 
You've been a big help.


Re: Using filter with std.container.Array.

2017-03-22 Thread Soulsbane via Digitalmars-d-learn
On Wednesday, 22 March 2017 at 07:30:48 UTC, Jonathan M Davis 
wrote:
On Wednesday, March 22, 2017 07:06:47 Soulsbane via 
Digitalmars-d-learn wrote:

Example code:
struct Foo
{
   string name;
   size_t id;
}

Array!Foo foo_;

I get errors when I try to use filter like this:

auto found = filter!((Foo data, size_t id) => data.id ==
id)(foo_[], 100);

I get this error
source/app.d(15,62): Error: template
std.algorithm.iteration.filter!(function (Foo data, ulong id) 
=>
data.id == id).filter cannot deduce function from argument 
types

!()(RangeT!(Array!(Foo)), int), candidates are:
/usr/include/dmd/phobos/std/algorithm/iteration.d(1089,10):
  std.algorithm.iteration.filter!(function (Foo data, ulong 
id) =>

data.id == id).filter(Range)(Range range) if
(isInputRange!(Unqual!Range))

I can't figure out what I'm doing wrong. Thanks!


filter takes a unary predicate that gets called on each element 
in a range. It's not going to work with a function that takes 
two arguments, and filter itself isn't going to take two 
arguments. You could do something like


auto result = filter!(a => a.id == 100)(foo_[]);

but you can't pass multiple arguments to filter. Also, if 
you're looking to find an element, then find would make more 
sense than filter, since filter is going to give you a lazy 
range with every element that matches the predicate, whereas 
find is just going to iterate the range until it finds the 
element (or is empty) and then returns the range. But I don't 
know whether calling the variable found was just the name you 
came up with or whether you're really trying to do a find 
operation rather than filter.


- Jonathan M Davis


Thanks for the reply Jonathan! Yes, I was trying to find all the 
ids that match but couldn't get find to work. So I think I have 
missed something somewhere.


As a quick example:
import std.stdio;
import std.algorithm;
import std.container;

struct Foo
{
  string name;
  size_t id;
}

Array!Foo foo_;

void main(string[] arguments)
{
Foo first;
first.id = 200;

Foo second;
second.id = 100;

Foo third;
third.id = 345;

Foo fourth;
fourth.id = 100;

foo_.insert(first);
foo_.insert(second);
foo_.insert(third);
foo_.insert(fourth);

auto filterIt = filter!((Foo data) => data.id == 100)(foo_[]);
auto foundIt = find!((Foo data) => data.id == 100)(foo_[]);
writeln(filterIt);
writeln(foundIt);
}

Will print:
[Foo("", 100), Foo("", 100)]
[Foo("", 100), Foo("", 345), Foo("", 100)]

I only want the ids that match 100. Looking at find's 
documentation it looks like it's returning exactly as it should 
but not the way I want. No 345 id.


Thanks for the help. I have this code working just fine using 
foreach and have been trying to learn this different way of doing 
things lately and my brain hurts :). Thanks again.




Using filter with std.container.Array.

2017-03-22 Thread Soulsbane via Digitalmars-d-learn

Example code:
struct Foo
{
  string name;
  size_t id;
}

Array!Foo foo_;

I get errors when I try to use filter like this:

auto found = filter!((Foo data, size_t id) => data.id == 
id)(foo_[], 100);


I get this error
source/app.d(15,62): Error: template 
std.algorithm.iteration.filter!(function (Foo data, ulong id) => 
data.id == id).filter cannot deduce function from argument types 
!()(RangeT!(Array!(Foo)), int), candidates are:
/usr/include/dmd/phobos/std/algorithm/iteration.d(1089,10):   
 std.algorithm.iteration.filter!(function (Foo data, ulong id) => 
data.id == id).filter(Range)(Range range) if 
(isInputRange!(Unqual!Range))


I can't figure out what I'm doing wrong. Thanks!


Re: Using tango with dub

2016-12-17 Thread Soulsbane via Digitalmars-d-learn

On Saturday, 17 December 2016 at 20:26:53 UTC, albert-j wrote:

I thought Tango was obsolete a long time ago.

Is there a specific reason you need to use Tango and can't use 
Phobos?


I need a Set implementation and from what I understand there 
isn't one in Phobos right now?


Have you seen https://github.com/economicmodeling/containers it 
has a HashSet 
http://economicmodeling.github.io/containers/containers/hashset.HashSet.html


Re: Popular embedded language for scripting in D

2016-11-20 Thread Soulsbane via Digitalmars-d-learn

On Saturday, 19 November 2016 at 22:18:39 UTC, Sai wrote:
I have seen luad and Walters own JavaScript VM that can be used 
in D for embedded scripting purpose in an application.


I was wondering which is more popular among D applications? Any 
suggestions?


Thanks, sai


I've used LuaD in a couple projects now and been fairly happy 
with it. I'm partial to Lua though(not a fan of Javascript).