I am trying to compile next code:
import std.net.curl;
import std.stdio;
void main()
{
writeln(get(https://google.com/;));
}
and got next error
http://www.everfall.com/paste/id.php?y37dr6qmu54h
I have got same error. I need to pass in instance of class
constant, but got error Error: static variable cannot be read
at compile
http://www.everfall.com/paste/id.php?1mc9mb9cxyie
When I had create instance of class in main, and create
confvarible above it all worked, but when I had moved
Thanks! But is there any other solution? I am thinking that I am
trying to specify config name by wrong way...
I am tying to hardcode name of config file name. Then I would
read and parse it.
I am trying to write simple parser, that split text to
key value
name = david
lastname = wood
here is my code:
foreach (line; readText(confname).splitLines())
{
writeln(line);
foreach (str; split(line, =))
DFL is really cool. Not all programmers need complex toolkits. A
lot of need easy to learning toolkits for medium projects.
It would be cool if somebody will handle developing of DFL. It's
better to have one such toolkit, than tons of complex and not
finished toolkits.
A lot of developers will say thanks if you help with developing
DGUI https://bitbucket.org/dgui/dgui/
D very need native and easy to use GUI lib...
void main()
{
auto result = readconfig();
foreach (_; result)
{
// I want to iterate result that I got from structure.
}
}
auto readconfig()
{
struct ConfigStruct
{
string key1;
string key2;
foreach (field; result.tupleof)
Why I should here specify type of iterable element, but not first
element that I use for iteration?
I mean:
foreach (_some_type_possible_enum_ field; result)
?
bool[4] x = [1, 1, 0, 0];
BitArray ba = BitArray(x);
When I try to compile this I am getting error:
source\app.d(13): Error: cannot implicitly convert expression (x)
of type bool[4] to uint
What I am doing wrong?
How can I feel struct with foreach loop?
struct ConfigStruct
{
string [string] key1;
string [string] key2;
}
ConfigStruct confstruct;
foreach (i, line; readText(ConfigName).splitLines())
{
string [] keyvalue = line.split(=);
confstruct.key1[keyvalue[0]] = keyvalue[1];
}
it's ok for 1
Is it's possible to change dub package cache dir?
Already 1 hour I am looking at example from
http://ddili.org/ders/d.en/concurrency.html and my modification
of it, and can't understand what's difference? Why it's output
only:
1
3
and then do not do nothing!
import std.stdio;
import std.concurrency;
import core.thread;
void main()
{
void worker()
{
int value = 0;
while (value =10)
{
value = receiveOnly!int();
writeln(value);
int result = value * 3;
ownerTid.send(result);
}
}
give me:
Running .\app1.exe
2
6
3
9
4
12
5
15
6
18
What is the best way to remove file name from full path?
string path = thisExePath()
string path = thisExePath()
Seems like dirName in std.path is a good candidate ;)
http://dlang.org/phobos/std_path.html#.dirName
You'll find many other path manipulation functions there.
Thanks! But if I want to strip it, how I can cut it?
I can't understand how to use strip? For example I would like to
cut just extension.
path = path.stripRight(exe);
Error: no overload matches for stripRight(C)(C[] str) if
string getFileName()
{
//чтобы было проще обрабатываемый файл будем хранить рядом с
бинариком
string filename = chomp(readln());
string path = getcwd();
writeln((path ~ \\ ~ filename));
if (exists(path ~ \\ ~ filename))
return (path ~ \\ ~
I am planing to buy ARM-Board. I would use it for internet
browsing and whant to know would it's possible to develop D apps
on it?
I had read that LDC have limited support of ARM. wiki said that
it can compile hello-world apps. But it it not enough.
What about DMD. Is there any progress of
import std.stdio;
import std.conv;
import std.string;
import std.net.curl;
void main()
{
string content = get(d-lang.appspot.com/testUrl2);
}
Error: cannot implicitly convert expression (get(d-lang.appsp
ot.com/testUrl2, AutoProtocol())) of type char[] to string
code from:
Solution
http://forum.dlang.org/thread/bgkklxwbhrqdhveth...@forum.dlang.org#post-l639dt:24vlj:241:40digitalmars.com
Am I right understand that it's bug in doc?
Where I can find compatibility with D online regexp constructor?
I found only https://github.com/Bystroushaak/DHTMLParser
But I can't get it work:
C:\Users\Dima\Downloads\DHTMLParser-master\DHTMLParser-masterdmd
find_links.d
OPTLINK (R) for Win32 Release 8.00.15
Copyright (C) Digital Mars 1989-2013 All rights reserved.
You need to pass a library to compiler as well (all its files
or .lib/.a file) if it is compiled as static library
You can try
dmd find_links.d dhtmlparser.d quote_escaper.d
C:\Users\Dima\Downloads\DHTMLParser-master\DHTMLParser-masterdmd
find_links.d quote_escaper.d
OPTLINK (R) for
On Saturday, 25 October 2014 at 19:51:48 UTC, Suliman wrote:
You need to pass a library to compiler as well (all its files
or .lib/.a file) if it is compiled as static library
You can try
dmd find_links.d dhtmlparser.d quote_escaper.d
How I can build such App with DUB?
Unfortunately that library has no dub package.
But you can include it in your project.
See info here http://code.dlang.org/package-format
I can't understand how to set in dub that I need to to include in
compilation process other files... Could you help me?
Is it's possible to create single language that cover desktop and
web? Like D+Dart?
I ask becouse I can't understand why it's need 2 language if they
are very simmiler and it's can be 1 language instead 2.
I know that there is way to write all on JS. But I can't
understand what the reason that there are no single language that
can work on web and as native language.
It is possible, but you need to design the language within the
constraints of javascript:
1. single threaded (or worker threads)
2. 53 bits integers, 26 bits for multiplies.
4. weird fixed size heaps (ArrayView)
5. if garbage collection then it has to be javascript style
6. no tricks:
No! I mean not translation to js. I mean theoretical ability of
creation new programming language that can work every where!
Few questions.
1. In examples tuples are created with keyword auto. Can I create
them with another keyword. Or auto mean structure of data, that
have not standard type like (int or string)?
2. How ti expend tuple? I tried to do:
auto imglist = tuple(aaa);
imglist.expand[sss];
Thanks! In which cases tuples can be helpful?
void openFile(string fname, string current_folder)
{
auto file = readText(current_folder ~ fname);
scope(failure)
{
writeln(failure);
}
// writeln(file);
}
if file name do not exists, I want to rise scope exception. But
it's do not rise,
I can't understand what I am missing. Try-catch block also do not
handle exception:
void main()
{
string fname = app.d1; //file name with error
string current_folder = (getcwd() ~\\);
writeln(current_folder);
openFile(fname, current_folder);
}
void
Am I right understand that keyword Exception is handle
universal type of exceptions?
catch (Exception)
{
writeln(inner);
}
But in my example with try block can I change it's to something
more informative?
Replace that with something like writeln(caught) and you will
see that it is indeed caught. :) Printing the exception mimicks
the default behavior and you (and I) think that the exception
is not caught. :)
that's work, but I can not understand where I can to look at
exception level. If I
We have to look at the documentation of the function. In this
case the possibilities are FileException and UTFException.
http://dlang.org/phobos/std_file.html#.readText
However, judging by their names, they are both descendants of
Exception, so what you are doing will catch either of them.
I know that a lot of people are using for programming tools like
Sublime. I am one of them. But if for very simple code it's ok,
how to write hard code?
Do you often need debugger when you are writing code? For which
tasks debugger are more needed for you?
dmd a.d b.d
Otherwise you can also use ddmd and let it find the module
dependencies by itself.
Am I right understand that if I will put all needed files at src
folder and name main file App.d dub will add all needed files to
App.d ?
I can't understand how to use UFCS with instance of class:
void main()
{
string name = Suliman;
userName username = new userName(name);
/// How to use UFCS here?
userName.name.sayHello();
///
}
class userName
{
string name;
this(string name)
{
this.name = name;
}
Thanks!
Ali Çehreli, could you add this mention and possible the example
to your book?
I did 2 steps from http://d-apt.sourceforge.net/
$ sudo wget
http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list
-O /etc/apt/sources.list.d/d-apt.list
$ sudo apt-get update sudo apt-get -y --allow-unauthenticated
install --reinstall d-apt-keyring sudo apt-get update
And now
root@66898:~# apt-get install multiarch-support
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package multiarch-support is not available, but is referred to by
another packag
e.
This may mean that the package is missing, has been obsoleted, or
is only
If you haven't found the problem yet, please post:
1. what is the architecture of your machine? $ lscpu
2. what is the debian version? $ lsb_release -a
root@66898:~# lscpu
Architecture: x86_64
CPU op-mode(s):32-bit, 64-bit
CPU(s):4
Vendor ID:
You are right, after updating Debian to 7.7 dub was installed
successfully
I have got few questions about DFL2.
1: What is dco and in which situation I should prefer it's to dub?
2: Old DFL had easy to use GUI Builder. Does dfl2 have such tool?
You need to check if remote file exist of server and only after
it download шею
Also add scope or try catch block to your code.
In dco source code I have found:
void ShowUsage()
{
writeln(
dco build tool ~ strVersion ~
written by FrankLIKE.
Usage:
dco [switches...] files...
for example: dco
or: dco app.d
build for dfl2: dco
}
I do not see here any \n. Why this code is output all one by
line, and not in single
I am playing with dco. And it's look very helpful for tiny
projects.
I can't understand is it's possible to add to dco.ini Jpath?
I am talking about something like:
dflags=-JD:\code\d\App1\source\
but when I am trying to compile code with dco it's can't find
import.
I looked at source code
I understand it.
I expect what concatenation symbol will stay new line in new line
and not append it's to current:
writeln(
first string
second ~
string
);
I expect:
first string
second
string
but not:
first stringsecondstring
I can't understand how to get date in format -MM-dd from
Clock.currTime
auto time = Clock.currTime;
And what next? Could anybody give any examples?
Is there any way to set separator? For example I want use '/' or
':'?
And could anybody explain me how the cast is work. How to
understand which types to which may be casted?
I can't understand why foreach loop produce every line by line,
while it's fuctional analog print lines on one string:
foreach(f; file.byLine())
{
writeln(f);
}
auto file = File(foo.txt,r);
file
.byLine()
.writeln;
file content:
-
first sring
second string
-
Thanks! But is there any way to do it with std.algorithm?
Can be skipOver used for it?
This is an issue with your version of dub with a buggy url
encoding method. Download the latest at code.dlang.org
http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/22266/
Full function look like this:
auto parseConfig()
{
auto config = Ini.Parse(getcwd ~ \\ ~ config.ini);
string txtlinks = getcwd ~ \\ ~ config.getKey(input_links);
if(!exists(txtlinks))
{
writeln(Can't find input file with list of links.);
auto parseConfig()
{
auto lines = File(txtlinks, r).byLine;
return lines;
}
Error: cannot return non-void from void function
I can't understand the reasons of the error;
Can I return auto from function?
I try to compile simple example:
import std.net.curl;
void main()
{
download(ftp.digitalmars.com/sieve.ds,
D:\\Project\\2014\\txt_downloader\\img\\1.foo);
}
but I am getting error:
function app.download (string[] links) is not callableusing
argument types (string, string)
Look like it was missed installation or so. I installed new copy
of dmd and error gone away.
The downloading still do not work. Work only:
get(dlang.org);
ah, that's it! as spec says, D determines function return value
from
the first 'return' statement it seen. in your case this is
`return;`,
so function return type is determined to be `void`.
if you doing `auto` functions, try to arrange your code so the
first
`return` returning the actual
Running .\txtdownloader.exe
std.stream.OpenException@std\stream.d(50): Cannot open or create
file 'D:\Projec
t\2014\txt_downloader\img\1.foo'
0x0041BA59 in void std.stream.File.open(immutable(char)[],
std.stream.FileMode)
0x00404B75 in void
Is there any way to detect where collision was occurred?
Oh! It's work! I forgot to change path on my home PC!
On Thursday, 27 November 2014 at 17:39:10 UTC, Suliman wrote:
Is there any way to detect where collision was occurred?
It's look like collision was with method name.
Sometimes it's path string may do not have tail slash of the path
Compare:
string path = C:\\folder\\name
string path = C:\\folder\\name\\
in case if I need to append file name to path to get full path I
can get error like:
path ~= foo.txt
C:\\folder\\namefoo.txt
instead of
see std.path, it contains alot of useful things.
I looked there, but found only buildNormalizedPath, but it's not
for such situation...
take a second look then. ;-) you'll find `buildPath()` here too.
Not better:
string foo = D:/code/txtDownloader;
writeln(foo);
foo = foo.buildPath;
foo ~= config.txt;
writeln(foo);
Running .\txtdownloader.exe
D:/code/txtDownloader
Could you quote for me part of docs where it's written? I really
can't understand about what you are taking.
thanks! I understood!
I can't understand why I am getting exception on next code:
void downloadFile()
{
foreach(link; links)
{
try
{
writeln(connect(link));
}
Am I right understand all exception are derived from
assertThrown
http://dlang.org/phobos/std_exception.html
So msg in catch(Exception msg) is from function
assertThrown?
Could you show me example of how to handle type of exception?
Big thanks Ali!
Only the small last question:
why:
string link = dlang.org;
writeln(connect(link));
cause crash:
std.net.curl.CurlException@C:\DMD\dmd2\windows\bin\..\..\src\phobos\std\net\curl
.d(779): HTTP request returned status code 400
0x00404263
My guess is that you have to use HTTPS for CONNECT and that you
have to have credentials for it. (?)
Ali
dlang.org should work on HTTP, but not HTTPS.
Also I do not think that when I connect to HTTPS I should have
any credentials. It's mostly like issue with curl...
Could anybody explain why there is opinion that stack is fast and
the heap is slow. All of them are located in the same memory. So
the access time should be equal.
connect() sends a CONNECT request to the server, as defined
by HTTP [1]. This method is only used when you're working with
proxies and the like. What you most likely want, however, is a
GET request. Use get() for that.
So what is the best way to check status server response (400, 404
etc)
I am trying to start with http://code.dlang.org/packages/dpq2
But I can't understand where I should to get pq.lib and where I
should to place it. In the Program Files I did not find such
file...
string dbname = config.getKey(dbname1);
scope(failure) writeln(look like dbname is missing);
I am using dini and trying to throw exception if value can't be
extract from config. If I am wrap it's in try-сефср block it's
work or. But in this situation scope block do not execute and I
see only
If I right understand scope is not good for checking if one of
function is fail.
For example:
string dbpass = config.getKey(dbpass);
string dbpass = config.getKey(dbpass);
string dbhost = config.getKey(dbhost);
string dbport = config.getKey(dbport);
if I will try to add scope(failure)
I reread docs and understood that scope not for such case.
Next code is do what I need:
try
{
string dbname = config.getKey(dbname);
string dbpass = config.getKey(dbpass);
string dbhost = config.getKey(dbhost);
string dbport = config.getKey(dbport);
}
catch
On the code.dlang.org I found SQLLite driver
https://github.com/biozic/d2sqlite3
Look like it's not ready for Windows:
pragma(msg, \nWARNING !!!\nDevelopped for POSIX systems
only.\nNot tested on Windows.\n);
I tried to add import to my project and I got next errors:
Yes I used 2.0.65, but after updating compiler the situation did
not resolved...
http://www.everfall.com/paste/id.php?apd0bfs5z4eg
There is also a branch named `develop` which at least compiles,
maybe it is usable.
how to add to dub this branch?
On Sunday, 14 December 2014 at 13:33:27 UTC, Suliman wrote:
There is also a branch named `develop` which at least
compiles, maybe it is usable.
how to add to dub this branch?
Compiling using dmd...
Linking...
OPTLINK (R) for Win32 Release 8.00.15
Copyright (C) Digital Mars 1989-2013 All
The problem with 31 string.
http://www.everfall.com/paste/id.php?jgsdz7mdbrnm
If I uncomment it, and server response is return 404 code I code
at runtime throw exception with text:
Can't parse config: HTTP request returned status code 404
I thought that checkLinkCode is throw any king
Oh sorry I understood where problem.
Could anybody provide any simple examples of usage DerelictPQ. I
do not have experience of C, and I can't understand how to use
this driver.
I need just basics like connect, select and insert.
http://code.dlang.org/packages/derelict-pq
thanks!
I have done next:
string connString = psql -h localhost -p 5432 -U postgres -d
testdb;
package PGconn* conn;
@property bool nonBlocking(){ return PQisnonblocking(conn) == 1;
}
this(parseConfig parseconfig)
{
void connect()
{
On Wednesday, 24 December 2014 at 14:08:53 UTC, Adam D. Ruppe
wrote:
I haven't used the derelict version but I have used the C
library itself and wrapped it briefly in my postgres.d here:
https://github.com/adamdruppe/arsd/blob/master/postgres.d
Thanks! But few questions:
1. how to build it
DerelictPQ is only a binding to libpq. The only difference is
the
DerelictPQ.load method. Just follow the libpq documentation.
http://www.postgresql.org/docs/9.1/static/libpq.html
Actually, Derelict binds to version 9.3, so the proper link
should be
Adam, I trying to build simple app:
import std.stdio;
import postgres;
import database;
void main() {
auto db = new PostgreSql(dbname = test2);
foreach(line; db.query(SELECT * FROM customer)) {
writeln(line[0], line[customer_id]);
}
}
and getting next
I need to pass some config to ddbc driver. When I use static
const all work ok.
static const string PGSQL_UNITTEST_HOST = localhost;
static const intPGSQL_UNITTEST_PORT = 5432;
static const string PGSQL_UNITTEST_USER = postgres;
static const string PGSQL_UNITTEST_PASSWORD = Infinity8;
But why variant:
static const int PGSQL_UNITTEST_PORT = 5432;
do not require of implicit convert to!short() at connection
string?
I think it's fine to have a global config instance.
Alternatively you can pass the config to both the
seismoDownlead and MySqlWhatever classes.
// there ist enforce(cond, msg) for this in
std.exception/std.conv, dunno.
if (!exists(confpath)) throw new Exception(ERROR: config.ini
do not
class parseConfig
{
string dbname;
string dbuser;
string dbpass;
string dbhost;
string dbport;
uint status;
this()
{
auto checkLinkCode(string link) // we need to check all links to
be sure if they are alive
{
return
Thanks! I will try!
D is my first compilable language, I wrote only some scripts
without OO before.
So in my case your suggestion is best practice? Or there is any
more simple way to pass config and data to MySQL class?
Anything declared in main() is local to main and not a global.
Ok! So I need create multiple instances of the parseconfig?
Or please suggest me any solution, I really can't understand how
to be in such situation...
Oh mama mia! I did it!
http://www.everfall.com/paste/id.php?a5pp73ns1e4k
auto seismodownload = new seismoDownload(emsc_csem, this);
then:
auto mysql = new MySQL(parseconfig,eqs);
So could anybody show me better way? As I said I did not fully
understand how use global class instance...
1 - 100 of 439 matches
Mail list logo