std.file.readText() extra Line Feed character

2014-12-18 Thread Colin via Digitalmars-d-learn
Why does std.file.readText() append a Line Feed char onto the end 
of the string?


I have a file with the following contents in it:
Name   =   Int
Other=Float
One More = String(Random;)

I then have the code:

void main(string[] args){
const text = Name   =   Int
Other=Float
One More = String(Random;);

string input = readText(args[1]);

writefln(Raw data);
writefln(D)%s, cast(ubyte[])text[$-5..$]);
writefln(File) %s, cast(ubyte[])input[$-5..$]);

}

This produces:
Raw data
D)[100, 111, 109, 59, 41]
File) [111, 109, 59, 41, 10]

Any Idea why the reading from the File adds on that extra '10' 
character?


I don't think it's my editor adding chars to the end of the file, 
as I'm using vi.


Re: std.file.readText() extra Line Feed character

2014-12-18 Thread ketmar via Digitalmars-d-learn
On Thu, 18 Dec 2014 09:18:35 +
Colin via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 Why does std.file.readText() append a Line Feed char onto the end 
 of the string?
 
 I have a file with the following contents in it:
 Name   =   Int
 Other=Float
 One More = String(Random;)
 
 I then have the code:
 
 void main(string[] args){
  const text = Name   =   Int
 Other=Float
 One More = String(Random;);
 
  string input = readText(args[1]);
 
  writefln(Raw data);
  writefln(D)%s, cast(ubyte[])text[$-5..$]);
  writefln(File) %s, cast(ubyte[])input[$-5..$]);
 
 }
 
 This produces:
 Raw data
 D)[100, 111, 109, 59, 41]
 File) [111, 109, 59, 41, 10]
 
 Any Idea why the reading from the File adds on that extra '10' 
 character?
 
 I don't think it's my editor adding chars to the end of the file, 
 as I'm using vi.

you *definetely* has the last line ended with '\n'.


signature.asc
Description: PGP signature


Re: std.file.readText() extra Line Feed character

2014-12-18 Thread Colin via Digitalmars-d-learn
On Thursday, 18 December 2014 at 09:25:47 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Thu, 18 Dec 2014 09:18:35 +
Colin via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:


Why does std.file.readText() append a Line Feed char onto the 
end of the string?


I have a file with the following contents in it:
Name   =   Int
Other=Float
One More = String(Random;)

I then have the code:

void main(string[] args){
 const text = Name   =   Int
Other=Float
One More = String(Random;);

 string input = readText(args[1]);

 writefln(Raw data);
 writefln(D)%s, cast(ubyte[])text[$-5..$]);
 writefln(File) %s, cast(ubyte[])input[$-5..$]);

}

This produces:
Raw data
D)[100, 111, 109, 59, 41]
File) [111, 109, 59, 41, 10]

Any Idea why the reading from the File adds on that extra '10' 
character?


I don't think it's my editor adding chars to the end of the 
file, as I'm using vi.


you *definetely* has the last line ended with '\n'.


I dont see how, I copy and pasted from the string definition in 
D, directly after the first  and directly before the last .


If I look at the file in vim with line numbers turned on, the 
file is like this. So I really dont think I have a new line in 
the file...


  1 Name   =   Int
  2 Other=Float
  3 One More = String(Random;)


Re: std.file.readText() extra Line Feed character

2014-12-18 Thread yazd via Digitalmars-d-learn

On Thursday, 18 December 2014 at 10:16:38 UTC, Colin wrote:
On Thursday, 18 December 2014 at 09:25:47 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Thu, 18 Dec 2014 09:18:35 +
Colin via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:


Why does std.file.readText() append a Line Feed char onto the 
end of the string?


I have a file with the following contents in it:
Name   =   Int
Other=Float
One More = String(Random;)

I then have the code:

void main(string[] args){
const text = Name   =   Int
Other=Float
One More = String(Random;);

string input = readText(args[1]);

writefln(Raw data);
writefln(D)%s, cast(ubyte[])text[$-5..$]);
writefln(File) %s, cast(ubyte[])input[$-5..$]);

}

This produces:
Raw data
D)[100, 111, 109, 59, 41]
File) [111, 109, 59, 41, 10]

Any Idea why the reading from the File adds on that extra 
'10' character?


I don't think it's my editor adding chars to the end of the 
file, as I'm using vi.


you *definetely* has the last line ended with '\n'.


I dont see how, I copy and pasted from the string definition in 
D, directly after the first  and directly before the last .


If I look at the file in vim with line numbers turned on, the 
file is like this. So I really dont think I have a new line in 
the file...


  1 Name   =   Int
  2 Other=Float
  3 One More = String(Random;)


You can make sure using `hexdump -C file`. I tested locally 
creating a file using vi, and it does indeed have a '\n' at the 
end of file.


Re: std.file.readText() extra Line Feed character

2014-12-18 Thread Colin via Digitalmars-d-learn

On Thursday, 18 December 2014 at 10:43:32 UTC, yazd wrote:

On Thursday, 18 December 2014 at 10:16:38 UTC, Colin wrote:
On Thursday, 18 December 2014 at 09:25:47 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Thu, 18 Dec 2014 09:18:35 +
Colin via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:


Why does std.file.readText() append a Line Feed char onto 
the end of the string?


I have a file with the following contents in it:
Name   =   Int
Other=Float
One More = String(Random;)

I then have the code:

void main(string[] args){
   const text = Name   =   Int
Other=Float
One More = String(Random;);

   string input = readText(args[1]);

   writefln(Raw data);
   writefln(D)%s, cast(ubyte[])text[$-5..$]);
   writefln(File) %s, cast(ubyte[])input[$-5..$]);

}

This produces:
Raw data
D)[100, 111, 109, 59, 41]
File) [111, 109, 59, 41, 10]

Any Idea why the reading from the File adds on that extra 
'10' character?


I don't think it's my editor adding chars to the end of the 
file, as I'm using vi.


you *definetely* has the last line ended with '\n'.


I dont see how, I copy and pasted from the string definition 
in D, directly after the first  and directly before the last 
.


If I look at the file in vim with line numbers turned on, the 
file is like this. So I really dont think I have a new line in 
the file...


 1 Name   =   Int
 2 Other=Float
 3 One More = String(Random;)


You can make sure using `hexdump -C file`. I tested locally 
creating a file using vi, and it does indeed have a '\n' at the 
end of file.


Ah, I see. That's a little annoying.
Thanks folks!


Re: core.bitop.bt not faster than ?

2014-12-18 Thread Dicebot via Digitalmars-d-learn
Having quick read through the 
http://en.wikipedia.org/wiki/Word_%28computer_architecture%29 may 
help re-calibrating the way you thing about bit operations and 
optimization.


Re: Check type is a struct at compile time?

2014-12-18 Thread shona123 via Digitalmars-d-learn

But how to do the same thing for a struct?


_
dhoom


Re: Derelict SDL2 library not loading on OS X

2014-12-18 Thread Mike Parker via Digitalmars-d-learn

On 12/18/2014 3:29 PM, Joel wrote:

I've installed SDL2.

Joels-MacBook-Pro:DerelictTest joelcnz$ cat test.d

import derelict.sdl2.sdl;

int main() {
 DerelictSDL2.load();
}


Joels-MacBook-Pro:DerelictTest joelcnz$ dmd test libDerelictSDL2.a
libDerelictUtil.a
Joels-MacBook-Pro:DerelictTest joelcnz$ ./test
derelict.util.exception.SharedLibLoadException@source/derelict/util/exception.d(35):
Failed to load one or more shared libraries:


After that last colon, you should be seeing a list of library names that 
failed to load. Did you somehow fail to copy/paste it or is it really 
missing?


You can see the names that Derelict searches for by default on Mac at 
[1]. Make sure that your copy of SDL is installed at one of those 
locations. Otherwise, you can pass the path to your installed copy to an 
overload of the load method:


DerelictSDL2.load( [Path/to/your/SDL2/installation.framework/dylib] );

[1] 
https://github.com/DerelictOrg/DerelictSDL2/blob/master/source/derelict/sdl2/sdl.d#L42 





Re: std.file.readText() extra Line Feed character

2014-12-18 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 18 December 2014 at 09:18:36 UTC, Colin wrote:
I don't think it's my editor adding chars to the end of the 
file, as I'm using vi.


:-) vim actually does it by default. Check out :help eol from 
inside it.


I think other vi clones do it too but I'm not sure, but I know 
vim has it as documented behavior.


There's apparently a few reasons for it:
http://stackoverflow.com/questions/729692/why-should-files-end-with-a-newline


Re: Fastest Way to Append Multiple Elements to an Array

2014-12-18 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/17/14 6:15 AM, zeljkog wrote:

On 15.12.14 01:00, Nordlöw wrote:

Isn't this algorithm already encoded somewhere in Phobos?


void append(T, Args...)(ref T[] arr, auto ref Args args){
{
static if (args.length == 1)
   arr ~= args[0]; // inlined
else{
   arr.length += args.length;
   foreach(i, e; args)
  arr[$ - args.length + i] = e;
}
}

I've just tested, this looks usable.
Equal for 1 item, considerably (~40%) faster for 2, and much (100+%) faster for 
more.
Also more convenient.


This makes sense. The cost of calling a function is much much higher 
than copying a single element.



Maybe samthing like that should go to Fobos.


Definitely. I would love to see the improvement, however, of having arr 
~= [a, b, c] do this automatically by the compiler.


I wonder how your code compares to this:

void append(T)(ref T[] arr, T[] args...)
{
   arr ~= args;
}

Which is how I would have approached it. Your solution is more general, 
but mine has the benefit of avoiding the double-initialization of the data.


-Steve


Re: Fastest Way to Append Multiple Elements to an Array

2014-12-18 Thread Nordlöw
On Wednesday, 17 December 2014 at 12:30:37 UTC, Tobias Pankrath 
wrote:

void append(T, Args...)(ref T[] arr, auto ref Args args){
{
  static if (args.length == 1)
 arr ~= args[0]; // inlined
  else{
 arr.length += args.length;
 foreach(i, e; args)
arr[$ - args.length + i] = e;
  }
}


Is it un-Phobos-like to make append return a reference to data 
like at


https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1605


Why do std.traits use template foo(args...) instead of foo(alias arg) ?

2014-12-18 Thread Mathias LANG via Digitalmars-d-learn

An exemple being fullyQualifiedName:
https://github.com/D-Programming-Language/phobos/blob/master/std/traits.d#L415

I don't get this pattern. Is it documented somewhere ?


Re: Why do std.traits use template foo(args...) instead of foo(alias arg) ?

2014-12-18 Thread Low Functioning via Digitalmars-d-learn

On Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG wrote:

An exemple being fullyQualifiedName:
https://github.com/D-Programming-Language/phobos/blob/master/std/traits.d#L415

I don't get this pattern. Is it documented somewhere ?


http://dlang.org/variadic-function-templates.html


Re: Why do std.traits use template foo(args...) instead of foo(alias arg) ?

2014-12-18 Thread Dicebot via Digitalmars-d-learn

On Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG wrote:

An exemple being fullyQualifiedName:
https://github.com/D-Programming-Language/phobos/blob/master/std/traits.d#L415

I don't get this pattern. Is it documented somewhere ?


Full pattern looks like this:

template foo(T...)
if (T.length == 1)

This is a way to workaround D template argument limitation - you 
can't have any parameter that accepts both types and symbols 
(`alias T` and `T` at once) other than variadic parameter. Limit 
variadic length to 1 and you emulate such accepts anything 
parameter.


Re: Why do std.traits use template foo(args...) instead of foo(alias arg) ?

2014-12-18 Thread ketmar via Digitalmars-d-learn
On Thu, 18 Dec 2014 15:52:06 +
Low Functioning via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 On Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG wrote:
  An exemple being fullyQualifiedName:
  https://github.com/D-Programming-Language/phobos/blob/master/std/traits.d#L415
 
  I don't get this pattern. Is it documented somewhere ?
 
 http://dlang.org/variadic-function-templates.html
that's not a question about what it does?, but the question about
why it did this way?

the answer is simple: `alias` arguments can't accept types. i.e.

  template t0(T...) if (T.length == 1) {
enum t0 = T[0].stringof;
  }

  template t1(alias T) {
enum t1 = T.stringof;
  }


  pragma(msg, t0!int);
  pragma(msg, t1!int);

# dmd -c -o- test.d

  int
  test.d(11): Error: template instance t1!int does not match template 
declaration t1(alias T)
  test.d(11):while evaluating pragma(msg, t1!int)

but:

  int a;
  pragma(msg, t0!a);
  pragma(msg, t1!a);

gives:

  a
  a

i.e. (T...) can accept both types and symbols, and `alias` can accept
only symbols. `fullyQualifiedName` then checks if T is symbol or type:

  static if (is(T)) ... // T is a type, process as type
  else ... // T is a symbold, process as symbol


signature.asc
Description: PGP signature


Re: Why do std.traits use template foo(args...) instead of foo(alias arg) ?

2014-12-18 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/18/14 11:21 AM, ketmar via Digitalmars-d-learn wrote:

On Thu, 18 Dec 2014 15:52:06 +
Low Functioning via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:


On Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG wrote:

An exemple being fullyQualifiedName:
https://github.com/D-Programming-Language/phobos/blob/master/std/traits..d#L415

I don't get this pattern. Is it documented somewhere ?


http://dlang.org/variadic-function-templates.html

that's not a question about what it does?, but the question about
why it did this way?

the answer is simple: `alias` arguments can't accept types. i.e.


s/types/keywords

alias can accept types as long as they are symbols.

For instance:

struct S {}

pragma(msg, t1!S); // works.

-Steve


Re: Why do std.traits use template foo(args...) instead of foo(alias arg) ?

2014-12-18 Thread ketmar via Digitalmars-d-learn
On Thu, 18 Dec 2014 11:26:20 -0500
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 On 12/18/14 11:21 AM, ketmar via Digitalmars-d-learn wrote:
  On Thu, 18 Dec 2014 15:52:06 +
  Low Functioning via Digitalmars-d-learn
  digitalmars-d-learn@puremagic.com wrote:
 
  On Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG wrote:
  An exemple being fullyQualifiedName:
  https://github.com/D-Programming-Language/phobos/blob/master/std/traits..d#L415
 
  I don't get this pattern. Is it documented somewhere ?
 
  http://dlang.org/variadic-function-templates.html
  that's not a question about what it does?, but the question about
  why it did this way?
 
  the answer is simple: `alias` arguments can't accept types. i.e.
 
 s/types/keywords
 
 alias can accept types as long as they are symbols.
 
 For instance:
 
 struct S {}
 
 pragma(msg, t1!S); // works.

yes, thank you. bad wording on my side.


signature.asc
Description: PGP signature


Re: Why do std.traits use template foo(args...) instead of foo(alias arg) ?

2014-12-18 Thread Mathias LANG via Digitalmars-d-learn

On Thursday, 18 December 2014 at 16:10:31 UTC, Dicebot wrote:
On Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG 
wrote:

An exemple being fullyQualifiedName:
https://github.com/D-Programming-Language/phobos/blob/master/std/traits.d#L415

I don't get this pattern. Is it documented somewhere ?


Full pattern looks like this:

template foo(T...)
if (T.length == 1)

This is a way to workaround D template argument limitation - 
you can't have any parameter that accepts both types and 
symbols (`alias T` and `T` at once) other than variadic 
parameter. Limit variadic length to 1 and you emulate such 
accepts anything parameter.


Thanks for the precision. Is it something that is going to be 
fixed, or is it by design ?


Re: Why do std.traits use template foo(args...) instead of foo(alias arg) ?

2014-12-18 Thread Dicebot via Digitalmars-d-learn

On Thursday, 18 December 2014 at 17:20:28 UTC, Mathias LANG wrote:
Thanks for the precision. Is it something that is going to be 
fixed, or is it by design ?


It is something that most likely would have been designed 
differently if we had another chance (aka D3) but unlikely to 
change in D2 as existing pattern works good enough in practice. 
It is confusing but usually only needed for power user libraries 
thus learning curve impact is low.


Re: Fastest Way to Append Multiple Elements to an Array

2014-12-18 Thread Tobias Pankrath via Digitalmars-d-learn

On Thursday, 18 December 2014 at 15:12:39 UTC, Nordlöw wrote:
On Wednesday, 17 December 2014 at 12:30:37 UTC, Tobias Pankrath 
wrote:

void append(T, Args...)(ref T[] arr, auto ref Args args){
{
 static if (args.length == 1)
arr ~= args[0]; // inlined
 else{
arr.length += args.length;
foreach(i, e; args)
   arr[$ - args.length + i] = e;
 }
}


Is it un-Phobos-like to make append return a reference to data 
like at


https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1605


I don't now, returning it at least allows chaining, which is nice.

You shouldn't use my code verbatim though. For example, you 
should only use x.length, if x is of element type of data. 
Otherwise if you have e.g. an array of array you'd get totally 
wrong numbers.


PyD-like wrapping for Excel/VBA and Julia?

2014-12-18 Thread Laeeth Isharc via Digitalmars-d-learn
I have a bunch of D functions I would like to make available to 
Excel (and possibly Julia) without having to write wrappers for 
each function individually.


For Excel, I think one needs two levels of wrapper - one is to 
create a C style interface [using extern(Windows) calling 
convention, and pointers to doubles or structs rather than 
dynamic arrays], and the second is to write the VBA wrapper that 
calls the C interface.  (There may be more efficient purer ways 
of doing this, but I don't wish to spend time learning Excel 
internals/object models, and I know my route will work reasonably 
well).


So a very simple D function:
double test(double[] inp,  ref double[] oup)
{
double sum=0.0;
oup.length=inp.length;
foreach(i;0..inp.length)
{
oup[i]=inp[i]*inp[i];
sum+=oup[i];
}
return sum;
}

and my first attempt at a wrapper:

extern(Windows) double vbwrap_test(double* inp,size_t 
num_inp,double* oup,size_t num_oup)

{
double[] arg_inp;
arg_inp.length=num_inp;
double[] arg_oup;
arg_oup.length=num_oup;
foreach(arg;0..num_inp)
{
arg_inp[arg]=inp[arg];
}

foreach(arg;0..num_oup)
{
arg_oup[arg]=oup[arg];
}

return test(arg_inp,arg_oup);
}

I didn't yet write the bit that copies the result from test back 
to the calling double*.


Slowly learning metaprogramming/CTFE in D, and the code above was 
generated from the function definition by some horrible looking D 
code, ready to place into a string mixin.  I need to make it more 
general (to accept structs etc), and write the VBA wrapper 
generation too.


But if anyone has any useful pointers or suggestions or would 
like to help, do let me know.  I guess this project could be of 
broader application since in the financial and other sectors 
people still are stuck with Excel as a front end in many cases, 
for better or for worse.


I will look at LuaD and PyD and Adam's web.d for inspiration..

Julia was just something to think about further down the line.  I 
haven't used it much yet.



Thanks.


Laeeth.


Re: std.file.readText() extra Line Feed character

2014-12-18 Thread Ali Çehreli via Digitalmars-d-learn

On 12/18/2014 02:51 AM, Colin wrote:

  vi, and it does indeed have a '\n' at the end of file.

 Ah, I see. That's a little annoying.

It looks like there are ways of dealing with it:


http://stackoverflow.com/questions/1050640/vim-disable-automatic-newline-at-end-of-file

Ali
happy with Emacs :p



Re: Fastest Way to Append Multiple Elements to an Array

2014-12-18 Thread zeljkog via Digitalmars-d-learn
On 18.12.14 14:50, Steven Schveighoffer wrote:
 I wonder how your code compares to this:
 
 void append(T)(ref T[] arr, T[] args...)
 {
 arr ~= args;
 }

This is ~20% slower for ints, but it difference  increases for bigger structs.


Re: Derelict SDL2 library not loading on OS X

2014-12-18 Thread Joel via Digitalmars-d-learn

[snip]

Failed to load one or more shared libraries:


After that last colon, you should be seeing a list of library 
names that failed to load. Did you somehow fail to copy/paste 
it or is it really missing?


Yes, there was something wrong there, here's another go:

Joels-MBP:test joelcnz$ dmd test.d sdl.a util.a
Joels-MBP:test joelcnz$ ./test
derelict.util.exception.SymbolLoadException@derelict/util/exception.d(35): 
Failed to load symbol SDL_free from shared library 
/usr/local/lib/libSDL2.dylib


5   test0x0001046a1993 void 
derelict.util.loader.SharedLibLoader.bindFunc(void**, 
immutable(char)[], bool) + 127
6   test0x00010469d3dc void 
derelict.sdl2.sdl.DerelictSDL2Loader.loadSymbols() + 312
7   test0x0001046a168f void 
derelict.util.loader.SharedLibLoader.load(immutable(char)[][]) + 
123
8   test0x0001046a1611 void 
derelict.util.loader.SharedLibLoader.load(immutable(char)[]) + 269
9   test0x0001046a14fe void 
derelict.util.loader.SharedLibLoader.load() + 98
10  test0x00010469cec5 _Dmain 
+ 21
11  test0x0001046b8a64 
D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv + 40
12  test0x0001046b89a9 void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) + 45
13  test0x0001046b8a09 void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() + 45
14  test0x0001046b89a9 void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) + 45
15  test0x0001046b8925 
_d_run_main + 433
16  test0x00010469cee4 main + 
20
17  libdyld.dylib   0x7fff8ac6f5c9 start 
+ 1

18  ??? 0x0001 0x0 + 1
Joels-MBP:test joelcnz$

You can see the names that Derelict searches for by default on 
Mac at [1]. Make sure that your copy of SDL is installed at one 
of those locations. Otherwise, you can pass the path to your 
installed copy to an overload of the load method:


DerelictSDL2.load( 
[Path/to/your/SDL2/installation.framework/dylib] );


I didn't put install with SDL2, libSDL2.dylib was in a different 
place than were I copied SDL2 (old installation?). And I couldn't 
get that to work either.


[1] 
https://github.com/DerelictOrg/DerelictSDL2/blob/master/source/derelict/sdl2/sdl.d#L42




Re: PyD-like wrapping for Excel/VBA and Julia?

2014-12-18 Thread Ellery Newcomer via Digitalmars-d-learn

On 12/18/2014 12:41 PM, Laeeth Isharc wrote:

I have a bunch of D functions I would like to make available to Excel
(and possibly Julia) without having to write wrappers for each function
individually.



I've thought about refactoring the reflection parts of pyd into a 
reusable library for e.g. resurrecting RuD. Come to think of it, that 
would probably be necessary for supporting pypy.


It'd be a heck of a lot of work, though.



For your wrapper, you can probably do something like

extern(Windows) double vbwrap_test(double* inp,size_t num_inp,double* 
oup,size_t num_oup)

{
return test(inp[0 .. num_inp], arg_oup[0 .. num_oup]);
}

with .dup sprinkled in as you see fit. And you don't need to explicitly 
copy the results back! Might need to take the ref off oup in test..


Memoizing methods

2014-12-18 Thread kyle via Digitalmars-d-learn
If you memoize a method inside a class definition using 
std.functional.memoize is caching done in a per-object manner, or 
do all objects of this class share cached return values? Thank 
you.


Re: Derelict SDL2 library not loading on OS X

2014-12-18 Thread Mike Parker via Digitalmars-d-learn

On 12/19/2014 9:58 AM, Joel wrote:

[snip]



derelict.util.exception.SymbolLoadException@derelict/util/exception.d(35):
Failed to load symbol SDL_free from shared library
/usr/local/lib/libSDL2.dylib


OK, the loader is finding libSDL2.dylib in /usr/local/lib where it 
expects it to be. Your error is that it cannot find the SDL_free 
function in the library. That indicates that the library version of SDL 
is 2.0.0 (SDL_free was added in 2.0.1) and you are using a branch of 
Derelict that is implemented against SDL 2.01 or higher.


You have three possible solutions here.

1) Use the 2.0.0 branch of Derelict.

2) Uninstall your 2.0.0 installation of SDL and use the latest version 
(along with the appropriate branch of DerelictSDL2 -- 2.0.1 for SDL 
2.0.1 and 2.0.2 for SDL 2.0.2  2.0.3 -- you shouldn't be using master).


3) Take advantage of Derelict's selective loading mechanism. This means 
you can use any branch of Derelict to load older versions of SDL2 by 
telling Derelict to not to throw exception on certain missing symbols. 
But that also means that you have to add a complete list of every symbol 
that was added between SDL 2.0.0 and whichever version corresponds to 
your version of Derelict. It's only feasible if you don't need the 
missing functions, but in that case you should go with option 1 anyway.


I strongly recommend the first option. Using the 2.0.0 branch allows you 
to load every version of SDL 2.0.x that has been or will be released. 
However, if you need certain functions that were added in later versions 
(such as SDL_GetBasePath which was added in 2.0.1), then you will need 
to use the 2.0.1 branch of Derelict and require version 2.0.1 at run time.



I didn't put install with SDL2, libSDL2.dylib was in a different place
than were I copied SDL2 (old installation?). And I couldn't get that to
work either.


I'm not quite clear on what you're saying here. Is that you did not copy 
the version you compiled to /usr/local/lib/libSDL2.dylib and that the 
version you compiled also failed? At any rate, the options I presented 
above should help you sort it out.


[1] Selective Symbol Loading at the bottom of 
http://derelictorg.github.io/using.html


BigInt and

2014-12-18 Thread Andre via Digitalmars-d-learn

Hi,

I try to translate following javascript coding to D:

i = buffer[2]  16;
i |= buffer[1]  8;
i |= buffer[0];
i += buffer[3]  24  0;

Buffer is:
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
255, 255, 111]


Expected result for i is: 4294967295
But in D the last statement returns -1, the previous 3 statements
returns the same values like in JavaScript.

I tried long and also like in the example BigInt, both do not
work correctly. In the documentation it is also mentioned that

is not supported for BigInt?


void main()
{
import std.stdio;
import std.bigInt;

	auto buffer = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
255, 255, 255, 255, 255, 111];

BigInt i;

i = buffer[2]  16;
i |= buffer[1]  8;
i |= buffer[0];
i += buffer[3]  24  0;
writeln(i: , i);
}

Do you have any idea how to translate the coding correctly?

Kind regards
André