Re: D-Man culture

2016-06-19 Thread Max Klyga via Digitalmars-d-announce

On 2016-06-19 23:29:35 +, Adam D. Ruppe said:


We should probably make a D-man video game.


There already are a couple:

http://yomogimaru.tumblr.com/post/145803169293
http://goboriin.sub.jp/DLNGRING/ 



Re: Are there any D scripting engines for use with D?

2016-01-04 Thread Max Klyga via Digitalmars-d-learn

On 2016-01-04 18:40:03 +, Jason Jeffory said:

We have many scripting engines available for use in D more or less(lua, 
python, etc...).


Is there a D scripting engine that can be easily integrated into a D 
project? A sort of "exec()". Something that works at compile 
time and run time possibly? If  is a static string then it 
should be able to compile it at compile time, else, run time. Also, it 
would be nice if one could set up a unique state for the code to run 
in(so it can't be hacked by harmful coding), e.g., "exec(, 
state)", where state is the state used for the exec(passed along to the 
 to use) for external function access and variable passing.


Something that is fast as possible would be nice too! I know there this 
is quite a request, but hopefully there will be work on it. I'd love to 
see scripting capabilities included with most programs! This would be a 
start, at least, for my programs.


The fastest one would probably be Lua - http://code.dlang.org/search?q=lua
But there are other options:
Python - http://code.dlang.org/packages/pyd
Javascript - http://code.dlang.org/search?q=javascript and 
http://pointersgonewild.com/higgs/
Croc (previously miniD, a scripting language implemented in D) - 
http://jfbillingsley.com/croc/




Dependent types in half of D

2015-07-30 Thread Max Klyga via Digitalmars-d
Just noticed a nice blog post about mapping dependent type 
applications to D.

http://www.infognition.com/blog/2015/dependent_types_in_d.html

reddit: 
https://www.reddit.com/r/programming/comments/3f59f4/dependent_types_in_half_of_d/


Re: D casually mentioned and dismissed + a suggestion

2015-05-12 Thread Max Klyga via Digitalmars-d

On 2015-05-12 20:02:05 +, Brian Schott said:


On Tuesday, 12 May 2015 at 18:35:10 UTC, FujiBar wrote:

But there are no vacancies...


There's at least one:
https://emsi.bamboohr.com/jobs/view.php?id=30


https://arex.recruiterbox.com/jobs/fk0hjlh/



Re: a success story for D ! !!

2015-05-06 Thread Max Klyga via Digitalmars-d

On 2015-05-06 12:21:30 +, Mengu said:


On Tuesday, 5 May 2015 at 12:04:39 UTC, Alex Ogheri wrote:

Hi guys, did you know this ??

http://vlang.org/


In fact, it gathered quite an enthusiastic appreciation at dvcon in Munich!!


some of you might know it, some of you might not but bernard helyer of 
our own, also created a language called Volt. its compiler is written 
in D.


see it in action: https://github.com/VoltLang/Volta


It's more or less a fork of SDC so feature-wise and syntax-wise Volt 
and D overlap quite a bit.
Also Tango folks forked D1 to create Amber - 
https://bitbucket.org/larsivi/amber/wiki/Home (it seems it's not 
actively developed right now)




Re: Templates: Array slices not recognized

2015-04-18 Thread Max Klyga via Digitalmars-d-learn

On 2015-04-18 13:46:19 +, Chris said:


The following:

import std.stdio : writefln;
import std.range.primitives : isInputRange, hasLength;

void main() {
   size_t[] a = [1, 2, 3, 4, 5, 6, 7, 8, 9];
   doSomething(a);  // works

   doSomething(a[0..5]);

// --- Error: template slices.doSomething cannot deduce function from 
argument types !()(ulong[]), candidates are:
   // slices.d(11): slices.doSomething(R)(ref R r) if (isInputRange!R 
 hasLength!R)


   doSomething!(size_t[])(a[0..5]);
   // --- Error: doSomething (ref ulong[] r) is not callable using 
argument types (ulong[])

}

void doSomething(R)(ref R r)
 if (isInputRange!R  hasLength!R)  // etc..
{
   foreach (ref n; r) {
 writefln(%d * 2 = %d, n, n * 2);
   }
}

//EOF

a[0..5] is not recognized as size_t[]. If I give the compiler a hint 
with !(size_t[]), it complains again, i.e. I can not pass the slice as 
a reference.


A workaround is

size_t[] b = a[0..5];
doSomething(b);

However, this comes with a serious performance penalty in for loops 
(even if I predefine b and reuse it in the loop). 
to!(size_t[])(a[0..5]) is even worse.


Any thoughts or tips?


a[0..5] is an R-value, and cannot be passed by reference.
As you noticed, once you use a variable - everything works because only 
L-values can be passed by reference.


Also why are you passing slices by reference? Slices do not copy the 
memory they point to when passed by value.




Re: Interlocked (compare) exchange

2015-04-17 Thread Max Klyga via Digitalmars-d-learn

On 2015-04-17 10:36:31 +, Szymon Gatner said:


Hi,

are there equivalents of Interlocked.Exchange [1] and 
Interlocked.CompareExchange [2] in D? I can't find it in teh docs?


[1] https://msdn.microsoft.com/en-us/library/f2090ex9(v=vs.110).aspx

[2] https://msdn.microsoft.com/en-us/library/h7etff8w(v=vs.110).aspx


http://dlang.org/phobos/core_atomic.html#.cas



Re: Release Candidate D 2.067.0-rc1

2015-03-17 Thread Max Klyga via Digitalmars-d-announce

On 2015-03-17 11:18:10 +, Daniel Kozak said:


On Monday, 16 March 2015 at 21:38:22 UTC, Martin Nowak wrote:

Release Candidate for 2.067.0

http://downloads.dlang.org/pre-releases/2.x/2.067.0/
http://ftp.digitalmars.com/
You can get the binaries here until they are mirrored.
https://dlang.dawg.eu/downloads/dmd.2.067.0-rc1/

We fixed the few remaining issues.
https://github.com/D-Programming-Language/dmd/compare/v2.067.0-b4...v2.067.0-rc1 

https://github.com/D-Programming-Language/phobos/compare/v2.067.0-b4...v2.067.0-rc1 



Unless any new issue pops up, we'll make the release on friday.

-Martin


Does not work with my code base :(

dmd: interpret.c:6724: void setValue(VarDeclaration*, Expression*): 
Assertion `(vd-storage_class  (0x1000LL | 0x20LL)) ? 
isCtfeReferenceValid(newval) : isCtfeValueValid(newval)' failed.

Exit code 134


Please concider submitting a bug request with minified test case 
created using dustmite (https://github.com/CyberShadow/DustMite)




Re: string-int[] array

2015-03-08 Thread Max Klyga via Digitalmars-d-learn

On 2015-03-08 21:11:42 +, Paul said:


On Sunday, 8 March 2015 at 18:05:33 UTC, Dennis Ritchie wrote:
Is it possible to create such an array in which you can store strings 
and numbers at the same time?


string-int[] array = [4, five];


As there's no mention of performance, what's wrong with a plain old 
string array with a bit of conversion and error checking?


string[] soup = [4, Test, 5, More Test];


OP is fighting a loosing battle in flame war on some obscure forum. F# 
enthusiast trolls OP into solving stupid puzzles that are trivial in F# 
(or any ML-family language) and clumsy in C-family languages.


In language holy wars the only winning move is not to play.



Re: Object as function argument

2015-03-05 Thread Max Klyga via Digitalmars-d-learn

On 2015-03-05 19:35:34 +, Chris Sperandio said:


Hi,

I'm a developer coming from C and I've a question about class instance 
as method or function parameter.
In the book The D Programming Language, I read the instance was 
passed by reference to functions (in the opposite of structures). I 
understood that it was the same object in the function and the caller. 
But I'm think, I was wrong because when I print the addresses of an 
object before the function call and inside the function, they're not 
the same but the changes from the function are kept in the instance.
If I use the ref qualifier in the function declaration, the 2 
addresses are the same.


How do the changes work in the function? Is there a copy ? Or a magic 
trick :) ?


Chris


When you write `auto myObject = new MyObject();`
`myObject` is actually a pointer to object in GC memory. Its roughly 
equivalent to `struct MyObject *myobject` in C. So when you take a 
pointer you actually take a pointer to reference on the stack and thats 
why its different in the function - variable is higher up the stack.

`ref` qualifyer guaranties that you get the pointer to the same reference.

If you really need the actual pointer to object data you can use 
`*cast(void**)myObject`. Compiler cannot cast object reference to 
`void*` but we can trick it ;)




Re: A Refcounted Array Type

2015-02-23 Thread Max Klyga via Digitalmars-d
I thought that delete is deprecated, yet here Walter himself promotes a 
solution that uses it.
Can we *PLEASE* finally deprecate things that are supposed to be 
deprecated and remove things that are supposed to be removed?


On 2015-02-23 22:15:46 +, Walter Bright said:


This is pretty straightforward. More could be done:

1. small array optimization
2. support for ranges as constructor args
3. present a range interface
4. support for malloc/free instead of GC
5. bounds checking
6. the array[] and the count could be allocated together
7. array[] could be just a pointer

but the basic idea is there, I didn't want to hide it behind all the 
other flesh a professional type would have.


Note the return in opIndex(). This is DIP25 at work!

Compile:
 dmd rcarray -unittest -main -dip25

===

struct RCArray(E) {

 this(E[] a)
 {
 array = a.dup;
 start = 0;
 end = a.length;
 count = new int;
 *count = 1;
 }

 ~this()
 {
 if (count  --*count == 0)
 delete array;
 }

 this(this)
 {
 if (count)
 ++*count;
 }

 size_t length()
 {
 return end - start;
 }

 ref E opIndex(size_t i) return // here's the magic
 {
 return array[start + i];
 }

 RCArray opSlice(size_t lwr, size_t upr)
 {
 RCArray result = this;
 result.start = start + lwr;
 result.end = start + upr;
 return result;
 }

   private:
 E[] array;
 size_t start, end;
 int* count;
}

unittest
{
 static int[3] s = [7, 6, 4];
 auto r = RCArray!int(s);
 assert(r.length == 3);
 assert(r[0] == 7);
 assert(r[1] == 6);
 assert(r[2] == 4);
 assert(*r.count == 1);

 {
 auto r2 = r;
 assert(r2[0] == 7);
 assert(r2[1] == 6);
 assert(r2[2] == 4);
 assert(*r.count == 2);

 r[1] = 3;
 assert(r2[0] == 7);
 assert(r2[1] == 3);
 assert(r2[2] == 4);
 }
 assert(*r.count == 1);

 auto r3 = r[1 .. 3];
 r[2] = 9;
 assert(r3[0] == 3);
 assert(r3[1] == 9);

   /+
 ref int test(ref RCArray!int rr)
 {
 return rr[1]; // this gives error
 }
+/
}





Re: std.sevenzip - Do you need it?

2015-01-30 Thread Max Klyga via Digitalmars-d

On 2015-01-30 16:01:27 +, data man said:


Right now I'm working on std.sevenzip (7-zip by Igor Pavlov).

The main features of 7-Zip:
- High compression ratio in 7z format with LZMA and LZMA2 compression
- Supported formats:
   - Packing / unpacking: 7z, XZ, BZIP2, GZIP, TAR, ZIP and WIM
   - Unpacking only: ARJ, CAB, CHM, CPIO, CramFS, DEB, DMG, FAT, HFS, 
ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, RAR, RPM, SquashFS, UDF, VHD, 
WIM, XAR and Z.
   - For ZIP and GZIP formats, 7-Zip provides a compression ratio that 
is 2-10 % better than the ratio provided by PKZip and WinZip

- Strong AES-256 encryption in 7z and ZIP formats

Why are there - everybody knows it :-)

My question is: how best to do - one big module std.sevenzip or divided 
into sub-modules:


std.sevenzip.aes
std.sevenzip.lzma
std.sevenzip.lzma2
std.sevenzip.ppmd
std.sevenzip.sha256
std.sevenzip.xz
...etc.

Or there is the issue of the license? (http://7-zip.org/license.txt)


Is this a port or binding for some existing library?
Also all phobos submissions must be Boost licenced.

If this is a binding or code cannot be relicenced this might better be 
suited for inclusion in DUB registry




Re: Calypso and the future of D

2015-01-23 Thread Max Klyga via Digitalmars-d

On 2015-01-23 00:24:44 +, Andrei Alexandrescu said:

I think it's important that we enable Calypso 
(https://github.com/Syniurge/Calypso) and related tooling that 
interfaces D with other languages, notably C++.


A key topic in 2015 for D is playing well with C++. A good C++ 
interface will give access to a host of mature C++ libraries, starting 
of course with the C++ standard library. More importantly, it will 
provide a smooth migration path for organizations that want to do 
development in D whilst taking advantage of their legacy code.


I'd like to open the topic of what can we do in core D to make Calypso 
better.


But first, I want to get better acquainted with Calypso and raise 
awareness of it with coworkers and the larger community. To my dismay, 
the github homepage provides exactly zero look and feel use examples 
beyond the mechanics of building Calypso itself.


To Calypso's creator: is it possible to beef up the documentation of 
Calypso with a few use cases? Ideally there'd be a soup-to-nuts step by 
step guide of making a C++ library (either artificial or extant) 
interfacing with D. Also: what things on the D side would be necessary 
to make the interface better? Exceptions would be an obvious topic on 
which we have an attack already (more on it later).



Thanks,

Andrei


I remember Walter arguing against this type of solutions because it 
requires a C++ compiler to be bundled with D.

Does that mean that now we are adopting this path instead of 'extern(C++)' ?



Re: Data-Oriented Demo: SOA, composition via crazy 'using'

2015-01-21 Thread Max Klyga via Digitalmars-d

On 2015-01-21 19:12:20 +, Fool said:

Jonathan Blow published another video [1] presenting the progress of 
his language. He is treating two main topics:


  - a keyword preliminary called 'using' which seems to be quite close 
to 'alias this';
  - an annotation SOA for pointers and arrays which allow high level 
treatment of structures of arrays;


Jonathan does not seem to be aware of 'alias this' in D.


This is a very good video demonstrating the power that 'alias this' 
gives to people that really want to controll object layout and manage 
details of memory access patterns.


AoS and SoA annotations are interesting. This should be easily 
replicatable with the power of D's templates except for the 
'robustness' part of his talk, as you would have to change declarations 
at invocation part to switch AoS to SoA and back.


The material in his talk would make a great blog post demostrating 
power of 'alias this'




Re: Error handling in DMD and Bugzilla

2014-12-11 Thread Max Klyga via Digitalmars-d

On 2014-12-11 14:53:57 +, Etienne said:

I've found 2 internal compiler errors so far, but they have been 
occurring in very complex circumstances that I haven't been able to 
isolate within reasonable time frames (~ 1 hour).


https://github.com/etcimon/dmd/commit/32f2b44c8c126243f9c4ff00b89b175c9e596e7f

https://github.com/D-Programming-Language/dmd/commit/ca333f4b320223cc7d3779471cd27bb43af2f84a 



In each case, simply showing the error with ::error allowed me to debug 
the source code and the ICE was not justified at all.


Is there a way to fast track the specific category (error handling) of 
ICE in DMD to avoid forcing me to waste more time isolating the bug?


Have you tried running Dustmite 
(https://github.com/CyberShadow/DustMite) to minimize a test case 
automatically?




Re: Keeping a dynamic sorted range

2014-11-07 Thread Max Klyga via Digitalmars-d

On 2014-11-07 14:11:30 +, bearophile said:


(This is a partial repost from a recent D.learn thread.)

In Phobos we have SortedRange and assumeSorted, but I do find them not 
very good for a common enough use case.


The use case is to keep a sorted array, keep adding items to it (adding 
larger and larger items at the end. Or sometimes even inserting items 
in the middle. In both cases I keep the sorting invariant). And while I 
add items, I also now and then want to perform a binary search on the 
sorted range.


So sometimes I'd like to do something like this (but a SortedRange 
doesn't have append):


struct Foo { int x; }
SortedRange!(Foo[], q{ a.x  b.x }) data;
data ~= Foo(5);
immutable n = data.upperBound(Foo(2)).length;

Bye,
bearophile


Ranges are not container. They are meant for traversing. If you want a 
sorted range - use an underlying container that preserves ordering 
(trees, heaps)




Re: [Semi OT] Language for Game Development talk

2014-10-01 Thread Max Klyga via Digitalmars-d

On 2014-10-01 22:33:39 +, Paulo Pinto said:


Am 02.10.2014 00:11, schrieb po:



I don't know of any OOP in the STL, unless you mean the 1980's stuff
like iostreams and the other shit most people avoid using, but I don't
think this is considered part of the STL



Any use of a class instance is part of OOP.

IOStreams, iterators, strings, containers, ranges, filesytem,
networking, graphics, traits

Being lazy, and counting its occurrences in comments and when used as
instead of typename in templates as well

/cygdrive/c/android-sdk/android-ndk/sources/cxx-stl/gnu-libstdc++/4.8/include

$ grep -R class * | uniq | wc -c
15601

STL is a name that stuck from the old days when it wasn't part of the
language. Nowadays it is just the C++ standard library.

--
Paulo


According to Stepanov STL author:

http://www.stlport.org/resources/StepanovUSA.html

Yes. STL is not object oriented. I think that object orientedness is
almost as much of a hoax as Artificial Intelligence. I have yet to see
an interesting piece of code that comes from these OO people.

I'd agree with him, just using a class, because it is the primary
abstraction in C++, does not make your code OOP.




Well I disagree with him and can find examples of static and dynamic 
polymorphism, data encapsulation and aggregation everywhere in STL, 
even if he dislikes OO people.


Algorithms is probably the only part that is free of OO concepts.


Data encapsulation is not unique to oop. STL is ADT not OOP.



[Semi OT] Language for Game Development talk

2014-09-19 Thread Max Klyga via Digitalmars-d
Jonathan Blow just recorded a talk about the needs and ideas for a 
programming language for game developer.


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

This talk mentions D quite a lot of times.
D is mentioned as the most probable to be adopted if it were possible 
for frictionless interaction with existing codebase.
An interesting talk if you want to look at language design from game 
developer perspective.




[OT] Microsoft filled patent applications for scoped and immutable types

2014-08-26 Thread Max Klyga via Digitalmars-d

Microsoft being microsoft again.

http://www.freepatentsonline.com/y2014/0196015.html - DECLARATION OF 
LIFETIME OF RESOURCE REFERENCE

This contains description of scoped classes, etc.

http://www.freepatentsonline.com/y2014/0196008.html - IMMUTABLE OBJECT TYPES

I really hope patent office will reject these applications.



Re: D Users Survey: Primary OS?

2014-05-29 Thread Max Klyga via Digitalmars-d

On 2014-05-29 15:53:22 +, Tom Browder via Digitalmars-d said:


Has anyone done a survey of the primary OS of D users?

I (a D newbie) use Debian Linux (64-bit), but I get the feeling that
many (if not most) users are on some version of Windows.

Thanks.

Best regards,

-Tom


os X 10.9 



Re: Unnecessary Large Memory Usage of Levenshtein Distance in Phobos

2014-05-22 Thread Max Klyga via Digitalmars-d
You should make a pull request with this implementation adapted to 
std.algorithm interface


On 2014-05-22 09:49:09 +, Nordlöw said:

I justd discovered that the std.algorithm implementation of Levenshtein 
Distance requires O(m*n) memory usage.


This is not neccessary. I have a C++-implementation of 
Damerau-Levenshtein that requires only O(3*min(m,n)). Is anybody 
interested in discussion modifying std.algorithm to make use of this?


Here's C++ implementation:


templateclass T inline void perm3_231(T a, T b, T c) {
 T _t=a; a=b; b=c; c=_t;
}
templateclass T inline pure bool is_min(const T a) {
 return a == pnw::minofT();
}
templateclass T inline pure bool is_max(const T a) {
 return a == pnw::maxofT();
}

templateclass T, class D = size_t
inline pure
D damerau_levenshtein(const T s_, const T t_,
   D max_distance = std::numeric_limitsD::max(),
   D insert_weight = static_castD(10),
   D delete_weight = static_castD(7),
   D replace_weight = static_castD(5),
   D transposition_weight = static_castD(3))
{
 // reorder s and t to minimize memory usage
 bool ook = s_.size() = t_.size(); // argument ordering ok flag
 const T s = ook ? s_ : t_; // assure \c s becomes the \em longest
 const T t = ook ? t_ : s_; // assure \c t becomes the \em shortest

 const D m = s.size();
 const D n = t.size();

 if (m == 0) { return n; }
 if (n == 0) { return m; }

 // Adapt the algorithm to use less space, O(3*min(n,m)) instead of O(mn),
 // since it only requires that the previous row/column and current 
row/column be stored at

 // any one time.
#ifdef HAVE_C99_VARIABLE_LENGTH_ARRAYS
 D cc_[n+1], pc_[n+1], sc_[n+1]; // current, previous and 
second-previous column on stack

#elif HAVE_CXX11_UNIQUE_PTR
 std::unique_ptrD[] cc_(new D[n+1]);  // current column
 std::unique_ptrD[] pc_(new D[n+1]);  // previous column
 std::unique_ptrD[] sc_(new D[n+1]);  // second previous column
#else
 auto cc_ = new D[n+1];  // current column
 auto pc_ = new D[n+1];  // previous column
 auto sc_ = new D[n+1];  // second previous column
 //std::vectorD cc_(n+1), pc_(n+1), sc_(n+1); // current, 
previous and second previous column

#endif
 D * cc = cc_[0], * pc = pc_[0], * sc = sc_[0]; // pointers for 
efficient swapping


 // initialize previous column
 for (D i = 0; i  n+1; ++i) { pc[i] = i * insert_weight; }

 // second previous column \c sc will be defined in second \c i 
iteration in outer-loop


 const auto D_max = std::numeric_limitsD::max();

 // Computing the Levenshtein distance is based on the observation 
that if we

 // reserve a matrix to hold the Levenshtein distances between all prefixes
 // of the first string and all prefixes of the second, then we can compute
 // the values in the matrix by flood filling the matrix, and thus find the
 // distance between the two full strings as the last value computed.
 // This algorithm, an example of bottom-up dynamic programming, is
 // discussed, with variants, in the 1974 article The String-to-string
 // correction problem by Robert A. Wagner and Michael J.Fischer.
 for (D i = 0; i  m; ++i) {
 cc[0] = i+insert_weight;
 auto tmin = D_max; // row/column total min
 for (D j = 0; j  n; ++j) {
 // TODO Use sub_dist
 //auto sub_dist = damerau_levenshtein(s[i], t[j]); // 
recurse if for example T is an std::vectorstd::string

 cc[j+1] = pnw::min(pc[j+1] + insert_weight, // insertion
cc[j] + delete_weight,   // deletion
pc[j] + (s[i] == t[j] ? 0 : 
replace_weight)); // substitution


 // transposition
 if (not is_max(transposition_weight)) { // if 
transposition should be allowed

 if (i  0 and j  0 and // we need at least two characters
 s[i-1] == t[j] and  // and first must be equal second
 s[i]   == t[j-1]// and vice versa
 ) {
 cc[j+1] = std::min(cc[j+1],
sc[j-1] + transposition_weight);
 }
 }

 if (not is_max(max_distance)) {
 tmin = std::min(tmin, cc[j+1]);
 }
 }

 if ((not is_max(max_distance)) and
 tmin = max_distance) {
 // if no element is smaller than \p max_distance
 return max_distance;
 }

 if (transposition_weight) {
 perm3_231(pc, cc, sc); // rotate pointers
 } else {
 std::swap(cc, pc);
 }
 }

#if !(defined(HAVE_C99_VARIABLE_LENGTH_ARRAYS) || 
defined(HAVE_CXX11_UNIQUE_PTR))

 delete [] cc_;
 delete [] pc_;
 delete []