On Friday, 27 December 2013 at 07:31:19 UTC, nazriel wrote:
On Friday, 27 December 2013 at 06:39:54 UTC, Ravn wrote:
Hi, I'm trying get the directory path and time at which the
compilation was made (not when the program is run), something
similar like this example in Haxe
Hello, here is simple pice of code to read text file into array
of lines:
import std.stdio;
void main(string args[]) {
auto file = File(args[1]);
auto frange = file.byLine();
char[][] buf;
foreach (char[] line; frange) {
buf = buf ~ line;
}
writeln(buf);
}
When
The solution is to append `line.dup` instead of `line`.
I guess this note in the documentation should be marked red:
Each front will not persist after popFront is called, so the
caller must copy its contents (e.g. by calling to!string) if
retention is needed.
On Friday, 27 December 2013 at 09:44:22 UTC, lomereiter wrote:
The solution is to append `line.dup` instead of `line`.
I guess this note in the documentation should be marked red:
Each front will not persist after popFront is called, so the
caller must copy its contents (e.g. by calling
Am Fri, 27 Dec 2013 10:24:15 +
schrieb Dfr defle...@yandex.ru:
On Friday, 27 December 2013 at 09:44:22 UTC, lomereiter wrote:
The solution is to append `line.dup` instead of `line`.
I guess this note in the documentation should be marked red:
Each front will not persist after
Am Fri, 27 Dec 2013 07:00:29 +
schrieb Rikki Cattermole alphaglosi...@gmail.com:
On Friday, 27 December 2013 at 05:00:30 UTC, Josh Phillips wrote:
I was wondering if people could suggest which libraries may be
best to use for building an application which would be a type of
text editor
On 12/27/13 04:23, David Eagen wrote:
void main()
{
string filename=aaa;
int inotfd = inotify_init();
int watch_desc = inotify_add_watch(inotfd, toStringz(filename),
IN_MODIFY);
size_t bufsiz = inotify_event.sizeof + PATH_MAX + 1;
inotify_event* event =
On Friday, 27 December 2013 at 08:57:02 UTC, Ravn wrote:
On Friday, 27 December 2013 at 07:31:19 UTC, nazriel wrote:
On Friday, 27 December 2013 at 06:39:54 UTC, Ravn wrote:
Hi, I'm trying get the directory path and time at which the
compilation was made (not when the program is run),
On 12/27/2013 03:51 AM, Lemonfiend wrote:
module main;
import std.stdio;
enum file = __FILE__;
enum time = __TIME__;
void main()
{
writeln(file);
writeln(time);
}
This works for me.
And the reason is D's CTFE: Anything that needs to be and can to be
evaluated at compile
On Friday, 27 December 2013 at 11:56:08 UTC, Ali Çehreli wrote:
However, __FILE__ happens to be the current source file that is
being compiled but I think the OP wants the current compilation
directory. Being a C library file, getcwd() does not work at
compile time:
import std.stdio;
void
Jonathan:
Thank you. In reply to [1]: that is an interesting issue that
I don't really understand right now. Can you explain exactly
where I invoke undefined behavior?
It can be shown with this function:
int*[] foo() {
int x;
int*[] arr = [x];
return arr;
}
Here the value
On Friday, 27 December 2013 at 03:39:58 UTC, Hugo Florentino
wrote:
BTW, it it a requirement to use malloc, and if so, when would I
need to free the memory allocated by it?
I use a static ubyte array.
I've been using inotify quite a bit and found it to be very good
but there are a few things
On 12/27/2013 05:54 AM, Jonathan wrote:
Thanks to everyone that has replied.
@Timon Gehr:
Thank you. In reply to [1]: that is an interesting issue that I don't
really understand right now. Can you explain exactly where I invoke
undefined behavior? It was my understanding that structs are
On Friday, 27 December 2013 at 10:56:55 UTC, Artur Skawina wrote:
You probably meant
read(inotfd, event, (*event).sizeof);
but in this case the inotify_event structure contains an
optional
trailing buffer, so it should be
read(inotfd, event, bufsiz);
artur
Yes, thanks for the
Timon Gehr:
mixin ADT!q{ Term: Var char | Op char Term[] };
void main(){
const expr = Op('f', [Op('g',[Var('x'), Var('y')]),
Op('a',[]), Var('x')]);
}
Where is ADT defined? (And why isn't it a Phobos patch on GitHub?)
convertNum could be written more compactly as:
char
On 12/27/13 14:28, David Eagen wrote:
I had trouble getting the file name from the event. I think it's because the
inotify module has name defined as char[0]. So I did this, which prints the
name by using the extra data beyond the inotify_event struct itself:
void* buf =
Quick question.
(1) I can do
n.iota.map!(_ = readln)
to get the next n lines from stdin.
(2) However, when I do
readln.repeat(n)
it looks clearer but works differently: preserves front and reads
only one line.
(3) In the particular case of readln, we can substitute it with
On 2013-12-23 12:20, Benjamin Thaut wrote:
Yes it would, but then I would have to define some mangling for myself.
You can do something like this:
void foo ();
extern (C) pragma(mangle, foo.mangleof) void foo () { }
I'm pretty sure you remove the duplication with a mixin.
--
/Jacob
On 2013-12-27 08:00, Rikki Cattermole wrote:
There is also DQuick and DWT.
DWT [1] has OpenGL support as well. Here's a snippet that uses DWT and
OpenGL:
https://github.com/d-widget-toolkit/org.eclipse.swt.snippets/blob/master/src/org/eclipse/swt/snippets/Snippet195.d
[1]
Yes, just like what Ali said above,
__FILE__, __DATE__ and __TIME__ do work for their respective usages,
but I'm also looking for a way to get the current compilation directory
during compile time, and getcwd() doesn't seem to be working.
Isn't there something like __DIR__ or __PATH__ that I
Am Fri, 27 Dec 2013 14:26:59 +
schrieb Ivan Kazmenko ga...@mail.ru:
Quick question.
(1) I can do
n.iota.map!(_ = readln)
to get the next n lines from stdin.
(2) However, when I do
readln.repeat(n)
it looks clearer but works differently: preserves front and reads
only one line.
Am Fri, 27 Dec 2013 12:43:15 +
schrieb Ravn ravnd...@gmail.com:
On Friday, 27 December 2013 at 11:56:08 UTC, Ali Çehreli wrote:
However, __FILE__ happens to be the current source file that is
being compiled but I think the OP wants the current compilation
directory. Being a C library
On 2013-12-27 16:23, Marco Leise wrote:
No, but if you just want the path where your sources are you
could use __FILE__ for any module and cut off the part of
it that belongs to the module path. A lot of Phobos works at
compile time, so you might be able to write a one-liner for
that.
That
Am Fri, 27 Dec 2013 13:45:10 +
schrieb bearophile bearophileh...@lycos.com:
Timon Gehr:
mixin ADT!q{ Term: Var char | Op char Term[] };
void main(){
const expr = Op('f', [Op('g',[Var('x'), Var('y')]),
Op('a',[]), Var('x')]);
}
Where is ADT defined? (And why isn't it a
On 12/27/2013 02:45 PM, bearophile wrote:
Timon Gehr:
mixin ADT!q{ Term: Var char | Op char Term[] };
void main(){
const expr = Op('f', [Op('g',[Var('x'), Var('y')]), Op('a',[]),
Var('x')]);
}
Where is ADT defined?
https://d.puremagic.com/issues/show_bug.cgi?id=10431
(And why isn't
Let me just check my understanding: If a function says it
returns a thing of type T, it really does return something whose
outermost shape is T; however, if it contains pointers to other
things, and these were stack allocated, the pointers might be
readdressed.
@Bearophile: in your example,
On Fri, 27 Dec 2013 12:56:25 +, Gary Willoughby wrote:
On Friday, 27 December 2013 at 03:39:58 UTC, Hugo Florentino wrote:
BTW, it it a requirement to use malloc, and if so, when would I need
to free the memory allocated by it?
I use a static ubyte array.
I've been using inotify quite a
On Friday, 27 December 2013 at 00:23:58 UTC, Jonathan wrote:
I come from Haskell, so please excuse any functional
programming idiosyncracies I have :)
In Haskell, I have a datatype for representing so called terms
which looks like:
data Term = Var Char | Op Char [Term]
i.e. a Term is a
Found your other post nwm.
Timon Gehr:
https://d.puremagic.com/issues/show_bug.cgi?id=11558
We are getting there :-)
but implying that you are somehow ethically superior and that I
am not human seems to go a little far. :o)
Sorry. In my opinion that kid of code is not very readable,
spaces help to eye to chunk
On 12/27/13 15:13, Artur Skawina wrote:
struct MyInotifyEvent(size_t BS) {
inotify_event event;
char[BS] buffer;
alias event this;
}
[...]
enum bufsiz = inotify_event.sizeof + PATH_MAX + 1;
auto event = cast(MyInotifyEvent!bufsiz*)malloc(bufsiz);
[...]
On 12/27/2013 05:08 PM, Jonathan wrote:
Let me just check my understanding: If a function says it returns a
thing of type T, it really does return something whose outermost shape
is T; however, if it contains pointers to other things, and these were
stack allocated, the pointers might be
On Friday, 27 December 2013 at 16:08:09 UTC, Jonathan wrote:
Let me just check my understanding: If a function says it
returns a thing of type T, it really does return something
whose outermost shape is T; however, if it contains pointers to
other things, and these were stack allocated, the
On 12/27/2013 06:26 AM, Ivan Kazmenko wrote:
n.iota.map!(_ = readln)
to get the next n lines from stdin.
So, what I ask for is some non-caching repeat for functions with side
effects. More idiomatic than (1).
This request comes up once in a while.
Is there something like that in Phobos?
On Friday, 27 December 2013 at 15:23:37 UTC, Marco Leise wrote:
No, but if you just want the path where your sources are you
could use __FILE__ for any module and cut off the part of
it that belongs to the module path. A lot of Phobos works at
compile time, so you might be able to write a
On Friday, 27 December 2013 at 15:15:31 UTC, Jacob Carlborg wrote:
You can use this ugly hack:
Create a shell script with the following content.
#!/bin/bash
echo `pwd` dir.txt
dmd main.d -J.
And the D source code:
module main;
enum compilePath = import(dir.txt);
pragma(msg, compilePath);
On 2013-12-27 19:14, Ravn wrote:
I need the absolute path __FILE__ during compile time,
so far the only way I know to get absolute paths is by using
std.path.absolutePath (which uses getcwd() as its base) and getcwd()
itself (which doesn't seem to work during compile time).
Is there any
Thanks Ali. Stupid of me, it is the dirEntries call that opens
the directory and tries to read contents. I did this (below), but
it still leaves the odd situation that Documents and Settings
cannot be opened, and surely non-administrators have access to
this folder.
try{
auto dirs =
On Friday, 27 December 2013 at 19:35:23 UTC, Jacob Carlborg wrote:
On 2013-12-27 19:14, Ravn wrote:
__FILE__ will return the full path (absolute path) of the file
currently compiling. But that is not the same thing as getting
the path to where the compilation was made.
Eh, it does? :-?
It
On Friday, 27 December 2013 at 18:32:29 UTC, Jakob Ovrum wrote:
(1) I can do
n.iota.map!(_ = readln)
to get the next n lines from stdin.
This has several issues:
* The result claims to have all kinds of range capabilities
that don't make sense at all. Attempting to actually use these
On Friday, 27 December 2013 at 20:30:52 UTC, Ivan Kazmenko wrote:
On Friday, 27 December 2013 at 18:32:29 UTC, Jakob Ovrum wrote:
If repeat could know whether its first argument is pure, it
could then enable or disable front caching depending on
purity... no way currently?
`readln.repeat(n)`
I'm writing a compiler that uses Pegged for parsing D code.
Pegged is fed a string with a special grammar syntax and changes
it into templated D code, which is in turn mixed in. Even with
just a small subset of D, Pegged currently produces 4000 lines of
dense code, and it consumes enough time
On Saturday, December 28, 2013 01:08:37 Casper Færgemand
shortt...@hotmail.com@puremagic.com wrote:
I'm writing a compiler that uses Pegged for parsing D code.
Pegged is fed a string with a special grammar syntax and changes
it into templated D code, which is in turn mixed in. Even with
just
import std.algorithm;
import std.stdio;
import std.conv;
class Trivial
{
int sideEffect() { return n++; }
override string toString() pure { return to!string(n); }
int n;
}
void main()
{
Trivial[] objs = [ new Trivial ];
map!(o = o.sideEffect())(objs);
writeln(objs);
On Saturday, 28 December 2013 at 01:41:35 UTC, David Held wrote:
Can someone explain to me why map() is not equivalent to
foreach in the code above? From what I can tell, map() doesn't
do anything at all on objs, even though it is a perfectly
legitimate range (as far as I can tell).
map()
On 12/27/2013 5:46 PM, David Nadlinger wrote:
On Saturday, 28 December 2013 at 01:41:35 UTC, David Held wrote:
Can someone explain to me why map() is not equivalent to foreach in
the code above? From what I can tell, map() doesn't do anything at
all on objs, even though it is a perfectly
On Saturday, 28 December 2013 at 01:41:35 UTC, David Held wrote:
import std.algorithm;
import std.stdio;
import std.conv;
class Trivial
{
int sideEffect() { return n++; }
override string toString() pure { return to!string(n); }
int n;
}
void main()
{
Trivial[] objs = [ new
import std.stdio;
void test(T)()
if (is (T : float))
{
writeln(typeid(T));
}
void main()
{
test!int;
}
When I run this I am getting the output int
My understanding of template constraints is that the call to
test!int will not find a match since the function test only
On Saturday, 28 December 2013 at 02:27:00 UTC, Ross Hays wrote:
import std.stdio;
void test(T)()
if (is (T : float))
{
writeln(typeid(T));
}
void main()
{
test!int;
}
When I run this I am getting the output int
My understanding of template constraints is that the call
Am Fri, 27 Dec 2013 20:14:00 +
schrieb Ravn ravnd...@gmail.com:
Tried enum path = dirName(__FILE__), compiles normally, no error
from the compiler, but it still returns a relative path instead
of a fullpath in my machine.
Too bad :-/
I hoped it would use absolute paths.
--
Marco
Am Fri, 27 Dec 2013 20:34:02 +
schrieb Ivan Kazmenko ga...@mail.ru:
Maybe the imperative should be repeat is a function, and
arguments of functions should be evaluated only once? It does
make sense from a language point of view, but somewhat breaks the
abstraction for me.
The
On Saturday, December 28, 2013 02:31:56 Ross Hays wrote:
Okay figured it out actually. If you are not going to allow
implicit conversion the appropriate constraint is...
if (is (T == float))
If you want to accept any floating point type but not implicit conversions,
then use
Am Sat, 28 Dec 2013 01:54:26 +
schrieb John Colvin john.loughran.col...@gmail.com:
On Saturday, 28 December 2013 at 01:41:35 UTC, David Held wrote:
import std.algorithm;
import std.stdio;
import std.conv;
class Trivial
{
int sideEffect() { return n++; }
override
If you want to accept any floating point type but not implicit
conversions,
then use std.traits.isFloatingPoint.
Thank you that's good to know. Though for this particular example
I was just making a basic demo of the problem.
54 matches
Mail list logo