Re: Operator Precedence and Associativity

2013-11-07 Thread Tyro[17]

On 11/6/13, 6:43 AM, Timon Gehr wrote:

On 11/06/2013 04:34 AM, Tyro[17] wrote:

I’m sure the following table is missing a few items but am unclear
what they are. For starters these <>, <>=, >>>, , !<>, !<>=
belong on the table but I’m not sure where. I am also not sure if
these ..., @, # belong there at all. There might be other errors
or missing operators. Request assist to complete correctly.
...


I have some time ago compiled my own table, which can be found here:
http://wiki.dlang.org/Operator_precedence




Thanks. Did not see this earlier. I will compare my list and adjust 
accordingly.


Re: Operator Precedence and Associativity

2013-11-07 Thread Tyro[17]

On 11/5/13, 11:36 PM, Jonathan M Davis wrote:

On Tuesday, November 05, 2013 22:34:49 Tyro[17] wrote:

I’m sure the following table is missing a few items but am unclear
what they are. For starters these <>, <>=, >>>, , !<>, !<>=
belong on the table but I’m not sure where.


I'm not quite sure where they go, but I believe that all of them (save maybe

) are supposed to be deprecated, in which case, it matters a lot less where

they'd go in the table.

- Jonathan M Davis




OK thanks. As for the actual chart, I take it there wasn't anything 
glaringly wrong with what's already in it?


Andrew


Operator Precedence and Associativity

2013-11-05 Thread Tyro[17]

I’m sure the following table is missing a few items but am unclear
what they are. For starters these <>, <>=, >>>, , !<>, !<>=
belong on the table but I’m not sure where. I am also not sure if
these ..., @, # belong there at all. There might be other errors
or missing operators. Request assist to complete correctly.


  Operator Precedence and Associativity Rules in D
———
!   template instantiation
———
=>  lambdaright-to-left
———
()  function call left-to-right
[]  array element
.   member selection
++  post incrementright-to-left
--  post decrement
———
!   logical not   right-to-left
~   bitwise complement
-   unary minus
++  pre increment
--  pre decrement
*   contents of (dereference)
new
ref
in
!in
out
inout
cast()
is
!is
———
^^  power left-to-right
*   multiply
/   divide
%   remainder
———
+   add   left-to-right
-   subtract
———
<<  bitwise left shiftleft-to-right
>>  bitwise right shift
———
<   arithmetic less than  left-to-right
!>= arithmetic not greater than or equal to
>   arithmetic greater than
!<= arithmetic not less than or equal to
<=  arithmetic less than or equal to
!>  arithmetic not greater than
>=  arithmetic greater than or equal to
!<  arithmetic not less than
———
==  arithmetic equal  left-to-right
!=  arithmetic not equal
———
&   bitwise and   left-to-right
———
^   bitwise exclusive or  left-to-right
———
|   bitwise orleft-to-right
———
&&  logical and   left-to-right
———
||  logical orleft-to-right
———
? : conditional expressionright-to-left
———
=   assignment operator   right-to-left
also +=-=*=/=%=
<<=>>=&=^=|=
~=^^=>>>=
———
=>  lambdaleft-to-right
———
,   sequential expression left-to-right
———
..  range separator
———

--

Andrew Edwards

http://www.akeron.co
auto getAddress() {
string location = "@", period = ".";
return ("info" ~ location ~ "afidem" ~ period ~ "org");
}


Re: Address of overloaded functions

2013-07-03 Thread Tyro[17]

On 7/3/13 12:52 PM, Artur Skawina wrote:

import std.stdio;

void foo(int a){ writeln("overload int"); }
void foo(long b){ writeln("overload long"); }

auto pickOverload(alias FP, A...)() @property { typeof(FP(A.init)) function(A) 
fp = &FP; return fp;}

void main()
{
auto b = pickOverload!(foo, long);
b(2);
}


Often I see terse demonstrations of ingenious ways of doing things in 
the language but am at a lost as with regards to under what 
circumstances on would use such a feature. This happens to be one of 
those cases. Could you provide a couple circumstances where this would 
prove useful/handy?



Thanks,

--

Andrew Edwards

http://www.akeron.co
auto getAddress() {
string location = "@", period = ".";
return ("info" ~ location ~ "afidem" ~ period ~ "org");
}


Re: memcpy in D

2013-07-01 Thread Tyro[17]
I'd just like to say thanks for your suggestions and quite complete 
solutions. I particularly liked the alternate implementation presented 
by Marco. I must admit that I did not understand what was happening at 
first.


So just to confirm my understanding: Because the address at memory is 
casted to ushort* in defining base, every iteration of the foreach loop 
advances the pointer two bytes into the array?


Thanks,
Andrew


memcpy in D

2013-06-30 Thread Tyro[17]

What is the equivalent of memcpy

module memcopy;

immutable ADDRESS_BUS_SIZE = 20; // 2^20 address bus
byte memory[1 << ADDRESS_BUS_SIZE];

void main()
{
ushort val = 12345;

for (int i = 0x12340; i < 0x1234A; i+= 2) {
memcpy (&memory[i], &val, sizeof val); // D way???
val++;
}

for (int i = 0x12340; i < 0x1234A; i+= 2) {
memcpy (&val, &memory[i], sizeof val); // D way???
writefln("%x", val);
}
}

achieved in D? I am trying not to use memcpy or any function from the C API.

Thanks,

--

Andrew Edwards

http://www.akeron.co
auto getAddress() {
string location = "@", period = ".";
return ("info" ~ location ~ "afidem" ~ period ~ "org");
}


BigInt not integral type?

2013-06-16 Thread Tyro[17]

The following code:

void main()
{
import std.bigint;
BigInt x, m;
BigInt l = x & m;
}

Result in:
andrew@ace:~$ dmd f
f.d(6): Error: 'x' is not of integral type, it is a BigInt
f.d(6): Error: 'm' is not of integral type, it is a BigInt

I'm sure there is plans to resolve this situation but is there a work 
around I can use in the meantime?


Thanks,
--

Andrew Edwards

http://www.akeron.co
auto getAddress() {
string location = "@", period = ".";
return ("info" ~ location ~ "afidem" ~ period ~ "org");
}


Re: Internationalization vs. Unicode

2013-04-29 Thread Tyro[17]

On 4/27/13 6:37 AM, Jacob Carlborg wrote:

On 2013-04-27 00:09, Tyro[17] wrote:

There are myriad encoding schemes. D natively supports Unicode and
provide functionality via phobos. A byproduct of this is that since
ASCII is a subset of Unicode, it also natively support ASCII. This is a
plus for the language but what of the other encoding schemes? What
library functionality is provided to manipulate or convert between those
encoding schemes and Unicode?

I have a need to convert from CKJ encoding (presently EUC-JP and
Shift-JIS) to Unicode. How do I accomplish this using D/Phobos? Is there
a standalone library that does this? If so, can someone point me to it?
If not, is there planned functionality for inclusion in phobos or am I
doomed to resorting to Java or some other language to accomplish this
task (or at least until I'm educated enough to do it myself)?


Would ICU do the work? If that's the case you can take a look at this:

https://github.com/d-widget-toolkit/com.ibm.icu

I will most likely not compile with the latest version of DMD. Also I
don't know how complete it is.



This might work. Not sure yet. The first thing that caught my eyes is

import java.lang.all;
import java.math.BigInteger;
import java.text.CharacterIterator;
import java.text.ParsePosition;
import java.util.Comparator;
import java.util.Date;

and I was immediately confused. What? We can directly import and use 
Java in D? Let me try this... Oh! No! Not really! We can't. Well, since 
D uses the file system to organize its files, I should be able to find a 
java folder with these classes signatures or the D equivalent somewhere 
in the project folder. No... I don't see one anywhere. Looks like I will 
have to file ICU on my list of things to get educated about. For now I 
will continue to use the Java implementation I've got. Thanks.


Internationalization vs. Unicode

2013-04-26 Thread Tyro[17]
There are myriad encoding schemes. D natively supports Unicode and 
provide functionality via phobos. A byproduct of this is that since 
ASCII is a subset of Unicode, it also natively support ASCII. This is a 
plus for the language but what of the other encoding schemes? What 
library functionality is provided to manipulate or convert between those 
encoding schemes and Unicode?


I have a need to convert from CKJ encoding (presently EUC-JP and 
Shift-JIS) to Unicode. How do I accomplish this using D/Phobos? Is there 
a standalone library that does this? If so, can someone point me to it? 
If not, is there planned functionality for inclusion in phobos or am I 
doomed to resorting to Java or some other language to accomplish this 
task (or at least until I'm educated enough to do it myself)?


Thanks,
Andrew


Re: writeln, UFCS and flip

2013-04-26 Thread Tyro[17]

On 4/26/13 5:09 PM, Tyro[17] wrote:

On 4/26/13 4:15 PM, bearophile wrote:

Tyro[17]:


> While flip2 does:
>
> flip2!foo(a, b, c) === foo(b, a, c)
> flip2!foo(a, b, c, d) === foo(b, a, c, d)

and this rotate


Really? Just swapping the first two arguments and leaving the others at
their place is for a "rotate"?



Actually, by brain was thinking it but my eyes saw something completely
different. You are correct, this what I would expect flip to do. Thanks.


Why flip in the first place?


I don't know, it's the name used in the Haskell Prelude.

Bye,
bearophile




With that clarification, I just have one more question, since flip does 
what is intuitively implied by a reverse function and flip2 does what is 
intuitively implied by a flip function, why not name them as such? 
Understand the Haskell influence and all but, influence notwithstanding, 
this is D so why not designate functions in a manner that intuitively 
imply functionality?


I would expect a flip and flip2 if both accomplish the exact same thing 
but both outperforms the other in certain scenarios thus warranting both 
to be present.


Andrew


Re: writeln, UFCS and flip

2013-04-26 Thread Tyro[17]

On 4/26/13 4:15 PM, bearophile wrote:

Tyro[17]:


> While flip2 does:
>
> flip2!foo(a, b, c) === foo(b, a, c)
> flip2!foo(a, b, c, d) === foo(b, a, c, d)

and this rotate


Really? Just swapping the first two arguments and leaving the others at
their place is for a "rotate"?



Actually, by brain was thinking it but my eyes saw something completely 
different. You are correct, this what I would expect flip to do. Thanks.



Why flip in the first place?


I don't know, it's the name used in the Haskell Prelude.

Bye,
bearophile




Re: writeln, UFCS and flip

2013-04-26 Thread Tyro[17]

On 4/26/13 8:59 AM, bearophile wrote:
> ixid:
>
>> flip2 is the more general and useful function with new functionality
>> so there's no need for what was flip and we should call the new
>> function 'flip'.
>
> I don't agree. Maybe you are missing something.
>
> I expect a function named "flip" to do:
>
> flip!foo(a, b, c) === foo(c, b, a)
> flip!foo(a, b, c, d) === foo(d, c, b, a)

I would expect this to be called reverse

> While flip2 does:
>
> flip2!foo(a, b, c) === foo(b, a, c)
> flip2!foo(a, b, c, d) === foo(b, a, c, d)

and this rotate

Why flip in the first place?

> Bye,
> bearophile



Re: two mains

2013-01-27 Thread Tyro[17]

On 1/27/13 8:57 AM, David Nadlinger wrote:

On Saturday, 26 January 2013 at 20:42:27 UTC, Tyro[17] wrote:

Trying to learn from the ground up and would appreciate some
assistance making sense of the following:

// void main(){} [1]
[...]


This might not be directly relevant here, but in general, I'd steer
clear of main() for such experiments. Due to its special nature (several
possible signatures, but the calling code in druntime stays the same),
there is quite a bit of extra magic going on internally.

For example, you wouldn't normally find "xor EAX, EAX" in a
void-returning functions, as its purpose is to set the return value to
0, which implicitly happens to make the void main() and void
main(string[]) variants conform to the "full" int main(string[]) signature.

David


Thank you much. Things are starting to get a little clearer. Oh, thanks 
Vlad.


Re: two mains

2013-01-26 Thread Tyro[17]

On 1/26/13 3:42 PM, Tyro[17] wrote:
[Snip]


Both segments of code deal with a minimal D program: the first taking no
arguments and the second taking a string array. Information prior to the
".text_Dmain segment" in both files mirror each other with the exception
of module name differences.

The first difference that jumps out at me is that the ".text._Dmain
segment" in [1] properly terminates with ".text._Dmain ends" like all
other segments in the file up to this point. [2] is improperly:
".text._Dm".


[1] This seems to be a problem with the disassembler @DPaste


The second is the use of leave in [2]. If I understand correctly, leave
is the exact same as:

 movRBP,RSP
 popRBP

So why do we need to mov RBP, RSP in [2] but not in [1]? I'm thinking
this is because RBP contains the address of args but not sure.


Still not clear on this choice.


Last is the .cto at the end of [1], what on earth is it and what is it
used for? Why does it not exist in [2]?


See [1] above.


Thanks,
Andrew


two mains

2013-01-26 Thread Tyro[17]
Trying to learn from the ground up and would appreciate some assistance 
making sense of the following:


// void main(){} [1]
.text._Dmainsegment
assume  CS:.text._Dmain
_Dmain:
pushRBP
mov RBP,RSP
xor EAX,EAX
pop RBP
ret
.text._Dmainends
.cto

// void main(string[] args) {} [2]
.text._Dmainsegment
assume  CS:.text._Dmain
_Dmain:
pushRBP
mov RBP,RSP
sub RSP,010h
xor EAX,EAX
leave
ret
.text._Dm

Both segments of code deal with a minimal D program: the first taking no 
arguments and the second taking a string array. Information prior to the 
".text_Dmain segment" in both files mirror each other with the exception 
of module name differences.


The first difference that jumps out at me is that the ".text._Dmain 
segment" in [1] properly terminates with ".text._Dmain ends" like all 
other segments in the file up to this point. [2] is improperly: ".text._Dm".


The second is the use of leave in [2]. If I understand correctly, leave 
is the exact same as:


mov RBP,RSP
pop RBP

So why do we need to mov RBP, RSP in [2] but not in [1]? I'm thinking 
this is because RBP contains the address of args but not sure.


Last is the .cto at the end of [1], what on earth is it and what is it 
used for? Why does it not exist in [2]?


Thanks,
Andrew


two mains

2013-01-26 Thread Tyro[17]
Trying to learn from the ground up and would appreciate some assistance 
making sense of the following:


// void main(){} [1]
.text._Dmainsegment
assume  CS:.text._Dmain
_Dmain:
pushRBP
mov RBP,RSP
xor EAX,EAX
pop RBP
ret
.text._Dmainends
.cto

// void main(string[] args) {} [2]
.text._Dmainsegment
assume  CS:.text._Dmain
_Dmain:
pushRBP
mov RBP,RSP
sub RSP,010h
xor EAX,EAX
leave
ret
.text._Dm

Both of segments of code deal with a minimal D program: the first taking 
no arguments and the second taking a string array. Prior .text_Dmain 
segment of both files mirror each other with the exception of module 
name differences.


The first difference that jumps out at me is that the ".text._Dmain 
segment" in [1] properly terminates with ".text._Dmain ends" like all 
other segments in the file up to this point. [2] is improperly: 
".text._Dm".


The second is the use of leave in [2]. If I understand correctly, leave 
is the exact same as:


mov RBP,RSP
pop RBP

So why do we need to mov RBP, RSP in [2] but not in [1]? I'm thinking 
this is because RBP contains the address of args but not sure.


Last is the .cto at the end of [1], what on earth is it and what is it 
used for? Why does it not exist in [2]?


Thanks,
Andrew


ELF interpreter /libexec/ld-elf.so.1 not found

2012-12-28 Thread Tyro[17]

I am attempting to install DMD on BSD and a running into some issues.

The first issue is that there is no dmd.conf file bundled in 
freebsd/bin32. I mirrored the content of /osx/bin/dmd.conf but am not 
sure if there is anything unique to FREEBSD or some other BSD flavor 
that needs to be in this file.


The other problem is that I keep getting the error:

ELF interpreter /libexec/ld-elf.so.1 not found

on my system this files is actually in /usr/libexec/ld-elf.so.1.
What do I need to configure so that DMD will find it?

Thanks in advance.

Andrew


Re: declaration/initialization of multidimensional arrays

2012-11-18 Thread Tyro[17]

On 11/18/12 8:14 PM, bearophile wrote:

Why is no one complaining about this array allocation syntax?


A syntax I like is:

new double[][3][](N, M)


Why not simply allow new double[N][3][M]; ?
Seems a lot more intuitive/succinct than a separate []() implementation.


Where:
- The numbers inside the [] must be always compile-time constants, and
they always refer to fixed-sized arrays.
- The numbers inside the () are run-time values and must be used for
dynamic arrays. (They can be up to the number of empty []. No more. But
maybe they are allowed to be less).

This means this syntax becomes an error:

int n = 5;
auto a = new int[n];

You must write:

int n = 5;
auto a = new int[](n);

This becomes allowed and allocates a fixed-sized array on the heap?

auto a = new int[5];

Bye,
bearophile





Re: declaration/initialization of multidimensional arrays

2012-11-18 Thread Tyro[17]

On 11/18/12 7:53 PM, bearophile wrote:

Tyro[17]:


What is the proper way to declare a multidimensional array?
In Java, I can do:

double[][] a = new double[M][N];


In D (hopefully I have not swapped the to sizes, it's a too much common
mistake in my D code):

auto a = new double[][](M, N);

Bye,
bearophile


Thanks... This solved my issue. Much appreciated.


declaration/initialization of multidimensional arrays

2012-11-18 Thread Tyro[17]

What is the proper way to declare a multidimensional array?
In Java, I can do:

double[][] a = new double[M][N];

D does not allow this because of two reasons.

1) M & N are variables and cannot be read at compile time even if they 
are explicitly initialized.


Error: variable N cannot be read at compile time (sawalks)

2) double[17][17] is a static array and cannot be used to initialize a 
dynamic array.


	Error: cannot implicitly convert expression (new double[17LU][](17LU)) 
of type double[17LU][] to double[][] (sawalks)


Assigning a length and then trying to access the values obviously will 
not work:


double[][] a;
a.length = M * N;
a[i][j] = 17; // core.exception.RangeError@sawalks(19): Range violation

So what is the proper way to do this in D?

Thanks


Re: What is the proper way to handle pointers in variable arguments list?

2012-10-28 Thread Tyro[17]

On 10/28/12 5:16 PM, Simen Kjaeraas wrote:

On 2012-08-28 22:10, Tyro[17]  wrote:


On 10/28/12 4:44 PM, Dmitry Olshansky wrote:

On 29-Oct-12 00:36, Tyro[17] wrote:

The following fails because the compiler assumes I am trying to
dereference non-pointer variables. Can this be done?

void main()
{
 int i;
 int* pi;
 double d;
 double* pd;
 char c;
 char* pc;

 scan(i, pi, d, pd, c, pc);
}

void scan(A...)(ref A data)
{
 import std.traits;
 foreach (element; data) {
 if(isPointer!(typeof(element)) &&
isIntegral!(typeof(*element))) {
 *element = 10;
 }
 }
}

Thanks


Well, first things first:
if ---> static if



Changing it to static allows compilation, however I get the following
runtime error:

 "Segmentation fault: 11"

This happens whether I try to read from *element or modify it.


I assume you've actually initialized the pointers to something?

Given the above code, all the pointers point to null, and a segfault
would be a reasonable reaction.



Wow, so obvious yet so obviously overlooked... *banging my head on the 
monitor*


Thanks


Re: What is the proper way to handle pointers in variable arguments list?

2012-10-28 Thread Tyro[17]

On 10/28/12 4:44 PM, Dmitry Olshansky wrote:

On 29-Oct-12 00:36, Tyro[17] wrote:

The following fails because the compiler assumes I am trying to
dereference non-pointer variables. Can this be done?

void main()
{
 int i;
 int* pi;
 double d;
 double* pd;
 char c;
 char* pc;

 scan(i, pi, d, pd, c, pc);
}

void scan(A...)(ref A data)
{
 import std.traits;
 foreach (element; data) {
 if(isPointer!(typeof(element)) &&
isIntegral!(typeof(*element))) {
 *element = 10;
 }
 }
}

Thanks


Well, first things first:
if ---> static if



Changing it to static allows compilation, however I get the following 
runtime error:


"Segmentation fault: 11"

This happens whether I try to read from *element or modify it.


What is the proper way to handle pointers in variable arguments list?

2012-10-28 Thread Tyro[17]
The following fails because the compiler assumes I am trying to 
dereference non-pointer variables. Can this be done?


void main()
{
int i;
int* pi;
double d;
double* pd;
char c;
char* pc;

scan(i, pi, d, pd, c, pc);
}

void scan(A...)(ref A data)
{
import std.traits;
foreach (element; data) {
if(isPointer!(typeof(element)) && isIntegral!(typeof(*element))) {
*element = 10;
}
}
}

Thanks


Re: installation and configuration of vibe

2012-10-25 Thread Tyro[17]
On Thursday, 25 October 2012 at 11:15:38 UTC, Jacob Carlborg 
wrote:

On 2012-10-25 12:20, Tyro[17] wrote:

How the most obvious things elude us. I recently switched from 
placing
"alias dmd=/usr/share/dmd/osx/bin/dmd" .bash_profile (which 
has worked
perfectly for me since I bought my MAC) to placing the 
symlinks in
/usr/bin/. Typing DMD and RDMD at the terminal window and 
seeing help
and usage information for both programs display properly, I 
assumed that
they work. But since moving from the command line interface to 
Alexander
Bothe's awesome Mono-D ide a little while back, I haven't 
compiled
anything at the command line so hadn't realized that it wasn't 
working.


Long story short, it does not compile...
I wasn't expecting to anything else since the simple one liner 
placed in

.bash_profile took care of the issue. What am I missing?


You may need to create a symlink for the dmd.conf file as well, 
it's located next to the dmd binary. Double check that the 
dmd.conf file looks correct, when it's located in the zip it 
expects the src directory to be two levels up.


Alternative you can try out DVM:

https://bitbucket.org/doob/dvm

"DVM allows you to easily download and install D compilers and 
manage different versions of the compilers."


Just got around to looking back at this. That was in fact the 
piece of missing information. I never linked to or modified the 
dmd.conf file. Every thing works great now. Thanks for the DMV 
info but I prefer to do this manually. This way I'll never have 
to worry about an installer package being broken or unavailable. 
Besides, once you know what to do, this is pretty simple.


Thanks


Re: installation and configuration of vibe

2012-10-25 Thread Tyro[17]

On 10/25/12 5:45 AM, Jacob Carlborg wrote:

On 2012-10-25 11:23, Tyro[17] wrote:

I attempted once to install DMD on OSX using the .dmg installer but it
wasn't available. Since then I've simply downloaded the zip file, unzip
it into /usr/share/dmd and create two symlinks to DMD and RDMD in
/usr/bin/. Installation instructions contained in the readme file of
vibe suggests that I use the .dmg installer. Since I did not, I get the
following error after executing vibe:

andrew:vibe andrew$ vibe
Error: module object is in file 'object.d' which cannot be read
import path[0] = /usr/share/vibe/bin/../source
import path[1] = source
import path[2] = /tmp
Failed: 'dmd' '-g' '-w' '-property' '-I/usr/share/vibe/bin/../source'
'-L-levent_pthreads' '-L-levent' '-L-lssl' '-L-lcrypto' '-Jviews'
'-Isource' '-v' '-o-' '/tmp/vpm.d' '-I/tmp'

what do I need to do to configure vibe so that it can finds the D
installation without using this installer?


I suggest you first try and compile a simple Hello World in D :

// main.d
module main;

import std.stdio;

void main ()
{
 writeln("Hello World");
}

$ dmd main.d



How the most obvious things elude us. I recently switched from placing 
"alias dmd=/usr/share/dmd/osx/bin/dmd" .bash_profile (which has worked 
perfectly for me since I bought my MAC) to placing the symlinks in 
/usr/bin/. Typing DMD and RDMD at the terminal window and seeing help 
and usage information for both programs display properly, I assumed that 
they work. But since moving from the command line interface to Alexander 
Bothe's awesome Mono-D ide a little while back, I haven't compiled 
anything at the command line so hadn't realized that it wasn't working.


Long story short, it does not compile...
I wasn't expecting to anything else since the simple one liner placed in 
.bash_profile took care of the issue. What am I missing?


installation and configuration of vibe

2012-10-25 Thread Tyro[17]
I attempted once to install DMD on OSX using the .dmg installer but it 
wasn't available. Since then I've simply downloaded the zip file, unzip 
it into /usr/share/dmd and create two symlinks to DMD and RDMD in 
/usr/bin/. Installation instructions contained in the readme file of 
vibe suggests that I use the .dmg installer. Since I did not, I get the 
following error after executing vibe:


andrew:vibe andrew$ vibe
Error: module object is in file 'object.d' which cannot be read
import path[0] = /usr/share/vibe/bin/../source
import path[1] = source
import path[2] = /tmp
Failed: 'dmd' '-g' '-w' '-property' '-I/usr/share/vibe/bin/../source' 
'-L-levent_pthreads' '-L-levent' '-L-lssl' '-L-lcrypto' '-Jviews' 
'-Isource' '-v' '-o-' '/tmp/vpm.d' '-I/tmp'


what do I need to do to configure vibe so that it can finds the D 
installation without using this installer?


Re: BigInt Bug or just me?

2012-04-21 Thread Tyro[17]

On Saturday, 21 April 2012 at 14:30:49 UTC, Jordi Sayol wrote:

Al 21/04/12 16:07, En/na Tyro[17] ha escrit:
Why does the following implementation of the binomial 
coefficient yield two different answers?




Only happens when compiling to 32-bit.

32-bit:
(40  20) = 137846528820
(40  20) = 68923264410

64-bit:
(40  20) = 137846528820
(40  20) = 137846528820


Actually, in that case it only happens when compiling to 64-bit.

Note: comb1(BigInt(40), BigInt(20))/2; The the BigInt version is
being divided by two (on MAC OS X) in order to yield the
correct result.


BigInt Bug or just me?

2012-04-21 Thread Tyro[17]
Why does the following implementation of the binomial coefficient 
yield two different answers?


import std.stdio, std.bigint;

void main()
{
// Correct result when using long
writeln("(40  20) = ", binomial(40L, 20L));

// 2 times the expected result when using BigInt
writeln("(40  20) = ", binomial(BigInt(40), BigInt(20))/2);
}

T binomial(T)(T n, T k)
{
T iter(T n, T k, T i, T prev)
{
if (i >= k) return prev;
return iter(n, k, i+1, ((n-i)*prev)/(i+1));
}

if (k > (n-1)) return iter(n, k, cast(T)0, cast(T)1);
return iter(n, (n-k), cast(T)0, cast(T)1);
}

Additionally, why is there no implicit conversion from integer to 
BigInt?
Surely now precision will be lost when performing this 
conversion. All
those casts are butt ugly if you ask me. I believe one should be 
able to
assign any integral value to BigInt and reasonably expect that it 
be

implicitly converted.

Thanks,
Andrew


Re: GUI library

2012-03-27 Thread Tyro[17]

On Sunday, 25 March 2012 at 15:59:21 UTC, Jacob Carlborg wrote:

On 2012-03-25 17:22, Kevin Cox wrote:
I would reccomend Qt as well.  You will get native 
cross-platform
widgets with great performance.  I am not sure how far QtD is 
but I know

it once had a lot of development on it.


I don't think Qt is uses the native drawing operations on Mac 
OS X.


Thanks to you both for your assistance.


GUI library

2012-03-25 Thread Tyro[17]

Is there one available for use with D2 on MAC OS X?

Thanks,
Andrew


problems countered after while(read()){} terminated with ^D or EOF

2012-03-22 Thread Tyro[17]
I'm using the following to read arrays from the command line (or 
redirected file) but am having some issues that I have not been 
able to solve on my own. Would appreciate if a little guidance.


void f(T)(ref T a)if(isArray!T)
{
a.length = 100;
int i;
while(readf(" %s", &a[i++])) // #1
if(i == a.length) a.length *= 2;
a.length[--i];
}

issue #1
how do it terminate the input (or clear the buffer) such that 
subsequent calls to readf are not ignored?


int[] i;
f(i); // no matter how many time I call readf() after this 
point it is all always ignored

double d;
readf(" %s", &d); // not called

issue #2
how do i read a string[] such that whitespace (all or one of 
my choosing) delineate the string boundary?


readf(" %s ", &data)  sort of does the trick for spaces but 
it leaves all newlines embedded in substrings.  Assuming that 
input is provided one string per line, readf(" %s\n", &data) 
works similar to #1 above, however if there is multiple words per 
line separated by spaces an exception is immediately thrown from 
std.format.


Thanks,
Andrew