Re: How to get the client's MAC address in Vibe

2024-02-07 Thread Mengu via Digitalmars-d-learn
On Wednesday, 7 February 2024 at 22:16:54 UTC, Alexander Zhirov 
wrote:
Is there a way to identify a client by MAC address when using 
the Vibe library?
The `NetworkAddress` 
[structure](https://vibed.org/api/vibe.core.net/NetworkAddress) 
does not provide such features. Or did I miss something?


That doesn't have anything to do with the server side if I am not 
mistaken as you should receive that via the browser that actually 
allows you to receive the mac address -via an extension- or some 
private API exposed by the browser.


I don't know the use case but you may be better off with browser 
fingerprinting if you'd like to have a unique way of identifying 
the visitors. Or, if it's a local network, maybe you can use 
tcpdump/libpcap.


Re: Effective String to Date conversion?

2024-01-28 Thread Mengu via Digitalmars-d-learn

On Monday, 22 January 2024 at 10:56:04 UTC, atzensepp wrote:

Dear D-gurus,

being new to D I am trying my first steps and the language is 
quite intuitive and appealing.
When reading a file and creating a hash for the reocrds I want 
to get only the most recent ones. For this I need to convert 
Date/Time-Strings to comparable DateTime-Objects.
The code below works but looks a bit clumsy. Is there a more 
efficient (shorter) way to accomplish this?


[...]


If your date conforms to an ISO or extended ISO format, you can 
use DateTime.fromISOString [0] or DateTime.fromISOExtString [1] 
functions.


[0] 
https://dlang.org/phobos/std_datetime_date.html#.Date.fromISOString
[1] 
https://dlang.org/phobos/std_datetime_date.html#.Date.fromISOExtString


Re: Creating Struct for an output of a program.

2018-01-09 Thread Mengu via Digitalmars-d-learn

On Tuesday, 9 January 2018 at 07:57:19 UTC, Vino wrote:

Hi All,

 Request your help on how to create a struct with the output of 
the below program.


Program:
import std.algorithm: all, map, filter;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
import std.container.array;
import std.string: split, strip;
import std.uni: isWhite, toLower;
import std.range: chunks;

void main () {
Array!string TableData, StructureData;
auto Meta = 
File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\meta\\meta.txt", "r");

auto MetaData = Array!(Tuple!(string, string))(Meta.byLineCopy()
.filter!(line => !line.all!isWhite)
.map!(a => a.split(":"))
.map!(a => tuple(a[0].toLower.strip, a[1].toLower.strip)));
foreach (line; MetaData[]) { TableData.insertBack(line[0]); 
StructureData.insertBack(line[1]); }

for(int i = 0; i < TableData[].length; i++ ) {
auto S1 = StructureData[i].split(",").chunks(3);
auto S2 = S1.map!(a => tuple(a[0],a[1],a[2]));
for(int z =0; z < S2.length; z++)
{ writefln("%-8s %;s", S2[z][1] , S2[z][0]); }
}
}

Output:
string name;
string country;
int age;


Need to create as struct using the output

struct Layout {
{
string name;
string country;
int age;

}

From,
Vino.B


if S2 consists of data for Layout struct, then you can simply do:

auto S2 = S1.map!(a => Layout(a[0], a[1], a[2]));

which will give you a range of Layout.


Re: C++ Interop

2018-01-06 Thread Mengu via Digitalmars-d-learn

On Friday, 5 January 2018 at 13:02:12 UTC, qznc wrote:
I'm exploring [0] C++ interop after watching Walter's 
presentation [1].


I hit a block with classes as template parameters. This means 
vector works, but vector does not. D seems to map 
vector!Foo to vector. Likewise shared_ptr is a 
problem. Any way to fix that on the D side? The ugly workaround 
is to adapt the C++ code.


I understand that this mapping makes sense for function calls 
because bar(Foo f) in D maps to bar(Foo *f) in C++. And C++ 
bar(Foo f) has no equivalent in D because classes are reference 
types.


On a related note, C++ interop requires to redeclare or even 
reimplement C++ code. Has anybody started a libcpp-in-d 
project? I'm looking for basics like vector and string.


[0] https://github.com/qznc/d-cpptest
[1] https://youtu.be/IkwaV6k6BmM


is C++ support in LDC better than what we have with DMD?

i did checkout your code btw and could not enjoy it more. :)


Re: How do you safely deal with range.front?

2017-12-30 Thread Mengu via Digitalmars-d-learn

On Saturday, 30 December 2017 at 19:00:07 UTC, aliak wrote:

On Friday, 29 December 2017 at 20:47:44 UTC, Dukc wrote:

[...]


Hmm, interesting. Not sure that's what I'm looking for but I 
like it anyway :)


I'm more looking to deal with situations like this:

Instead of this:
  auto result = range.op!f;
  if (!result.empty) {
result.front.method();
  }

This:
  range.op!f.ifFront.method();


In the above scenario I only want method to be called if the 
pipeline resulted in any element left in the range.



[...]


True you don't want to call front on empty, but sometimes I 
only care to call a method on front if it's there. Where the 
situation necessitates the existence of front, and not having a 
front is indeed a bug, then you want the program to terminate, 
yes. But not otherwise.


it would be actually great in such scenarios if d had a language 
construct for existantial checks. you'd just be able to do 
range.front?.method(). but no, it is not 2017. d does not need it.


Re: structs inheriting from and implementing interfaces

2017-12-29 Thread Mengu via Digitalmars-d-learn
On Friday, 29 December 2017 at 13:08:38 UTC, rikki cattermole 
wrote:

On 29/12/2017 12:59 PM, rjframe wrote:

On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote:


[...]


I've actually thought about doing this to get rid of a bunch 
of if
qualifiers in my function declarations. `static interface {}` 
compiles but
doesn't [currently] seem to mean anything to the compiler, but 
could be a
hint to the programmer that nothing will directly implement 
it; it's a
compile-time interface. This would provide a more generic way 
of doing

stuff like `isInputRange`, etc.


Or we could get signatures, which are even better still!


+ for SML style signatures!


Re: How do I set a class member value by its name in a string?

2017-12-28 Thread Mengu via Digitalmars-d-learn

On Wednesday, 27 December 2017 at 23:47:14 UTC, Biotronic wrote:

[...]


much, much better. thanks biotronic.


Re: How do I set a class member value by its name in a string?

2017-12-27 Thread Mengu via Digitalmars-d-learn

On Wednesday, 27 December 2017 at 21:39:49 UTC, Mengu wrote:

On Wednesday, 27 December 2017 at 20:54:17 UTC, bitwise wrote:

[...]


there's also a simple workaround for fields with the same type: 
https://run.dlang.io/is/dsFajq


import std.stdio;

struct S {
  int x;
  int y;
}

auto setValue(ref S s, string field, int value) {
  foreach (fieldName; __traits(allMembers, S)) {
if (fieldName == field) {
  __traits(getMember, s, fieldName) = value;
  break;
}
  }
}

void main() {
  S s;
  s.setValue("x", 5);
  s.setValue("y", 25);
  writeln(s);
}


you can play with it to make it more generic. you can also 
create a mixin template that would generate setters for each 
field you would need a setter for and then in the run time 
you'd just be able to call them.


return type should just be void. that's just my muscle memory. :-D


Re: How do I set a class member value by its name in a string?

2017-12-27 Thread Mengu via Digitalmars-d-learn

On Wednesday, 27 December 2017 at 20:54:17 UTC, bitwise wrote:

On Wednesday, 27 December 2017 at 20:04:29 UTC, Marc wrote:
I'd like to set the members of a class by its name at runtime, 
I would do something like this:



__traits(getMember, myClass, name) = value;


but since name is only know at runtime, I can't use 
__traits(). What's a workaround for this?


I think you could write something using a combination of these 
two things:


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

or maybe '.tupleof':

https://dlang.org/spec/struct.html#struct_properties


there's also a simple workaround for fields with the same type: 
https://run.dlang.io/is/dsFajq


import std.stdio;

struct S {
  int x;
  int y;
}

auto setValue(ref S s, string field, int value) {
  foreach (fieldName; __traits(allMembers, S)) {
if (fieldName == field) {
  __traits(getMember, s, fieldName) = value;
  break;
}
  }
}

void main() {
  S s;
  s.setValue("x", 5);
  s.setValue("y", 25);
  writeln(s);
}


you can play with it to make it more generic. you can also create 
a mixin template that would generate setters for each field you 
would need a setter for and then in the run time you'd just be 
able to call them.


Re: partial application for templates

2017-12-26 Thread Mengu via Digitalmars-d-learn
On Monday, 25 December 2017 at 22:58:50 UTC, David Nadlinger 
wrote:

On Monday, 25 December 2017 at 20:39:52 UTC, Mengu wrote:

is partially applying templates possible?


Check out std.meta.Apply{Left, Right}.

 — David


thanks a lot mr. smith & david.


Re: Can I use memoize with a non-static struct method?

2017-12-26 Thread Mengu via Digitalmars-d-learn

On Tuesday, 26 December 2017 at 00:47:14 UTC, Marc wrote:

something like this:


struct S {
  // variables...
  string doGen(int n) { return ""; }
  alias gen = memoize!doGen;
}


The error I got is:


Error: need 'this' for 'doGen' of type 'string(int n)'


I can't make doGen static because it access non-static struct 
members... can I workaround this?


i don't want to mislead you and i don't know if this is somehow 
possible but what about some ufcs magic?



  string doGen(S s, int n) {
return "hello ".repeat().take(n).join();
  }

  struct S {

int x;

auto gen() @property {
  return memoize!doGen(this, x);
}

  }

  void main() {
S s = S(5);
s.gen.writeln;

s.x = 10;
s.gen.writeln;

s.x = 15;
s.gen.writeln;

s.x = 20;
s.gen.writeln;
}



partial application for templates

2017-12-25 Thread Mengu via Digitalmars-d-learn

is partially applying templates possible?


Re: Define enum value at compile time via compiler argument?

2017-12-25 Thread Mengu via Digitalmars-d-learn

On Monday, 25 December 2017 at 16:13:48 UTC, Thomas Mader wrote:

Hello,

I would like to set the path to a directory at compile time but 
it doesn't seem to be possible yet.


I tried it with a -version=CustomPath argument and inside the 
version statement in the code I tried to read the value from 
the environment. Sadly this doesn't work because getenv can not 
be interpreted at compile time because it has no available 
source.


Now my question is if this is somehow possible and I just don't 
see it or would it be possible to add that somehow?


Thanks in advance.

Thomas


is it a relative path? if so:

pragma(msg, __FILE_FULL_PATH__.split("/")[0..$-1].join("/"));


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


Re: Does to!(string)(char[]) do any memory allocation on conversion?

2017-12-25 Thread Mengu via Digitalmars-d-learn

On Monday, 25 December 2017 at 14:12:32 UTC, Marc wrote:
Does to!(string)(char[]) do any memory allocation on conversion 
or is this similar to a cast or what else?


yes, it is allocating memory. you can test such cases with @nogc 
[0].


you can get a char[] via .dup of a string and then you can 
cast(string) if you don't want to allocate any memory.


[0] https://dlang.org/spec/attribute.html#nogc


Re: Converting array in to aliased tuple type.

2017-12-25 Thread Mengu via Digitalmars-d-learn

On Monday, 25 December 2017 at 12:03:32 UTC, aliak wrote:
Hi, been looking for a way to convert an array to a tuple, but 
can't seem to find one. Is there one?


Looking for something like:

alias Point = Tuple!(int, "x", int, "y");
enum data = "1,2:8,9";
auto points = data
  .split(':')
  .map!(a => a
.split(',')
.map!(to!int)
  )
  .map!Point; // <-- this works if you do `.map!(a => 
Point(a[0], a[1]));` instead


Cheers!


hi aliak

since Point is a Tuple and does not have a constructor that takes 
a list of integers (int[]), you should have a helper function.


import std.stdio: writeln;
import std.string: split;
import std.algorithm: map;
import std.typecons: Tuple;
import std.conv: to;

alias Point = Tuple!(int, "x", int, "y");
enum data = "1,2:8,9";
alias makePoint = (auto ref points) => Point(points[0], 
points[1]);
alias convertToInt = (string parts) => 
parts.split(',').map!(to!int);
auto points = 
data.split(':').map!(convertToInt).map!(makePoint);


writeln(points);


Re: One liner for creating an array filled by a factory method

2017-12-23 Thread Mengu via Digitalmars-d-learn

On Saturday, 23 December 2017 at 08:57:18 UTC, kerdemdemir wrote:

On Friday, 22 December 2017 at 23:33:55 UTC, Mengu wrote:
On Thursday, 21 December 2017 at 21:11:58 UTC, Steven 
Schveighoffer wrote:

On 12/21/17 4:00 PM, kerdemdemir wrote:

I have a case like :

http://rextester.com/NFS28102

I have a factory method, I am creating some instances given 
some enums.

My question is about :


void PushIntoVector( BaseEnum[] baseEnumList )
{
     Base[] baseList;
     foreach ( tempEnum; baseEnumList )
     {
    baseList ~= Factory(tempEnum);
     }
}

I don't want to use "foreach" loop. Is there any cool std 
function that I can call ?


Something like baseEnumList.CoolStdFunc!( a=> Factory(a) 
)(baseList);




https://dlang.org/phobos/std_algorithm_iteration.html#map

-Steve


so basically it becomes:

Base[] baseList = baseEnumList.map!(el => Factory(el));

there's also a parallel version of map [0] if you ever need to 
map the list concurrently.


[0] https://dlang.org/phobos/std_parallelism.html#.TaskPool.map


Yeah that was very easy and I used to use map for this purposed 
a lot already. I don't know why I get confused. Thanks guys for 
correction. I began to think like map could transform but it 
can't create vector of elements and this confused me.


it totally depends on the type of resulting element. if you 
expect Base[], then your map should transform your range / array 
elements into a Base.


import std.range, std.algorithm;
auto a = iota(1, 10);
int[] b = a.map!(el => el + 1).array;
int[][] c = a.map!(el => [el, el + 1]).array;
writeln(b);
writeln(c);


Re: One liner for creating an array filled by a factory method

2017-12-22 Thread Mengu via Digitalmars-d-learn
On Thursday, 21 December 2017 at 21:11:58 UTC, Steven 
Schveighoffer wrote:

On 12/21/17 4:00 PM, kerdemdemir wrote:

I have a case like :

http://rextester.com/NFS28102

I have a factory method, I am creating some instances given 
some enums.

My question is about :


void PushIntoVector( BaseEnum[] baseEnumList )
{
     Base[] baseList;
     foreach ( tempEnum; baseEnumList )
     {
    baseList ~= Factory(tempEnum);
     }
}

I don't want to use "foreach" loop. Is there any cool std 
function that I can call ?


Something like baseEnumList.CoolStdFunc!( a=> Factory(a) 
)(baseList);




https://dlang.org/phobos/std_algorithm_iteration.html#map

-Steve


so basically it becomes:

Base[] baseList = baseEnumList.map!(el => Factory(el));

there's also a parallel version of map [0] if you ever need to 
map the list concurrently.


[0] https://dlang.org/phobos/std_parallelism.html#.TaskPool.map


Re: Don't expect class destructors to be called at all by the GC

2017-12-22 Thread Mengu via Digitalmars-d-learn
On Thursday, 21 December 2017 at 18:45:27 UTC, Adam D. Ruppe 
wrote:

On Thursday, 21 December 2017 at 18:20:19 UTC, H. S. Teoh wrote:
When the scoped destruction of structs isn't an option, 
RefCounted!T seems to be a less evil alternative than an 
unreliable class dtor. :-/


Alas, RefCounted doesn't work well with inheritance...

Though, what you could do is make the refcounted owners and 
borrow the actual reference later.


i really wonder how Objective-C and Swift is pulling this off.


Re: Converting member variables to strings with using reflection from base class

2017-12-22 Thread Mengu via Digitalmars-d-learn

On Friday, 22 December 2017 at 22:09:05 UTC, H. S. Teoh wrote:
On Fri, Dec 22, 2017 at 09:13:31PM +, kerdemdemir via 
Digitalmars-d-learn wrote:
I want to make a logging function for member variables by 
using reflection.

[...]

class B
{
void Log()
{
auto a = [__traits(derivedMembers, D)];
foreach(memberName; a) {
// Somehow write only member variables with their 
names

// Result should be : a = 4.0, b = 3.0


Try this:

import std.traits : FieldNameTuple;
foreach (memberName; FieldNameTuple!B) {
writefln("%s = %s", memberName, mixin("this." ~ memberName));
}


T


and then turn it into a LoggerMixin with a mixin template and 
re-use it any time you want.


import std.stdio : writeln, writefln;
import std.traits : FieldNameTuple;

mixin template LoggerMixin() {
  void Log() {
foreach (memberName; FieldNameTuple!(typeof(this))) {
  writefln("%s = %s", memberName, mixin("this." ~ 
memberName));

}

  }
}

struct S {
  int x;
  bool y;
  double z;

  mixin LoggerMixin;
}

void main() {

  S s1 = S(int.min, true, );
  S s2 = S(int.max, false, );
  s1.Log();
  s2.Log();
}



Re: alias to struct method

2017-12-22 Thread Mengu via Digitalmars-d-learn

On Friday, 22 December 2017 at 17:53:34 UTC, Marc wrote:

How can I create a alias to a struct method?


struct S {
 string doSomething(int n) { return ""; }
}


I'd like to do something like this (imaginary code):

alias doSomething = S.doSomething;

then call it by doSomething(3)

I got the following error from this code:


Error: need 'this' for 'gen' of type 'string(int n)'


So I tried create a instance:


alias doSomething = S().doSomething;


Changes the error to:

app.d(96): Error: function declaration without return type. 
(Note that > constructors are always named this)

app.d(96): Error: semicolon expected to close alias declaration


it is also possible with getMember trait but why don't you just 
mark that method as static?


Re: why @property cannot be pass as ref ?

2017-12-20 Thread Mengu via Digitalmars-d-learn

On Wednesday, 20 December 2017 at 18:04:57 UTC, Ali Çehreli wrote:

On 12/20/2017 07:02 AM, ChangLong wrote:
> [...]
is not
> [...]

The problem is not with opAssign but with left(), which returns 
an rvalue. It's by design that rvalues cannot be bound to 
references in D.


[...]


was just reading this: 
https://p0nce.github.io/d-idioms/#Rvalue-references:-Understanding-auto-ref-and-then-not-using-it


Re: Can I run this at compile time?

2017-12-20 Thread Mengu via Digitalmars-d-learn

On Wednesday, 20 December 2017 at 16:54:35 UTC, Marc wrote:

Give this function I'd like to run it at compile time:

import std.concurrency : Generator, yield;

[...]


but when I do:


[...]


I get the following erros:

C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\thread.d(4059): Error: 
static variable PAGESIZE cannot be read at compile time
C:\D\dmd2\windows\bin\..\..\src\phobos\std\concurrency.d(1548):
 called from here: super.this(dg, PAGESIZE * 4u, PAGESIZE)
app.d(96):called from here: getNonIntegralMembers()


if PAGESIZE is not dynamic, it will not work at compile time. 
make it an enum or const and give it a try.


Re: weird exception on windows

2017-12-18 Thread Mengu via Digitalmars-d-learn

On Saturday, 16 December 2017 at 14:05:28 UTC, Vino wrote:

On Saturday, 16 December 2017 at 13:59:11 UTC, Vino wrote:

On Saturday, 16 December 2017 at 12:39:53 UTC, Kagamin wrote:

[...]


H, All,

  Are are also getting the same exception on Windows after 
updating the dmd to version v2.077.1, our code was working 
fine for the past 2 months, the exception is just crashes the 
program, and it occur's every 1 time  among in 3 runs. As per 
Microsoft it stated to download the package apps.diagcab and 
execute, but still no luck.


ExceptionCode: C005

From,
Vino.B


Moreover we were able to find the line of code which was 
causing this exception


string a = "1"
a.to!int.isNumber /* exception is occurring at this point.

From,
Vino.B


the compiler might be parsing the expr like (a.to!(int.isNumber)) 
so it becomes a.to!bool.


Re: GUI program on Mac OS in D?

2017-12-14 Thread Mengu via Digitalmars-d-learn
On Thursday, 14 December 2017 at 14:07:25 UTC, Adam D. Ruppe 
wrote:


I was playing with this myself based on Jacob's code and made 
it look like this:


extern (Objective-C) interface ViewController : 
NSViewController {

extern (C)
@ObjCMethodOverride("loadView")
static void loadView(ViewController self, SEL sel) {
printf("loadView\n");
}

extern (C)
@ObjCMethodOverride("viewDidLoad")
static void viewDidLoad(ViewController self, SEL sel) {
printf("viewDidLoad\n");
}

ViewController init() @selector("init");
mixin RegisterObjCClass;
}



so the mixin does some registering based on the method override 
attrs. It is still static with self cuz I actually felt hiding 
that made things a bit worse (inheritance wouldn't work like 
you expect), but most the registration stuff is now pulled from 
the attribute metadata.



Of course, my goal here isn't actually to do all of obj-c... 
just enough to port my simpledisplay.d. So I'm not sure if I'll 
make this public yet or just leave it as private and/or 
undocumented inside my library file.


please make it public.


Re: Sort characters in string

2017-12-07 Thread Mengu via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 12:43:09 UTC, Fredrik Boulund 
wrote:

On Wednesday, 6 December 2017 at 10:42:31 UTC, Dgame wrote:



Or you simply do

writeln("longword".array.sort);



This is so strange. I was dead sure I tried that but it failed 
for some reason. But after trying it just now it also seems to 
work just fine. Thanks! :)


if you're like me, you probably forgot an import :)


Re: lower case only first letter of word

2017-12-05 Thread Mengu via Digitalmars-d-learn

On Tuesday, 5 December 2017 at 14:34:57 UTC, Mengu wrote:

On Tuesday, 5 December 2017 at 14:01:35 UTC, Marc wrote:
On Tuesday, 5 December 2017 at 13:40:08 UTC, Daniel Kozak 
wrote:

[...]


Yes, this is not what I want. I want to convert only the first 
letter of the word to lower case and left all the others 
immutable. similar to PHP's lcfirst():


http://php.net/manual/en/function.lcfirst.php


this is how i'd do it:

string upcaseFirst(string wut) {
  import std.ascii : toUpper;
  import std.array : appender;

  auto s = appender!string;
  s ~= wut[0].toUpper;
  s ~= wut[1..$];
  return s.data;
}


however a solution that does not allocate any memory would be a 
lot better.


Re: lower case only first letter of word

2017-12-05 Thread Mengu via Digitalmars-d-learn

On Tuesday, 5 December 2017 at 14:01:35 UTC, Marc wrote:

On Tuesday, 5 December 2017 at 13:40:08 UTC, Daniel Kozak wrote:
but this will change all other uppercase to lowercase, so 
maybe it is not what you want. If you really want just change 
first char to upper, then there is nothing wrong to do it 
yourself


On Tue, Dec 5, 2017 at 2:37 PM, Daniel Kozak 
 wrote:


Something like this: 
https://dlang.org/phobos/std_uni.html#asCapitalized


On Tue, Dec 5, 2017 at 2:31 PM, Marc via Digitalmars-d-learn 
< digitalmars-d-learn@puremagic.com> wrote:


Does D have a native function to capitalize only the first 
letter of the word? (I'm asking that so I might avoid 
reinvent the wheel, which I did sometimes in D)


Yes, this is not what I want. I want to convert only the first 
letter of the word to lower case and left all the others 
immutable. similar to PHP's lcfirst():


http://php.net/manual/en/function.lcfirst.php


this is how i'd do it:

string upcaseFirst(string wut) {
  import std.ascii : toUpper;
  import std.array : appender;

  auto s = appender!string;
  s ~= wut[0].toUpper;
  s ~= wut[1..$];
  return s.data;
}


Re: git workflow for D

2017-12-03 Thread Mengu via Digitalmars-d-learn

On Sunday, 3 December 2017 at 20:05:47 UTC, bitwise wrote:
I've finally started learning git, due to our team expanding 
beyond one person - awesome, right? Anyways, I've got things 
more or less figured out, which is nice, because being clueless 
about git is a big blocker for me trying to do any real work on 
dmd/phobos/druntime. As far as working on a single master 
branch works, I can commit, rebase, merge, squash, push, reset, 
etc, like the best of em. What I'm confused about is how all 
this stuff will interact when working on a forked repo and 
trying to maintain pull requests while everyone else's commits 
flood in.


How does one keep their fork up to date? For example, if I fork 
dmd, and wait a month, do I just fetch using dmd's master as a 
remote, and then rebase? Will that actually work, or is that 
impossible across separate forks/branches? What if I have 
committed and pushed to my remote fork and still want to merge 
in the latest changes from dlang's master branch?


you can fork it, set dmd/master as upstream and then git fetch 
upstream. you can then rebase.




And how does a pull request actually work? Is it a request to 
merge my entire branch, or just some specific files? and do I 
need a separate branch for each pull request, or is the pull 
request itself somehow isolated from my changes?


commits can be cherrypick-ed or you can request your entire 
branch to be merged. it doesn't always have to be the master 
branch. for example, if there's std.experimental.logger branch, 
you can ask for your branch to be merged with that. having a 
seperate branch for each feature is most of the time the way to 
go. makes it cleaner for yourself. later on you can delete those 
merged branches.




Anyways, I'd just be rambling if I kept asking questions. If 
anyone can offer any kind of advice, or an article that 
explains these things concisely and effectively, that would be 
helpful.


Thanks





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

2017-09-29 Thread Mengu via Digitalmars-d-learn

On Friday, 29 September 2017 at 02:34:08 UTC, DreadKyller wrote:

On Thursday, 28 September 2017 at 14:01:33 UTC, user1234 wrote:

[...]


I understand that, but because the operator isn't defined 
normally for classes unless overloaded, then your statement 
about this being an inconsistency on the concerns stated prior 
about wrecking implementation of standard features. If & can't 
be overloaded then the type of  will always be a 
pointer, you can't override the dereference operator of the 
pointer itself as far as I can tell, overloading it on the 
class doesn't overload the pointer, thus any standard 
implementation that uses pointers to store an object would be 
completely unaffected by overloading the dereference operator. 
This I don't consider it an inconsistency.


[...]


+1 for forum issue.


Re: What does ! mean?

2017-09-27 Thread Mengu via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 17:58:27 UTC, Ali Çehreli 
wrote:

On 09/27/2017 08:33 AM, Ky-Anh Huynh wrote:
> [...]
Wissner wrote:
> [...]

The fact that such an important operator is explained so late 
in the book is due to the book's strong desire to have a linear 
flow.


[...]


ustad, guess you can still write the new ed. :-)



Re: segfault on gc.impl.conservative.gc.Gcx.smallAlloc

2017-09-26 Thread Mengu via Digitalmars-d-learn

On Tuesday, 26 September 2017 at 17:06:28 UTC, drug wrote:

26.09.2017 00:34, Mengu пишет:

 [...]



not big deal probably, but isn't ~32GB enormous value here? I 
would check why bigDataFun return this.


i could not find out why.

d certainly needs to improve on freebsd. i don't think devs would 
take d seriously if it won't work on a major platform.


for now, i switched to debian rather than rewriting the app. i 
had some invalid memory operation errors but i managed to get rid 
of them. i'll certainly port the app to another language and 
switch back to freebsd.


Re: segfault on gc.impl.conservative.gc.Gcx.smallAlloc

2017-09-26 Thread Mengu via Digitalmars-d-learn

On Monday, 25 September 2017 at 21:34:40 UTC, Mengu wrote:

hi all

this following code block [0] is exiting with "terminated by 
signal SIGBUS (Misaligned address error)" error. it processes 
like 200K rows and then fails. any ideas?


[...]


hi all

does anyone else have any ideas?


Re: segfault on gc.impl.conservative.gc.Gcx.smallAlloc

2017-09-26 Thread Mengu via Digitalmars-d-learn
On Tuesday, 26 September 2017 at 00:36:36 UTC, Vladimir Panteleev 
wrote:

On Monday, 25 September 2017 at 21:34:40 UTC, Mengu wrote:

delete fileContents;


This looks suspicious - it is a slice of the memory-mapped 
file, not memory on the GC-managed heap, so "delete" is 
inapplicable to it. The GC ought to throw an exception when 
attempting to delete things not on the GC heap though.


I think the stack trace itself looks like something that should 
only happen when the GC's internal data structures are 
corrupted, so you may want to investigate in that direction.


thanks vladimir, i'll look into that.

i also should mention that everything works as expected on mac os 
x.


segfault on gc.impl.conservative.gc.Gcx.smallAlloc

2017-09-25 Thread Mengu via Digitalmars-d-learn

hi all

this following code block [0] is exiting with "terminated by 
signal SIGBUS (Misaligned address error)" error. it processes 
like 200K rows and then fails. any ideas?


void getHotels() {
  import std.parallelism : taskPool;
  import std.functional  : partial;

  auto sunHotels = new SunHotels();
  auto destinations  = sunHotels.parseDestinations();
  auto conn  = client.lockConnection();
  auto destinationResult = conn.execStatement("SELECT 
provider_ref, id FROM hotels_destination", ValueFormat.BINARY);

  int[int] destinationIds;

  foreach (row; rangify(destinationResult)) {
destinationIds[row["provider_ref"].as!PGinteger] = 
row["id"].as!PGinteger;

  }

  foreach (destination; parallel(destinations)) {
const string destId = to!string(destination.destinationId);
const auto destinationFilePath = getcwd() ~ 
"/ext/data/hotels/" ~ destId ~ ".xml";

auto xmlFile = new MmFile(destinationFilePath);
auto fileContents = cast(string)xmlFile[0..xmlFile.length];
auto hotels = sunHotels.parseHotelsResult(fileContents);
const destIdInDb = destinationIds[destination.destinationId];
auto sqls = appender!string;
writeln("parsing destination: ", destination.destinationName);

foreach (hotel; parallel(hotels)) {
sqls.put(hotel.generateSql(destIdInDb).data.join);
}

sqls.data.writeln;


delete fileContents;
delete xmlFile;
  }

}

this is the full trace i got [1]:

#0  0x00bef5ef in 
gc.impl.conservative.gc.Gcx.smallAlloc(ubyte, ref ulong, uint) ()

[Current thread is 1 (LWP 100171)]
(gdb) bt full
#0  0x00bef5ef in 
gc.impl.conservative.gc.Gcx.smallAlloc(ubyte, ref ulong, uint) ()

No symbol table info available.
#1  0x00bf3925 in 
gc.impl.conservative.gc.ConservativeGC.runLocked!(gc.impl.conservative.gc.ConservativeGC.mallocNoSync(ulong, uint, ref ulong, const(TypeInfo)), gc.impl.conservative.gc.mallocTime, gc.impl.conservative.gc.numMallocs, ulong, uint, ulong, const(TypeInfo)).runLocked(ref ulong, ref uint, ref ulong, ref const(TypeInfo)) ()

No symbol table info available.
#2  0x00bed103 in 
gc.impl.conservative.gc.ConservativeGC.qalloc(ulong, uint, 
const(TypeInfo)) ()

No symbol table info available.
#3  0x00b9c6e3 in gc_qalloc ()
No symbol table info available.
#4  0x00b96140 in core.memory.GC.qalloc(ulong, uint, 
const(TypeInfo)) ()

No symbol table info available.
#5  0x0093fdce in 
std.array.Appender!(immutable(char)[]).Appender.ensureAddable(ulong) (this=..., nelems=761)
at 
/home/search-master/dmd2/freebsd/bin64/../../src/phobos/std/array.d:2929

len = 394
reqlen = 1155
newlen = 1155
u = 0
overflow = false
nbytes = 1155
bi = {base = 0x2b1, size = 140737488337376, attr = 
4294949280}
#6  0x00942c0f in 
std.array.Appender!(immutable(char)[]).Appender.put!(immutable(char)[]).put(immutable(char)[]).bigDataFun(ulong) (

this=0x7fffb9f0, extra=761)
at 
/home/search-master/dmd2/freebsd/bin64/../../src/phobos/std/array.d:3023

No locals.
#7  0x00942b55 in 
std.array.Appender!(immutable(char)[]).Appender.put!(immutable(char)[]).put(immutable(char)[]) (this=...,

---Type  to continue, or q  to quit---
 at 
/home/search-master/dmd2/freebsd/bin64/../../src/phobos/std/array.d:3026

bigData = "'"
len = 760
newlen = 34799909888
#8  0x0093e80a in hotel.Hotel.generateSql(int) (this=..., 
destinationId=5743) at source/hotel.d:216

sqls = {_data = 0x81d5ca6c0}
sql = {_data = 0x81d5ca6e0}
childSqls = {_data = 0x81d5ca700}
#9  0x009194c9 in app.getHotels().__foreachbody1(ref 
destination.Destination).__foreachbody2(ref hotel.Hotel) 
(this=0x7fffd2a0,

__applyArg0=...) at source/app.d:211
hotel = {provider_ref = 121475, destinationId = 7931, 
resortId = 11313, transfer = 0, roomTypes = {{rooms = {{roomType 
= 0x81a351188,
  hotelId = 121475, roomId = 5369802, beds = 
2, extrabeds = 0, meals = 0x0}}, roomType = "Twin/Double room",
roomTypeId = 21}, {rooms = {{roomType = 
0x81a35c108, hotelId = 121475, roomId = 5761375, beds = 2, 
extrabeds = 0,
  meals = 0x0}}, roomType = "Double room 
Queen bed", roomTypeId = 2651}}, reviews = 0x0, distance = 
nan(0xc),
  type = "Hotel", name = "Best Western Carriage House Inn 
and Suites", addr_1 = "1936 Highway 45 Bypass", addr_2 = 0x0,
  zip_code = "38305", city = "Jackson", state = "TN", 
country = "United States", country_code = "US",
  address = "1936 Highway 45 Bypass  38305 Jackson TN 
United States",
  mapurl = 
"http://www.sunhotels.net/GoogleMaps/showGoogleMap.asp?hotelId=121475=en;,
  headline = "With a stay at Best Western Carriage House 
Inn & Suites in Jackson, you'll be minutes from Casey Jones 
Village and close to Old Hickory Mall",
  

how to build project with locally compiled phobos

2017-09-23 Thread Mengu via Digitalmars-d-learn

hi all

i've successfully compiled phobos master with gmake on freebsd. 
(make fails, i've no clue at all as to why)


how do i compile my project now against my local phobos with dub? 
with plain dmd?


i tried (in dub.sdl):
- full path to new libphobos.so with -defaultlib to dflags
- full path to new libphobos.so to lflags

i checked with ldd and saw the original libphobos.so was used. my 
current workaround is copying mine to /usr/lib.


thanks in advanced.


Re: [FreeBSD] 0x000000000061d8cd in rt.aaA.Impl.findSlotLookup(ulong, const(void*), const(TypeInfo)) inout ()

2017-09-23 Thread Mengu via Digitalmars-d-learn
On Saturday, 23 September 2017 at 11:23:26 UTC, Nicholas Wilson 
wrote:

On Saturday, 23 September 2017 at 08:45:00 UTC, Mengu wrote:

[...]


So it fails:
trying to find if an element exists in an AA
in a regex
invoked as a callback from curl
inside a parallel foreach.

Interesting that it just straight up core dumps, usually you'll 
get an exception.
see 
https://forum.dlang.org/thread/rrpmgzqqtkqgeicjd...@forum.dlang.org for a recent discussion. What it the stack limit? 35 frames is a fair bit, could be a stack overflow. What is the return code? this will probably give you some info as to what happened.


Only other thing I can suggest is try linking against a debug 
phobos to see if you can get some more diagnostics.


hi nicholas

the latter is what i did. i re-compiled phobos master and used 
it. this time everything worked as expected.


btw, regex match happens in HTTP.Impl.onReceiveHeader. i think it 
no longer had access to that header to parse.


[FreeBSD] 0x000000000061d8cd in rt.aaA.Impl.findSlotLookup(ulong, const(void*), const(TypeInfo)) inout ()

2017-09-23 Thread Mengu via Digitalmars-d-learn

hello everyone

i have a small program that parses an xml file, holding a list 
with 13610 elements. after making the list, it iterates over the 
list (paralele), goes to a web site and grabs the related data 
for that element.


it works perfect for the first 1K element in the list. after that 
i get a very annoying segmentation fault. no exceptions, nothing. 
it just dumps a core file. below is the full stack trace. (also 
available at https://pastebin.com/PT1R5D7S)


i appreciate any help.

my dmd info:
DMD64 D Compiler v2.076.0-dirty
Copyright (c) 1999-2017 by Digital Mars written by Walter Bright

my os info:
FreeBSD metropol.com 11.1-RELEASE FreeBSD 11.1-RELEASE #0 
r321309: Fri Jul 21 02:08:28 UTC 2017 
r...@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64




(gdb) bt full
#0  0x0061d8cd in rt.aaA.Impl.findSlotLookup(ulong, 
const(void*), const(TypeInfo)) inout ()

No symbol table info available.
#1  0x005dcb21 in _aaInX ()
No symbol table info available.
#2  0x0067fef0 in 
std.regex.internal.ir.getMatcher(std.uni.InversionList!(std.uni.GcPolicy).InversionList) ()

No symbol table info available.
#3  0x00677a26 in 
std.regex.internal.parser.CodeGen.charsetToIr(std.uni.InversionList!(std.uni.GcPolicy).InversionList) ()

No symbol table info available.
#4  0x00655f47 in 
std.regex.internal.parser.Parser!(immutable(char)[], 
std.regex.internal.parser.CodeGen).Parser.parseEscape() ()

No symbol table info available.
#5  0x00654680 in 
std.regex.internal.parser.Parser!(immutable(char)[], 
std.regex.internal.parser.CodeGen).Parser.parseAtom() ()

No symbol table info available.
#6  0x006541e3 in 
std.regex.internal.parser.Parser!(immutable(char)[], 
std.regex.internal.parser.CodeGen).Parser.parseRegex() ()

No symbol table info available.
#7  0x006570f0 in 
std.regex.internal.parser.Parser!(immutable(char)[], 
std.regex.internal.parser.CodeGen).Parser.this!(const(char)[]).this(immutable(char)[], const(char)[]) ()

No symbol table info available.
#8  0x00652fb1 in 
std.regex.regexImpl!(immutable(char)[]).regexImpl(immutable(char)[], const(char)[]) ()

No symbol table info available.
#9  0x00636af3 in 
std.functional.memoize!(std.regex.regexImpl!(immutable(char)[]).regexImpl(immutable(char)[], const(char)[]), 8).memoize(immutable(char)[], const(char)[]) ()

No symbol table info available.
#10 0x005fd617 in 
std.regex.regex!(immutable(char)[]).regex(immutable(char)[][], 
const(char)[]) ()

No symbol table info available.
#11 0x005fd472 in 
std.regex.regex!(immutable(char)[]).regex(immutable(char)[], 
const(char)[]) ()

No symbol table info available.
#12 0x005f7bb7 in 
std.net.curl.HTTP.Impl.onReceiveHeader(void(const(char[]), 
const(char[])) delegate).__lambda2(const(char[])) ()

No symbol table info available.
#13 0x005fb98a in 
std.net.curl.Curl.onReceiveHeader(void(const(char[])) 
delegate).__lambda2(const(char[])) ()

No symbol table info available.
#14 0x005fbdce in 
std.net.curl.Curl._receiveHeaderCallback(const(char*), ulong, 
ulong, void*) ()

No symbol table info available.
#15 0x00080681838b in ?? () from /usr/local/lib/libcurl.so
No symbol table info available.
#16 0x000806816c95 in ?? () from /usr/local/lib/libcurl.so
No symbol table info available.
#17 0x00080683119c in ?? () from /usr/local/lib/libcurl.so
No symbol table info available.
#18 0x00080683bd94 in ?? () from /usr/local/lib/libcurl.so
No symbol table info available.
---Type  to continue, or q  to quit---
#19 0x00080683b56b in curl_multi_perform () from 
/usr/local/lib/libcurl.so

No symbol table info available.
#20 0x0008068334b0 in curl_easy_perform () from 
/usr/local/lib/libcurl.so

No symbol table info available.
#21 0x005fb77c in 
std.net.curl.Curl.perform(std.typecons.Flag!("throwOnError").Flag) ()

No symbol table info available.
#22 0x005f8a20 in 
std.net.curl.HTTP.perform(std.typecons.Flag!("throwOnError").Flag) ()

No symbol table info available.
#23 0x005cff60 in 
provider.SunHotels.getHotels(destination.Destination) 
(this=0x80097e000, destination=...) at source/provider.d:226

__closptr = 0x800980800
filePath = 
"/usr/home/search-master/search-api/ext/data/hotels/6593.xml"

__dollar = 7
hotelsPath = "http://some-domain.com;
data = {ptr = 0x80097f240}
http = {p = {_refCounted = {_store = 0x805a14000}}}
postData = "some=postData"
__flag = 2
__EAX = 0x8002901170
__exception_object = 0x0
__EAX = 0x8002901170
__EDX = -851895465
__handler = 0
__exception_object = 0x801f12540
#24 0x0059cdb2 in 
app.getDestinations().__foreachbody1(ref destination.Destination) 
(this=0x7fffe850, __applyArg0=...) at source/app.d:164
destination = {destinationId = 6593, destinationCode = 
"GRR", destinationCode_1 = 0x0, 

Re: How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread Mengu via Digitalmars-d-learn
On Monday, 14 August 2017 at 13:48:36 UTC, Dominikus Dittes 
Scherkl wrote:

if I use fixed-type functions, I can do the following:

uint foo(uint n)
{
   ++n; // modify n - as this function has received a copy of 
n, this is always possible

   return 42;
}

uint bar(const uint n)
{
   assert(foo(n)==42);
   return 17;
}

void main()
{
   bar(3);
}


But if I try the same with a template parameter, it doesn't 
work:


import std.traits; // Unqual

uint foo(T)(Unqual!T n) // first try
{
   ++n; // modify should be possible
   return 42;
}

uint foo2(T)(T n) // second try
{
   ++n; // modify fails, as T is const
   return 42;
}

uint bar(T)(const T n)
{
   assert(foo(n)==42u); // cannot deduce arguments - why?!?
   assert(foo2(n)==42u); // here it can deduce the arguments, 
but the function cannot modify n

   return 17;
}

void main()
{
   bar(3);
}

Any ideas what I need to do to make this work?


hi dominikus

you can call functions as func(arg) when compiler can infer the 
types for your functions but when it's not you'll get an "cannot 
deduce arguments" error.


when you call bar template function, you won't be able to modify 
the argument n. ++n will not work and will throw an error at 
compile time.


import std.traits : Unqual;
import std.stdio : writeln;

uint normalFoo(int n) {
++n;
return n;
}

uint constNormalFoo(const int n) {
++n; // will raise error
return n;
}

uint templateFoo(T)(Unqual!T n) {
++n;
return n;
}

uint constTemplateFoo(T)(const Unqual!T n) {
++n; // will raise error
return n;
}

void main() {
writeln(normalFoo(42));
// writeln(constNormalFoo(42));
writeln(templateFoo!int(42));
// writeln(constTemplateFoo!int(42));

}

more info is available at:


Re: gtkD load images

2017-08-03 Thread Mengu via Digitalmars-d-learn

On Thursday, 3 August 2017 at 03:59:40 UTC, Johnson Jones wrote:
How can be use gtkD to load images, I assume through gdkpixbuf? 
While I am getting errors loading images through glade's image:


(test.exe:8188): Gtk-WARNING **: Could not load 
image 'a.jpg': Couldn't recognize the image file format for 
file 'test\a.jpg'


(loads fine in glade)

which needs to be resolved, I'd also like to be able to use 
gdkpixbuf to load images programmatically. There seems to be no 
demos on the gtkD github page that deals with image loading.


I've tried to do something like

import gtkc.gdkpixbuf;
auto x = c_gdk_pixbuf_get_formats().data;

but I don't know how to interpret x.

Also something like

import gtkc.gdkpixbuf;
void* x;
auto p = c_gdk_pixbuf_get_formats();
for(int i = 0; i < 10; i++)
{   
x = p.data;
p = p.next;
}

which doesn't offer any help.


Aside: How can we call the gtk functions directly using gtkD? 
Seems it uses stuff like


Linker.link(gdk_pixbuf_get_formats, "gdk_pixbuf_get_formats", 
LIBRARY_GDKPIXBUF);


It does seem to alias to these function but something is off 
and I'm not sure what.


hi

- is the gtk.Image class not working for you? 
https://api.gtkd.org/gtkd/gtk/Image.html


- there's also a gdkpixbuf.Pixbuf that you can use. 
https://api.gtkd.org/gtkd/gdkpixbuf/Pixbuf.html


- you can import those functions from gdkpixbuf.c.functions.





Re: in a template argument, specify which object member to access?

2016-02-08 Thread Mengu via Digitalmars-d-learn

On Monday, 8 February 2016 at 21:09:47 UTC, cy wrote:
object.member lets me access the member of the object, but what 
if I want to access those members in a generic way, but in a 
different arrangement depending on context? Like if I wanted to 
first follow a tree down, and second priority would be going 
left to right, but then I wanted to first go right, and second 
priority would be going down to up.


[...]


i believe you can use __traits(getMember) there.


Re: in a template argument, specify which object member to access?

2016-02-08 Thread Mengu via Digitalmars-d-learn

On Monday, 8 February 2016 at 22:46:06 UTC, cy wrote:

On Monday, 8 February 2016 at 22:38:45 UTC, Mengu wrote:

i believe you can use __traits(getMember) there.


Great! Should have refreshed before sending that reply...

I wonder if mixin("a."~member) is better or worse than 
__traits(getMember,a,member)...


i think it's a matter of taste and here's how i would do it:

import std.stdio;
import std.array;

struct A {
  string up;
  string down;
  string left;
  string right;
}

string goPlaces(args...)(A a) {
  string[] result;
  foreach (arg; args) {
result ~= __traits(getMember, a, arg);
  }
  return "go " ~ result.join(" then go ");
}

void main() {
  A a = {"north", "south", "east", "west"};
  writeln(goPlaces!("up", "down", "left")(a));
  writeln(goPlaces!("down", "right", "left", "up")(a));
}

// outputs
// go north then go south then go east
// go south then go west then go east then go north


Re: OT: why do people use python when it is slow?

2015-10-18 Thread Mengu via Digitalmars-d-learn
On Sunday, 18 October 2015 at 13:29:50 UTC, Ola Fosheim Grøstad 
wrote:

On Sunday, 18 October 2015 at 12:50:43 UTC, Namespace wrote:
On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc 
wrote:

https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow
Andrei suggested posting more widely.


Maybe also interesting: 
https://docs.google.com/presentation/d/1LO_WI3N-3p2Wp9PDWyv5B6EGFZ8XTOTNJ7Hd40WOUHo/mobilepresent?pli=1=id.g70b0035b2_1_168


What I got out of that is that someone at Mozilla were writing 
a push service (stateful connections, which more demanding than 
regular http) and found that jitted Python was more suitable 
than Go for productivity reasons. Then they speculate that 
their own Rust will be better suited than Go for such services 
in the future, apparently not yet.



To the poster further up in the thread: turns out that 
reddit.com is implemented in Python and a little bit of C: 
https://github.com/reddit/reddit


So there we have it. Python gives higher productive at the cost 
of efficiency, but does not have a significant impact on 
effectiveness, for regular web services that are built to scale.


that's the pylons guy. he also has many python libraries for web 
development. reddit is built with pylons btw and pylons is now 
pyramid.


i've seen the presentation and i can't stop thinking how it'd be 
if they had chosen D instead of Go.


Re: OT: why do people use python when it is slow?

2015-10-14 Thread Mengu via Digitalmars-d-learn
On Wednesday, 14 October 2015 at 05:42:12 UTC, Ola Fosheim 
Grøstad wrote:
On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc 
wrote:

https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow
Andrei suggested posting more widely.


That's flaimbait:

«Many really popular websites use Python. But why is that? 
Doesn't it affect the performance of the website?»


No. Really popular websites use pre-generated content / front 
end caches / CDNs or wait for network traffic from distributed 
databases.


really popular portals, news sites? yes. really popular websites? 
nope. like booking.com, airbnb.com, reddit.com are popular 
websites that have many parts which have to be dynamic and 
responsive as hell and they cannot use caching, pre-generated 
content, etc.


using python affect the performance of your website. if you were 
to use ruby or php your web app would be slower than it's python 
version. and python version would be slower than go or d version.


Re: OT: interesting talk by Jane Street technical guy on why they used Ocaml

2015-10-03 Thread Mengu via Digitalmars-d-learn

On Saturday, 3 October 2015 at 01:41:55 UTC, Laeeth Isharc wrote:

https://www.youtube.com/watch?v=hKcOkWzj0_s

a little old but still relevant.  talks about importance of 
brevity and strong types for readability (also avoiding 
boilerplate).  two of the partners there committed to read 
every line of code (originally because they were terrified).  
very hard to code review boilerplate carefully because it is 
just too dull!

 (can't pay people enough!)

[...]


there's also andy smith's talk [0] at dconf 2015 on adapting D, 
titled "hedge fund development case study."


[0] https://www.youtube.com/watch?v=0KBhb0iWsWQ


Re: OT: interesting talk by Jane Street technical guy on why they used Ocaml

2015-10-03 Thread Mengu via Digitalmars-d-learn

On Saturday, 3 October 2015 at 16:33:38 UTC, Laeeth Isharc wrote:

On Saturday, 3 October 2015 at 15:58:38 UTC, Mengu wrote:
On Saturday, 3 October 2015 at 01:41:55 UTC, Laeeth Isharc 
wrote:

https://www.youtube.com/watch?v=hKcOkWzj0_s

a little old but still relevant.  talks about importance of 
brevity and strong types for readability (also avoiding 
boilerplate).  two of the partners there committed to read 
every line of code (originally because they were terrified).  
very hard to code review boilerplate carefully because it is 
just too dull!

 (can't pay people enough!)

[...]


there's also andy smith's talk [0] at dconf 2015 on adapting 
D, titled "hedge fund development case study."


[0] https://www.youtube.com/watch?v=0KBhb0iWsWQ


Thanks!  Funnily enough I rewatched the Jane Street talk 
because of a suggestion made by John Colvin when I was talking 
to Andy and him recently.  It's a good talk by Andy, and I hope 
to build on this with him at Codemesh next month.


The way languages actually get adopted is different from how 
people who are sitting in eg the kind of enterprise environment 
where they are never going to be early adopters imagine.  Hence 
one is much better off focusing efforts on those already 
receptive (and who are looking for a solution to their pain) 
than trying to convert those who are happy with what they have 
or uninterested (possibly rationally so) in exploring new 
things.


Being able to understand the codebase is underrated I think.


i watched this talk by yaron last year when i was looking at 
alternatives for sml. i was taking the programming languages 
course on coursera by dan grossman. ocaml looked like it tooked 
off at the beginning of 2000s but then due to many problems it 
failed to be a mainstream language.


imho, D will never take off like go or rust because people who 
adopted these languages are mostly python and ruby developers. D 
has an incredibly creative and helpful community yet our 
community is not as enthusiastic as go's and rust's community. 
phobos is extremely a great library yet not very welcoming and 
feels overly complicated. we should reduce the amount of WTFs 
when reading the phobos source and docs.


Re: endsWith - for a string vs an array of strings

2015-01-11 Thread Mengu via Digitalmars-d-learn

On Saturday, 10 January 2015 at 23:32:47 UTC, bearophile wrote:

Laeeth Isharc:

In D there is a feature that allows a function to accept both 
an array of items and items,


yes - it is funny there is not an overloading that accepts 
arrays


I meant this D feature:


void foo(T)(T[] items...) {
import std.stdio;
items.writeln;
}
void main() {
foo(red, green, blue);
foo([red, green, blue]);
auto a = [red, green, blue];
foo(a);
}


Bye,
bearophile


for the curious, expanding tuples and typetuples on ali's book is 
explained at 
http://ddili.org/ders/d.en/tuples.html#ix_tuples..expand and at 
http://ddili.org/ders/d.en/tuples.html#ix_tuples.TypeTuple, 
std.typetuple.


Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread Mengu via Digitalmars-d-learn

On Thursday, 8 January 2015 at 11:29:30 UTC, Laeeth Isharc wrote:


this conversation is so funny: well what's wrong with this . 
It's a keyword...

Aa Ha ha ha ha , rol.
Seriously, is it so complicated to use a D editor ? I mean 
with syntax color...


Man afraid to ask stoopid questions stays stoopid.  And 
compiler error message far from informative.
Not everyone is very visually oriented, and sometimes vi is 
quicker.


don't worry about it. use whatever you're comfortable with.


Re: Learning D for a non computer science background person : pre-requisite knowledge?

2014-12-05 Thread Mengu via Digitalmars-d-learn
On Wednesday, 3 December 2014 at 02:41:16 UTC, Shriramana Sharma 
via Digitalmars-d-learn wrote:

On Tue, Dec 2, 2014 at 10:45 PM, Mayuresh Kathe via
Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:
Okay, if that is the case, I'll dive into Mr. Alexandrescu's 
book as soon as

I get my copy.
BTW, how come all of you address him as Andrei?


Heh -- possibly you haven't interacted on international 
technical
mailing lists like this. For us (you and me) in India we are 
used to
employ/expect such honorifics, and in fact it would be 
considered
somewhat disrespectful if we didn't, but in my early days 
interacting

with people from western countries on the net, I was actually
discouraged from using Mr because it made people feel old! 
:-)


FWIW while we're talking honorifics, he's *Dr* Alexandrescu as 
in Ph D

doc. :-) [I'm one too, but you won't find me having mentioned it
anywhere earlier! :-) That's informal.]

Re Andrei's book versus Ali's, the latter is a more starting 
from the

basics approach whereas Andrei's book is more targeted at people
coming from other languages. (This is a judgment I read 
somewhere --

perhaps on this forum? -- and which I agree with, sorta.)


yes, you are totally right. Ali's book is aiming at teaching D 
language to complete beginners where Andrei's book is aiming at 
teaching D language to people who are already programmers.


Re: Disabling SSL Verification on std.net.curl

2014-05-16 Thread Mengu via Digitalmars-d-learn

On Friday, 16 May 2014 at 04:58:47 UTC, Jack wrote:
A follow up from : 
http://forum.dlang.org/thread/nsdomtdbqqlylrmgo...@forum.dlang.org


I discovered that it was not a C::B issue as I already compiled 
it with Xamarin Studio and it was still spewing out the error:


std.net.curl.CurlException@std\net\curl.d(3592): problem with 
the SSL CA cert (path? access rights?) on handle 22D3D68


And since I am only using the program by myself for personal 
things, I was thinking of disabling SSL Verification to stop it 
from complaining about the cert.


So how do I do it?


hi Jack

curl has an option called SSL_VERIFYPEER which is supported by 
etc.c.curl: CurlOption.


you can simply do the following:

import std.stdio;
import etc.c.curl : CurlOption;
import std.net.curl;

void main()
{
  auto conn = HTTP();
  conn.handle.set(CurlOption.ssl_verifypeer, 0);
  writeln(get(https://dlang.org/;, conn));
}


if you set the option to 1 you will receive this error: 
std.net.curl.CurlException@std/net/curl.d(3592): Peer certificate 
cannot be authenticated with given CA certificates on handle 
7F908C01DC00


Re: D Newbie Trying to Use D with Major C Libraries

2014-05-16 Thread Mengu via Digitalmars-d-learn

On Friday, 16 May 2014 at 09:44:11 UTC, bearophile wrote:

John Colvin:


Any plans to get any preprocessor stuff working?


Do you mean in D?

Bye,
bearophile


i think he means in dstep.


Re: TKD AddProtocolCommand example

2014-05-15 Thread Mengu via Digitalmars-d-learn

On Thursday, 15 May 2014 at 17:30:22 UTC, Gary Willoughby wrote:

On Wednesday, 14 May 2014 at 21:23:02 UTC, DaveG wrote:
tkd\window\window.d(426): Error: undefined identifier 
CommandCallback


Added the missing import and now all works fine. Fixed in 
v1.0.5-beta. Any more issues open them up in github and i'll 
deal with them there. :)


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


i just was about to send a PR :(


Re: TKD set focus on window?

2014-05-14 Thread Mengu via Digitalmars-d-learn

On Wednesday, 14 May 2014 at 17:08:21 UTC, Joakim wrote:

Hi,

Quick question regarding TKD (tkinter):

Is there a way to set focus on the application window 
automatically on run? I'm on Mac OS X if that's of any 
importance.


I have tried to grep the documentation but I can't find 
anything relevant.


Thanks!


it seems the UiElement class has a focus(bool) method: 
https://github.com/nomad-software/tkd/blob/master/source/tkd/element/uielement.d#L699-L711. 
so it seems it's kind of possible to do window.focus(true).




Re: How to use the std.process?

2014-05-13 Thread Mengu via Digitalmars-d-learn

On Tuesday, 13 May 2014 at 08:56:43 UTC, FrankLike wrote:

I want to start the process by std.process.

module main;
import std.process,std.stdio;
void main()
{
string url = http://dlang.org/;;
	executeShell(escapeShellCommand(wget, url, -O, 
dlang-index.html));

executeShell(iexplore localhost:8080);
}

But not open 'IE'. Why?

Thank you.


does it work when you run iexplore localhost:8000 in command
line? is path to iexplore in your windows path?


Re: How to use the std.process?

2014-05-13 Thread Mengu via Digitalmars-d-learn

On Tuesday, 13 May 2014 at 10:48:06 UTC, FrankLike wrote:



does it work when you run iexplore localhost:8000 in command
line? is path to iexplore in your windows path?


Ok,I get the answer by myself.

module main;
import std.process,std.stdio;
void main()
{
	//spawnProcess(C:\\Program Files (x86)\\Internet 
Explorer\\iexplore);
	spawnProcess([C:\\Program Files (x86)\\Internet 
Explorer\\iexplore, http://localhost:8080; ]);

}

:-D

Frank


that is actually what i meant by is path to iexplore in your 
windows path? :)


Re: Need help with movement from C to D

2014-05-08 Thread Mengu via Digitalmars-d-learn
On Tuesday, 6 May 2014 at 15:13:41 UTC, Artur Skawina via 
Digitalmars-d-learn wrote:

On 05/06/14 16:45, via Digitalmars-d-learn wrote:
On Tuesday, 6 May 2014 at 14:25:01 UTC, Artur Skawina via 
Digitalmars-d-learn wrote:
I'm not sure why you'd want to wrap the .offsetof expression 
in

a template, but it can easily be done like this:

   enum offsetOf(alias A, string S) = 
mixin(A.~S~.offsetof);


Great, that's even shorter.

Somehow I was fixated on converting the symbol to a string 
first, but of course the name is directly available in the 
mixin:


enum offsetof(alias typenfield) = 
mixin(typenfield.offsetof);


I didn't realize that worked, but it does. So...

   enum offsetOf(alias A) = A.offsetof;


But I have no idea why anybody would want to wrap this trivial
expression like that.

And, I have no idea if the, hmm, /unconventional/ D offsetof 
semantics
are in the bugzilla. It's not really a bug, but a design 
mistake...


artur


just out of curiousity, why an alias is used there?


Re: strange error with std.net.curl

2014-05-07 Thread Mengu via Digitalmars-d-learn

On Sunday, 4 May 2014 at 16:40:08 UTC, Suliman wrote:

I am trying to compile next code:

import std.net.curl;
import std.stdio;

void main()
{
writeln(get(https://google.com/;));
}

and got next error 
http://www.everfall.com/paste/id.php?y37dr6qmu54h


this is related to verifying certificates. see 
http://forum.dlang.org/thread/mailman.357.1384163617.9546.digitalmar...@puremagic.com