On Friday, 11 July 2014 at 14:48:26 UTC, H. S. Teoh via
Digitalmars-d-learn wrote:
On Fri, Jul 11, 2014 at 10:23:58AM -0300, Ary Borenszweig via
Digitalmars-d-learn wrote:
On 7/11/14, 4:46 AM, bearophile wrote:
pgtkda:
How can i get the number of items which are currently hold
in a
DList?
How can i get all folders from a given path?
On Tuesday, 15 July 2014 at 08:31:10 UTC, pgtkda wrote:
How can i get all folders from a given path?
If I understood you correctly:
http://dlang.org/phobos/std_file.html#.dirEntries
On Tuesday, 15 July 2014 at 08:38:30 UTC, sigod wrote:
On Tuesday, 15 July 2014 at 08:31:10 UTC, pgtkda wrote:
How can i get all folders from a given path?
If I understood you correctly:
http://dlang.org/phobos/std_file.html#.dirEntries
Thanks, that's exactly what i was looking for.
On Monday, 14 July 2014 at 21:22:12 UTC, Jason King wrote:
My idea is to use (at least test) DMDScript for server side JS.
I don't mean to sound like a D-hater here, but V8 has had about
2 years more work on it than DMDScript. At one time they were.
IIRC, quite close performance-wise but
How can i read the whole file if i use this:
File(C:\\Users\\text\\Desktop\\test.csv, r);
On Tuesday, 15 July 2014 at 02:49:56 UTC, WhatMeWorry wrote:
Sorry if this is an incredibly naive question.
I prefer to pragmatically pause my programs periodically so
that I can peruse output statements. Ideally, I'd like to
continue by just hitting any old key. My feeble attempt below
pgtkda:
How can i read the whole file if i use this:
File(C:\\Users\\text\\Desktop\\test.csv, r);
In std.file there are two functions to read a file or read a text
file, named read and readText.
Bye,
bearophile
On Fri, 11 Jul 2014 07:46:37 -0700
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:
On Fri, Jul 11, 2014 at 10:23:58AM -0300, Ary Borenszweig via
Digitalmars-d-learn wrote:
On 7/11/14, 4:46 AM, bearophile wrote:
pgtkda:
How can i get the number of items which
Hi,
I'd like to use immutable data, but instead of a one time
constructor, I would like to `build` the data lazily, by setting
its fields separately.
In java version of protocol-buffer, there is a pattern for this
mechanism:
1. Every data class in protobuf is immutable.
2. Each data class
On Tuesday, 15 July 2014 at 05:26:57 UTC, Philippe Sigaud via
Digitalmars-d-learn wrote:
@property allows you to call a function without the parenthesis
(), to imitate a field in a struct or class.
Ah, ok. That means without @property I would need to write
defaultInit!T() instead of
On Monday, 14 July 2014 at 11:43:01 UTC, Philippe Sigaud via
Digitalmars-d-learn wrote:
You can try Pegged, a parser generator that works at
compile-time
(both the generator and the generated parser).
I did, and I got it to work. Unfortunately, the code used to in
the CTFE is left in the
How Can I Iterate through JSON Subkeys using std.json? Or Do I
Have To Use An External Library For that
Hi :)
I made this function to inverse the bytes in intger or T
(possible) type...
int reverseBytes(T)(T val)
{
int retVal = 0;
static if(is(T == string))
retVal = to!int(val);
return (retVal 0x00FF) 24 |
(retVal 0xFF00) 8
Alexandre:
return (retVal 0x00FF) 24 |
(retVal 0xFF00) 8 |
(retVal 0x00FF) 8 |
(retVal 0xFF00) 24;
See also core.bitop.bswap.
Bye,
bearophile
I found another way to do this, namely first create a class that
is mutable, then cast it to an immutable object before using it.
```d
class A {
int a;
B b;
this(int a, int b)
{
this.a = a;
this.b = new B(b);
}
}
class B
Thanks, but, when I convert I recive a 'c' in the front of my
number...
uint reverseBytes(uint val)
{
import core.bitop : bitswap;
return bitswap(val);
}
//...
writefln(%x, reverseBytes(0x00402030));
//...
// output: c040200
On Tuesday, 15 July 2014 at 12:16:26 UTC,
Alexandre:
Thanks, but, when I convert I recive a 'c' in the front of my
number...
This shows it inverts all bits, not just the four byte positions.
I don't understand:
import core.bitop: bitswap;
uint reverseBytes(in uint val) pure nothrow @safe @nogc {
return val.bitswap;
}
void
Something is wrong between our communication...
I am wanting to do something better to order the bytes, for this
my code...
https://gist.github.com/bencz/3576dfc8a217a34c05a9
For example, in that case:
injectData(image[0x207], x30204000);
It's more simple to use something like:
On 07/15/2014 04:56 AM, Alexandre wrote:
retVal = to!int(val);
std.conv.ConvException@C:\D\dmd2\src\phobos\std\conv.d(1968): Unexpected
'@' when converting from type string to type int
That means to!int failed because 'val' contained a '@' character in it:
import std.conv;
void
On 07/15/2014 05:20 AM, Puming wrote:
I found another way to do this, namely first create a class that is
mutable, then cast it to an immutable object before using it.
```d
class A {
int a;
B b;
this(int a, int b)
{
this.a = a;
this.b = new B(b);
}
}
On Tuesday, 15 July 2014 at 14:05:14 UTC, Alexandre wrote:
Strange..., why '@' ?
because x40 == @
On Tuesday, 15 July 2014 at 12:24:48 UTC, Alexandre wrote:
Thanks, but, when I convert I recive a 'c' in the front of my
number...
uint reverseBytes(uint val)
{
import core.bitop : bitswap;
return bitswap(val);
}
You confused bswap with bitswap.
The former reverses bytes,
Strange..., why '@' ?
PS: Ali Çehreli, thanks for your book, your book is wonderful!!!
On Tuesday, 15 July 2014 at 13:49:51 UTC, Ali Çehreli wrote:
On 07/15/2014 04:56 AM, Alexandre wrote:
retVal = to!int(val);
std.conv.ConvException@C:\D\dmd2\src\phobos\std\conv.d(1968):
Alexandre:
RefCounted!(DWORD) addr;
I think RefCounted is for advanced usages in D :-)
template Wrap(T)
{
struct Wrap
{
T val;
this(T val){val = val;}
}
}
Simpler:
struct Wrap(T) {
T val;
this(T val_) { this.val =
Oh!
I used the RefCounted because this:
The proposed C++ shared_ptr, which implements ref counting,
suffers from all these faults. I haven't seen a heads up
benchmark of shared_ptr vs mark/sweep, but I wouldn't be
surprised if shared_ptr turned out to be a significant loser in
terms of both
I have this struct:
enum AddrType { Abs, RVA, Rel };
struct Address
{
shared_ptrDWORD addr;
AddrType type;
Address(): type(Abs) {}
Address(DWORD addr, AddrType type):
addr(shared_ptrDWORD(new DWORD(addr))), type(type) {}
Address(shared_ptrDWORD addr, AddrType type):
Alexandre:
as rc is better for managing scarce resources like file handles.
File instances are ref counted in D. Is this useful for you?
Bye,
bearophile
I did, and I got it to work. Unfortunately, the code used to in the CTFE is
left in the final executable even though it is not used at runtime. So now
the question is, is there away to get rid of the excess baggage?
Not that I know of. Once code is injected, it's compiled into the executable.
On Tuesday, 15 July 2014 at 13:59:24 UTC, Ali Çehreli wrote:
On 07/15/2014 05:20 AM, Puming wrote:
I found another way to do this, namely first create a class
that is
mutable, then cast it to an immutable object before using it.
```d
class A {
int a;
B b;
this(int a, int b)
{
Yes yes, I will use the ref... is more safer!
I will try to re-create my logic...
btw, how is the best way to reinterpret this ??:
mapstring, Address syms;
and:
vectorpairDWORD, Address values;
vectorpairDWORD, shared_ptrDWORD addrs;
On Tuesday, 15 July 2014 at 14:55:36 UTC, bearophile wrote:
Alexandre:
mapstring, Address syms;
If you don't need the key ordering then use a built-in
associative array:
Address[string] syms;
Otherwise use a RedBlackTree from std.container.
vectorpairDWORD, Address values;
vectorpairDWORD, shared_ptrDWORD addrs;
Tuple!(DWORD, Address)[]
struct Subscription {
const Object handle;
private immutable size_t index;
@disable this();
private this(Object o, size_t i) {
handle = o;
index = i;
}
}
I'd like this to be constructed with a handle to some object, and
Since you access a field through `a` instance, this is usually
done by loading the instance address into some register and
reading from a location at a certain offset from that register
mov esi, [ebp-4] # the instance address
mov eax, [esi+8] # first field
...
mov [ebp-4], 0 # clear stack
On 07/15/2014 09:39 AM, Anonymous wrote:
struct Subscription {
const Object handle;
private immutable size_t index;
@disable this();
private this(Object o, size_t i) {
handle = o;
index = i;
}
}
I'd like this to be constructed with a handle
On Tuesday, 15 July 2014 at 15:48:10 UTC, Puming wrote:
wow, that's interesting :-) Is it the idiomatic approach to
initiate immutable objects lazily? Or do people use data class
with immutable fields and generate a companion builder class at
compile time?
There's no real idiomatic approach,
On 07/15/2014 07:40 AM, Alexandre wrote:
I have this struct:
I think many short discussion threads are more efficient than a single
long thread. Many different C++ and D concepts are making this thread
difficult to follow for me. :)
Ali
On Tuesday, 15 July 2014 at 05:26:57 UTC, Philippe Sigaud via
Digitalmars-d-learn wrote:
@property allows you to call a function without the parenthesis
(), to
imitate a field in a struct or class.
That was the original idea, but today the situation is that for
all argument-less method calls
Nordlöw:
Could someone elaborate shortly which cases this means?
All cases where you really can't live without it :-) It's like a
cast(.
Bye,
bearophile
On Tuesday, 15 July 2014 at 00:03:04 UTC, bearophile wrote:
to avoid using @trusted in most cases.
Could someone elaborate shortly which cases this means?
Consider this:
import std.stdio, std.regex, std.array, std.algorithms ;
void main(string args[])
{
string[] greetings = [hello, hallo, hoi, salut];
regex r = regex(hello, g);
for(short i = 0; i greetings.count(); i++)
{
auto m = match(greetings[i], r);
}
}
To the best of my knowledge,
On Tue, Jul 15, 2014 at 08:18:55PM +, seany via Digitalmars-d-learn wrote:
Consider this:
import std.stdio, std.regex, std.array, std.algorithms ;
void main(string args[])
{
string[] greetings = [hello, hallo, hoi, salut];
regex r = regex(hello, g);
for(short i = 0; i
On Tuesday, 15 July 2014 at 20:18:58 UTC, seany wrote:
Consider this:
import std.stdio, std.regex, std.array, std.algorithms ;
void main(string args[])
{
string[] greetings = [hello, hallo, hoi, salut];
regex r = regex(hello, g);
for(short i = 0; i greetings.count(); i++)
{
auto m =
To make a long story short:
Is there any math library with e.g. mean, std, polynomial
fitting, ...?
On Tuesday, 15 July 2014 at 10:22:52 UTC, rumbu wrote:
getch() reads any key and continues;
On Windows you can pipe you executable with the more command
to pause after each page: your.exe | more
Don't forget that getch() is also Windows-specific.
On Tuesday, 15 July 2014 at 02:49:56 UTC, WhatMeWorry wrote:
Is there a way to continue with any old key press? or just the
enter key?
Yeah. It is more complex than you'd think but my terminal library
can do it:
https://github.com/adamdruppe/arsd/blob/master/terminal.d
Example usage:
I don't know about Windows, but on Linux, you can just press
ctrl-s and
ctrl-q to pause/resume the console. (This is a Linux terminal
function,
not specific to D.)
In the Windows shell, the pause key will halt a program and
return will resume it.
On Tuesday, 15 July 2014 at 20:46:32 UTC, Martijn Pot wrote:
To make a long story short:
Is there any math library with e.g. mean, std, polynomial
fitting, ...?
https://github.com/kyllingstad/scid
https://github.com/dsimcha/dstats
On Tuesday, 15 July 2014 at 18:50:06 UTC, bearophile wrote:
All cases where you really can't live without it :-) It's like
Hmm. I guess I'm gonna have to remove some @trusted tagging then
;)
...and any example where this switch will be usefull ?
Klb:
...and any example where this switch will be usefull ?
I guess it was added to D in the spirit of If you have to ask
what it is, then you don't need to use it.
More seriously, I too would like more documentation about its use
cases.
Bye,
bearophile
On 07/15/2014 04:33 PM, bearophile wrote:
Klb:
...and any example where this switch will be usefull ?
I guess it was added to D in the spirit of If you have to ask what it
is, then you don't need to use it.
More seriously, I too would like more documentation about its use cases.
Bye,
On 07/15/2014 04:56 PM, Ali Çehreli wrote:
char buffer[100];
[...]
char buffer[100] = void;
Before others point out, those are in C syntax by mistake. :) They
should preferably be:
char[100] buffer;
[...]
char[100] buffer = void;
Ali
On Tuesday, 15 July 2014 at 17:09:04 UTC, Meta wrote:
On Tuesday, 15 July 2014 at 15:48:10 UTC, Puming wrote:
wow, that's interesting :-) Is it the idiomatic approach to
initiate immutable objects lazily? Or do people use data class
with immutable fields and generate a companion builder class
On Tuesday, 15 July 2014 at 17:06:14 UTC, Ali Çehreli wrote:
On 07/15/2014 09:39 AM, Anonymous wrote:
struct Subscription {
const Object handle;
private immutable size_t index;
@disable this();
private this(Object o, size_t i) {
handle = o;
index =
On Tuesday, 15 July 2014 at 12:20:57 UTC, Puming wrote:
@property immutable(T) freeze(T)(T obj)
{
return cast(immutable(T))(obj);
}
What is the idiomatic approach to do this in D?
There is a Phobos function std.exception.assumeUnique which
performs this for arrays. According to
I'd like to have a Command class, where their is a name and a
handler field:
```d
class Command
{
string name;
string delegate(string[]) handler;
}
```
this is ok, but sometimes I want the handler also accept a
function (lambdas are init to functions if no capture of outer
scope
On 16/07/2014 3:50 p.m., Puming wrote:
I'd like to have a Command class, where their is a name and a handler
field:
```d
class Command
{
string name;
string delegate(string[]) handler;
}
```
this is ok, but sometimes I want the handler also accept a function
(lambdas are init to
58 matches
Mail list logo