I get an error message when trying to curl
Error output:
root@02x110:~/Desktop# gdc a.d -o a
a.d:2: Error: module curl is in file 'std/net/curl.d' which
cannot be read
import path[0] = /usr/include/d2/4.6/i486-linux-gnu
import path[1] = /usr/include/d2/4.6
My Code:
import std.net.curl;
impor
On Thursday, 11 July 2013 at 13:46:48 UTC, Johannes Pfau wrote:
Am Thu, 11 Jul 2013 15:29:09 +0200
schrieb "Ali" :
/usr/include/d2/4.6
This looks like you're using a very old gdc version.
std.net.curl was
added in 2.058.
How do I update? Searched, but could not find it.
On Thursday, 11 July 2013 at 14:44:23 UTC, H. S. Teoh wrote:
On Thu, Jul 11, 2013 at 04:36:42PM +0200, Ali wrote:
On Thursday, 11 July 2013 at 13:46:48 UTC, Johannes Pfau wrote:
>Am Thu, 11 Jul 2013 15:29:09 +0200
>schrieb "Ali" :
>
>>/usr/include/d2/4.6
>
>This
ut the better solution before sending this message:
foreach (e; __traits(allMembers, E)) {
writeln(e);
}
The difference is, the type of 'e' is string above. Finally, the
following produces integer values:
foreach (e; __traits(allMembers, E)) {
writeln(to!E(e));
}
Ok, good... :)
Ali
ere, separating (and sequencing) two expressions:
1) i
2) x[i] = 1
> assert(x == [1, 0]); // OK
>
> int j;
> int[2] y;
> y[j], j = 1;
Again, two expressions:
1) y[j]
2) j = 1
Only the second of both cases have an effect.
Ali
> assert(y == [0, 0]); // No
On 02/25/2011 05:09 PM, bearophile wrote:
> int j;
> int[2] y;
> y[j] = j = 1;
I think that's undefined behavior in C and C++. It is not defined
whether j's previous or past value is used in y[j].
I would expect the situation be the same in D.
Ali
On 02/25/2011 06:10 PM, Jonathan M Davis wrote:
On Friday, February 25, 2011 17:31:36 Ali Çehreli wrote:
On 02/25/2011 05:09 PM, bearophile wrote:
> int j;
> int[2] y;
> y[j] = j = 1;
I think that's undefined behavior in C and C++. It is not defined
whethe
first instantiation?
Thanks in advance,
Tom;
That's because the type of literals like [1, 2] are slices (dynamic
arrays), not fixed-sized arrays.
import std.stdio;
void main()
{
writeln(typeof([1,2]).stringof);
}
The output of that program is
int[]
Ali
3/01/2011 04:30 AM, bearophile wrote:
> Ali Çehreli:
>
>> That's because the type of literals like [1, 2] are slices (dynamic
>> arrays), not fixed-sized arrays.
>
> Then why is this accepted?
>
> foo!int([[1,2],[3,4],[5,6]]); // OK
If I have to guess, I think sup
an be very
powerful:
http://digitalmars.com/d/2.0/template.html#TemplateAliasParameter
Ali
stMember(1, new C); // now compiles
}
Ali
On 03/02/2011 11:11 PM, Peter Lundgren wrote:
> == Quote from Ali Çehreli (acehr...@yahoo.com)'s article
>> On 03/02/2011 08:56 PM, Peter Lundgren wrote:
>>> Where can I go to learn about parameterized structs? I can't seem
to find any
>>> literature on the
statically
initialized at compile time, and the value argument can be any
expression which can be evaluated at compile time. This includes
integers, floating point types, and strings.
Ali
On 03/03/2011 03:25 AM, bearophile wrote:
Ali Çehreli:
Template value parameter types can be any type which can be statically
initialized at compile time, and the value argument can be any
expression which can be evaluated at compile time. This includes
integers, floating point types, and
Huh. Cool. Works like a charm. Seems cleaner like the opBinaryRight
solution, really. I just didn't know of it :)
It can be seen on the D1 documentation:
http://www.digitalmars.com/d/1.0/operatoroverloading.html
That is (or "will be") deprecated in D2.
Ali
eviceType] execDeviceSuffix;
>
> static this()
> {
>execDeviceSuffix[deviceType.cpu] = "cpu";
>execDeviceSuffix[deviceType.gpu] = "gpu";
> }
This works too:
static this()
{
execDeviceSuffix = [deviceType.cpu:".cpu", deviceType.gpu:".gpu"];
}
Ali
compile time:
static if (isNumeric!SomeType)
It doesn't work with string values. Although unnecessary, you could do this:
bool test = isNumeric!(typeof(args[0]));
Ali
ou want to confuse yourself (and me):
ss.reserve(5); // same thing as above
foreach (ref s; ss)
s = S(1, 2);
return 0;
}
Ali
On 03/08/2011 02:03 PM, Steven Schveighoffer wrote:
> it's not std.array.reserve, it's object.reserve, always present, no need
> to import.
Thanks. The reserve that I found in array.d is
std.array.Appender(T).reserve.
Ali
{
return value << 24
| (value & 0xFF00) << 8
| (value & 0x00FF) >> 8
| value >> 24;
}
}
There is also std.intrinsic.bswap
Ali
though you would have to remember to call it for each file I/O operation
that relies on it. If you use a struct, you could
ke(recurrence!("a[n-1] + a[n-2]")(0L, 1L), n);
}
void main()
{
long[] data = [ 0, 1, 1, 2, 3, 5, 8 ];
foreach (n; 0 .. data.length) {
assert(equal(declarative(n), data[0..n]));
}
}
Ali
ollar] not implemented
The following doesn't work either:
auto result = v1[] + v2[];
auto result = v1 + v2;
dmd does not implement those features yet.
Ali
On 03/12/2011 02:52 PM, Ali Çehreli wrote:
On 03/12/2011 10:42 AM, Caligo wrote:
struct Test{
public double[3] ar_;
this(double[3] ar){
this.ar_ = ar;
}
}
void main(){
double[3] v1 = [1.0, 2.0, 3.0];
double[3] v2 = [2.0, 3.0, 4.0];
auto t1 = Test(v1[0..$] + v2[0..$]); // error
}
I want
name? ");
string name = readln();
writeln("Hi ", name, "!");
}
The newline character is read as a part of the input:
What is your name? Ali
Hi Ali
! <-- this is outputted on the next line
because of the newline character
A solution is to strip the line
On 03/16/2011 05:49 AM, Kagamin wrote:
Ali ǥhreli Wrote:
The following program may be surprising to the novice:
import std.stdio;
void main()
{
write("What is your name? ");
string name = readln();
writeln("Hi ", name, "!");
}
What if the u
tr != s0.ptr);
assert(s2.ptr != s1.ptr);
}
I forgot the name of the feature. Basically, no slice (aka dynamic
array) can extend into other elements and starts sharing them.
Ali
he file must have a well defined format. It is
not possible to insert or remove bytes from a file due to low level
reasons. The file systems that I am aware of don't provide such interfaces.
And writing after fseek would overwrite existing data.
Like Jonathan M Davis said, the best is to read from the source and
write to the destination.
Ali
ks to the C (and C++) heritage, there is no guarantee that
there is a keyboard around. The interface is stdin, stdout, and stderr;
which are just character streams.
But I agree: some subset of ncurses would be nice when a keyboard is
available.
>
> Bye,
> bearophile
Ali
tp://groups.google.com/group/comp.os.linux.development.apps/
>> browse_thread/thread/0667d16089e2b6fc
>>
>
> H mentions using tcgetattr to save old state and restoring it with
> tcsetattr. This is what this code does. Btw this code is not mine,
> Walter posted it and I just added the cfmakeraw prototype. So kudos
> goes to him.
Thanks for posting this.
It can be improved by moving the last tcsetattr to an earlier
scope(exit) statement:
termios ostate;
tcgetattr(1, &ostate);
scope (exit) tcsetattr(1, TCSADRAIN, &ostate);
Ali
somebody please point out the
> error of this code?
I would really love to look at it but like some other people all I get
is the following non-D code. ;) I don't know whether the problem is on
my end but e-mail and news used to be easier. :)
Ali
> begin 644 main.d
> M;6]D=6QE(&UA:6X[#0H-"FEM<&]R="!S=&0N M*'-T
ensible thing to do at that
level: log an error, skip that operation, go back to the user with an
error code, take corrective action, etc.
Disclaimer: That is what I follow in C++ code. I don't have experience
with exception safety in D. I don't know issues that may be specific to D.
Ali
> I'm not sure D's exceptions are much different than C++'s.
Yeah, it must be the same as what Digital Mars C++ compiler uses.
(Except, D also has the 'finally' clause.)
In summary: I hope I will never go back to pass-the-error-code style of
coding.
Ali
On 03/30/2011 12:40 PM, Jonathan M Davis wrote:
On 2011-03-30 05:09, spir wrote:
On 03/30/2011 05:32 AM, Ali Çehreli wrote:
On 03/29/2011 03:40 PM, Kai Meyer wrote:
I was given two words of advice on exceptions:
"Use exceptions for the exceptional"
"Use exceptio
rType, T)
{
// Instantiate the 'template template parameter'
ContainerType!T member;
}
void main()
{
Foo!(SomeContainer, double) foo1;
Foo!(SomeOtherContainer, int) foo2;
}
ContainerType is a template parameter of Foo and is itself a template.
And 'alias' seems to work...
Ali
td.stdio;
struct Box(T, int width, int height)
{
void Fun(T2, int width2, int height2)(Box!(T2, width2, height2) b)
{
writeln(width2, ' ', height2);
}
}
void main()
{
auto b1 = Box!(double, 2, 7)();
auto b2 = Box!(double, 3, 4)();
b1.Fun(b2);
}
Ali
iciency of the D GC it's better to reduce memory
allocations as much as possible.
> Here join() creates a brand new array, so idup performs a useless
copy. To avoid this extra copy do I have to write another joinString()
function?
>
> Bye,
> bearophile
Ali
d:
immutable(T)[] assumeUnique(T)(ref T[] array) pure nothrow
{
auto result = cast(immutable(T)[]) array;
array = null;
return result;
}
And that fails as join's return type is not an lvalue.
We need a simplyAssumeUnique() that doesn't null the reference parameter
:); and it would have no value over casting other than communicating the
intent.
Ali
On 04/07/2011 01:04 AM, spir wrote:
> On 04/07/2011 09:52 AM, spir wrote:
>> On 04/07/2011 03:07 AM, Ali Çehreli wrote:
>>>> Given an array of strings std.string.join() returns a single string:
>>>>
>>>> import std.string;
>>>> void mai
om D. They are deprecated in favor of a "range"
interface. std.range and std.algorithm have examples of ranges that are
first introduced in this article (with different names in Phobos):
http://www.informit.com/articles/printerfriendly.aspx?p=1407357
Ali
mean what is already in D, I mean those streams are gone from D. I
shouldn't need to disclaim that some module in the future may be related
to streams.
2) Streams that are currently present in D are deprecated in favor of a
new interface that will use ranges, or be ranges.
3) The seminal paper that I linked above is it.
Ali
Linux Programmer's Manual
STDIN(3)
NAME
stdin, stdout, stderr - standard I/O streams
SYNOPSIS
#include
Ali
the case of non-random access ranges.
Ali
declaration
Limitations are caused by bug, that is going to get fixed eventually ;)
Ali
p);
count = 0;
}
Thread.sleep( dur!("msecs")(100) );
}
}
I hope those bugs get squashed so I can have more fun with these ranges. :)
Ali
On 05/07/2011 09:07 PM, Andrej M. wrote:
I want to turn this:
auto arr = [1, 1, 2, 3, 4, 4];
into this:
auto arr2 = [[1, 1], [2], [3], [4, 4]];
I want an array of arrays of the same elements. Lazy or not, I don't care.
I thought I could get away with this inside some while loop:
auto equals =
ue is common. Here, the decision is the safer one.
Only when we know what we're doing, we can change this behavior.
> If I am not mistaken, in C++/Java. They will choose the most bottom up
> closes parameter type signature match.
Not in C++. C++ has "name hiding", which hides all of base's functions
and members with the same name.
Ali
ve been
in a single module.
Ali
top of the page. That is linked to
the class page.)
Ali
On 06/02/2011 08:51 AM, Guillermo Estrada wrote:
The exec* family of functions cause the new app to replace the
current process. So after the execv, the loop doesn't exist.
Any way to spawn the process without killing himself?
Would std.process.system or std.process.shell work?
Ali
On 06/03/2011 10:15 AM, Andrej Mitrovic wrote:
> Offending line in map:
> alias typeof(_fun(.ElementType!R.init)) ElementType;
The fact that the error points at that line should be a bug. That's just
an alias, nothing is evaluated at that line.
Ali
one
intermediate done
0 foo
1 foo
2 foo
3 foo
4 foo
Is the inconsistency a bug or a natural consequence of something? :)
(Perhaps even the first example that seems to run correctly just has a
higher probability of showing this behavior.)
I am aware of thread_joinAll(). Is that the recommended way of waiting
for all threads?
Thank you,
Ali
On 06/06/2011 12:07 PM, Steven Schveighoffer wrote:
On Mon, 06 Jun 2011 14:09:25 -0400, Ali Çehreli wrote:
First, the answer may be as simple as "use
core.thread.thread_joinAll". Is that the proper way of waiting for all
threads?
main (the C main, not D main) does this alrea
lts as well:
http://d.puremagic.com/issues/show_bug.cgi?id=6116
Ali
all of the negative feedback that you've listed.
Ali
.stdio;
import std.range;
enum a = [1, 2, 3];
auto range = cycle(a[]);
void main()
{
foreach (i; 0 .. 2) {
foo();
}
}
void foo()
{
foreach(i; 0 .. 5) {
writeln(range.front);
range.popFront();
}
}
Ali
nt count = 1)
{
direction_ += count;
direction_ %= Direction.sizeof;
}
void rotateLeft(int count = 1)
{
rotateRight(-count);
}
@property Direction direction() const
{
return direction_;
}
}
Ali
But anyway... How do you solve the problem of deciding the return type of
such functions?
Thank you,
Ali
On Tue, 21 Jun 2011 23:02:43 +, Jonathan M Davis wrote:
> On 2011-06-21 15:25, Ali Çehreli wrote:
>> (Note: I have a feeling that this must be related to the old 'unique'
>> discussions, which I had somehow managed to stay out of. If so, I
>> apologize for rep
On Tue, 21 Jun 2011 19:04:11 -0400, bearophile wrote:
> Ali Çehreli:
>
>> char[] result = foo();
>> string immutable_result = assumeUnique(result);
>>
>> But that's the wrong thing to do, as foo() may be changed in the future
>> to return a non
he function returns string
> rather than char[].
No. In the above code there is no need for a copy because the returned
string is actually mutable. But the caller must make a copy because of
not being certain whether the returned string is really mutable or
immutable.
> - Jonathan M Davis
Ali
On Wed, 22 Jun 2011 00:02:55 +, Ali Çehreli wrote:
> I wonder whether a UniqueRef object could be returned, which could allow
> a single casting of its data to mutable or immutable at the call site.
> Further casts could throw, but that would be a runtime solution. :-/
An extrem
ring;
void main()
{
float MyFloat;
readf(" %s", &MyFloat);
writeln(MyFloat);
readf(" ");
string MyString = chomp(readln());
writeln(MyString);
}
Ali
On Wed, 22 Jun 2011 15:58:02 +, Timon Gehr wrote:
> On Wed, 22 Jun 2011 00:02:55 +0000, Ali Çehreli wrote:
>
>> I wonder whether a UniqueRef object could be returned, which could
>> allow a single casting of its data to mutable or immutable at the call
>> site. Furthe
27; always means "new line" to be replaced with each
platform's correct code sequence.
Ali
is that is being (is?) deprecated. It reads simpler like
writeln:
import std.cstream;
void main()
{
double d;
int i;
din.readf(&d, &i);
dout.writefln("d: %s, i: %s", d, i);
}
It would still be problematic with strings. How many characters should be
a part of it?
Ali
;oku" means "read":
// Read into an existing variable
double d;
oku("Please enter a double: ", &d);
// Read and return a value
int i = oku!int("Please enter an int: ");
Ali
On Wed, 22 Jun 2011 13:45:56 -0500, Jimmy Cao wrote:
> On Wed, Jun 22, 2011 at 1:31 PM, Ali Çehreli wrote:
>
>> On Wed, 22 Jun 2011 20:17:39 +0200, Andrej Mitrovic wrote:
>>
>> > This library has some nice user-input methods for D2:
>> > https://github
art();
foreach(i, ref elem; parallel(logs)) {
elem = log(i + 1.0);
}
writeln(stopWatch.peek().msecs);
}
}
Here is my output:
CPUs : 4
8061
2686
I get similar results whether I pass 100_000 to parallel() or not.
Ali
hould
be safe:
foreach (key; aa.keys) {
aa.remove(key);
}
Ali
Node!(MyList, double, char) node2;
}
void main()
{}
But I hit other compilation problems in Algebraic, which I believe to be
const-correctness issues.
Also consider looking at Phobos ranges. Instead of templatizing on the
container type, templatizing on the range type may be better.
Ali
sizes do include the
padding bytes. The following class has the very odd size of 17! Is that
by design?
class C
{
char c;
}
void main()
{
assert(__traits(classInstanceSize, C) == 17);
}
Ali
y-paste mistake, right? You don't want create() before
reading. You must have meant open:
open( fileName );
It works with that change.
> read( verStr2 ); read( ver2 ); // version
> }
> writeln( verStr, ver );
> }
>
> And this is the result:
> std.stream.ReadException@std\stream.d(46): Stream is not readable
>
> - Joel
Ali
fout.close;
You are not supposed to need to close the File object yourself. Being a
struct, its destructor should be called automatically.
Ali
On Wed, 29 Jun 2011 10:47:39 -0400, Steven Schveighoffer wrote:
> On Wed, 29 Jun 2011 01:42:37 -0400, Ali Çehreli
> wrote:
>> On a related note, why doesn't __traits(classInstanceSize, T) consider
>> the padding bytes? If I'm not mistaken struct sizes do inclu
dn't call any destructors.
>
> -Steve
Thank you very much for all the heads up. Luckily we don't need to deal
with these issues in daily programming.
Ali
sTid);
}
void main()
{
writeln("owner's thisTid : ", &thisTid);
Tid worker = spawn(&workerThread, thisTid);
}
Interestingly the two variables will have the same address but they are
not equal as the assert above passes:
owner's thisTid : 46B58C
worker's thisTid: 46B58C
Ali
ot only handy for referring to parts of other arrays, but for
converting pointers into bounds-checked arrays:
int* p;
int[] b = p[0..8];
For strings (actually arrays), you would need .length and .ptr properties.
I've never used it but you might want to consider the serialization
library Orange as well:
http://www.dsource.org/projects/orange
Ali
ld be
different if it were ubyte* or void*.
Ali
ne another just
by having different addresses. The following array's data will occupy 10
bytes:
S[10] objects;
assert(&(objects[0]) != &(objects[1]));
Ali
std.range;
// ...
ElementType!Range front_or_null(Range)(Range range)
{
return range.empty ? null : range.front;
}
The template constraint has proven to be problematic though. I will open
a separate thread about that.
Ali
On Sun, 03 Jul 2011 20:07:43 +, Ali Çehreli wrote:
> import std.range;
>
> // ...
>
> ElementType!Range front_or_null(Range)(Range range) {
> return range.empty ? null : range.front;
> }
>
> The template constraint has proven to be problematic though. I wi
tring(1.5);
Error: template instance S is not a template declaration, it is a struct
And if I try to be smart after the error message, this seg faults the
compiler:
auto o = S.__ctor!string(1.5);
Ali
On Tue, 05 Jul 2011 16:20:44 +0200, Loopback wrote:
> On 2011-07-05 03:11, Ali Çehreli wrote:
>> struct S
>> {
>> this(T)(double d)
>> {}
>> }
>>
>> void main()
>> {
>> auto o = S(1.5);
>> }
>>
>&
hink a short vs int would make a difference when it comes to
indexing (it shouldn't anyway).
>
> -Steve
Ali
On Mon, 08 Aug 2011 20:32:03 +, Ali Çehreli wrote:
>> the point is, the compiler has no idea what the lvalue expression's
>> type should be when you do:
>>
>> a[x] = 1;
>>
>> is it short or int?
>>
>> so the compiler must *know* what
lue;
}
}
Notes:
- I had to give buffers[] to parallel() as it calls popFront() which my
constant-size array can't provide. (Yes, I could have used a dynamic
array.)
- Note the three ref's that I used; two of those are because constant-
size arrays are value types.
Ali
On Tue, 09 Aug 2011 20:37:04 +, Ali Çehreli wrote:
>> I wonder if I could:
>> Create a thread (task)
>> Read bytes directly into the tasks' thread local storage Execute the
>> thread
>
> I don't know what copies happen behind the scenes in the follo
tion and the code above it make absolutely no sense to me. The
> intention would be more clear if there was an error message, or any
> documentation of the implementation, but no dice.
Ali
I want to
> add another int as a parameter), I'll have to change all the ctors in
> the subclasses as well.
>
> Isn't that counterproductive?
Sounds like it but is necessary: Which of the constructors of the derived
constructors should the compiler call after calling super's matching one?
If it didn't, the derived parts would be left unconstructed.
Ali
;false', but
// we can use c here when it evaluates to 'true'.
// e.g. if it's a pointer:
writeln(*c);
}
Ali
}
}
void main()
{
auto some = CustomStruct();
some.attribute = [ 1, 2, 3 ];
}
Ali
or clear() over the deprecated delete.
delete used to destroy the object give the memory back. clear just calls
the destructor. The idea is that the programmer shouldn't have much say
on a new'ed object's memory.
I think the thought was, if the programmers really car
/// Ditto
auto ref opIndex(size_t index)
{
return _source[_indices[index]];
}
// ...
}
> assert(data == [7, 0, 5, 4, 3, 2, 1, 6]);
> }
>
>
> Bye and thank you,
> bearophile
It's unfortunate that template the error messages cannot be more
helpful. :-/
Ali
sign and even the names of range types have changed
since that article has been written.
These and other Phobos modules make use of ranges:
http://www.d-programming-language.org/phobos/std_range.html
http://www.d-programming-language.org/phobos/std_algorithm.html
http://www.d-programming
tion status
of the program to the environment that started it:
int main()
{
return 0;
}
Ali
is useless at
best, but here is a workaround:
Foo opBinary(string op) (Foo rhs)
if (op == "+" || op == "-")
{
writeln("My type: ", Foo.stringof);
return Foo();
}
Within the template definition, the name of the template alone means
"that particular instantiation of the template".
Ali
{
> TTest test;
test is null. This works:
auto test = new TTest();
> test.Info!(uint)("one");
> }
>
> When compiling no errors. But when I try to run a program there is an
> error: object.Error: Access Violation
> ----
> 426348
> 4261BF
> 402023
> 404C5B
> 404857
> 455789
>
Ali
ias Vector!(double, 3) Vec3D;
void main()
{
auto v2d = new Vec2D(2.2, 2.2);
auto v3d = new Vec3D(3.3, 3.3, 3.3);
// Alternatively, all parameters at once:
auto v3d_too = new Vec3D([ 33, 33, 33, ]);
}
(Some would find 'size_t N' to be more appropriate since N is a
dimension.)
Ali
On Sat, 08 Oct 2011 03:52:25 -0700, Roderick Gibson wrote:
> On 10/7/2011 11:35 PM, Ali Çehreli wrote:
>> On Fri, 07 Oct 2011 18:29:26 -0700, Roderick Gibson wrote:
>>
>>> This may be the completely wrong approach, but I am basically thinking
>>> of something li
ange.back
- myRange[i]
> as well as p[1] or
Only with RandomAccessRanges.
> p[-1] with ranges.
That should be considered out of bounds with ranges, but it is possible
to achieve with opIndex() for RandomAccessRanges.
Ali
P.S. I am in the process of translating my Turkish D book to Engli
1 - 100 of 2184 matches
Mail list logo