Re: How create a function that receive a function and run it in another threading?

2019-12-26 Thread mipri via Digitalmars-d-learn

On Friday, 27 December 2019 at 06:08:16 UTC, Marcone wrote:

import std;
import core.thread;

auto threading(lazy void fun){ return 
task!fun().executeInNewThread(); }


void main(){
threading(writeln("Hello World!"));
}


I want to create a function threading() to run some function in 
other threading, but I get this error bellow. How can I get 
success?



Error: static function Programa.threading.Task!(fun).Task.impl 
cannot access frame of function Programa.threading
Error: template instance `Programa.threading.Task!(fun)` error 
instantiating


This works:

import std;
import core.thread;

auto threading(void function() fun){ return 
task(fun).executeInNewThread(); }


void main(){
writeln("Main: ", thisTid);
threading({ writeln("Hello, ", thisTid); });
}



How create a function that receive a function and run it in another threading?

2019-12-26 Thread Marcone via Digitalmars-d-learn

import std;
import core.thread;

auto threading(lazy void fun){ return 
task!fun().executeInNewThread(); }


void main(){
threading(writeln("Hello World!"));
}


I want to create a function threading() to run some function in 
other threading, but I get this error bellow. How can I get 
success?



Error: static function Programa.threading.Task!(fun).Task.impl 
cannot access frame of function Programa.threading
Error: template instance `Programa.threading.Task!(fun)` error 
instantiating


Re: [OT] What kind of Editor, IDE you are using and which one do you like for D language?

2019-12-26 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/24/19 5:18 AM, Russel Winder wrote:

On Mon, 2019-12-23 at 08:09 -0800, H. S. Teoh via Digitalmars-d-learn
wrote:
[…]


No idea, I use vanilla vim (not even with syntax highlighting -- I'm
a
hardcore retro guy).


Surely a hardcore retro guy would be using vi not vim? Indeed wouldn't
a real hardcore retro guy be using ed?



Pt. Real hardcore users use ed.

 When I log into my Xenix system with my 110 baud teletype, both vi
 *and* Emacs are just too damn slow. They print useless messages like,
 'C-h for help' and '"foo" File is read only'. So I use the editor
 that doesn't waste my VALUABLE time.

 Ed, man! !man ed

 ED(1) UNIX Programmer's Manual ED(1)

 NAME
 ed - text editor

 SYNOPSIS
 ed [ - ] [ -x ] [ name ]
 DESCRIPTION
 Ed is the standard text editor.
 -

 Computer Scientists love ed, not just because it comes first
 alphabetically, but because it's the standard. Everyone else loves ed
 because it's ED!

 "Ed is the standard text editor."

 And ed doesn't waste space on my Timex Sinclair. Just look:

 -rwxr-xr-x 1 root 24 Oct 29 1929 /bin/ed
 -rwxr-xr-t 4 root 1310720 Jan 1 1970 /usr/ucb/vi
 -rwxr-xr-x 1 root 5.89824e37 Oct 22 1990 /usr/bin/emacs

 Of course, on the system *I* administrate, vi is symlinked to ed.
 Emacs has been replaced by a shell script which 1) Generates a syslog
 message at level LOG_EMERG; 2) reduces the user's disk quota by 100K;
 and 3) RUNS ED!!

 "Ed is the standard text editor."

 Let's look at a typical novice's session with the mighty ed:

 golem> ed

 ?
 help
 ?
 ?
 ?
 quit
 ?
 exit
 ?
 bye
 ?
 hello?
 ?
 eat flaming death
 ?
 ^C
 ?
 ^C
 ?
 ^D
 ?

 ---
 Note the consistent user interface and error reportage. Ed is
 generous enough to flag errors, yet prudent enough not to overwhelm
 the novice with verbosity.

 "Ed is the standard text editor."

 Ed, the greatest WYGIWYG editor of all.

 ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF
 EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR
 PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN
 SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

 When I use an editor, I don't want eight extra KILOBYTES of worthless
 help screens and cursor positioning code! I just want an EDitor!!
 Not a "viitor". Not a "emacsitor". Those aren't even WORDS ED!
 ED! ED IS THE STANDARD!!!

 TEXT EDITOR.

 When IBM, in its ever-present omnipotence, needed to base their
 "edlin" on a UNIX standard, did they mimic vi? No. Emacs? Surely
 you jest. They chose the most karmic editor of all. The standard.

 Ed is for those who can *remember* what they are working on. If you
 are an idiot, you should use Emacs. If you are an Emacs, you should
 not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE
 SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO
 TEMPT THE FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

 --
 Miquel van Smoorenburg | Our vision is to speed up time,
 miqu...@cistron.nl | eventually eliminating it.



I left in the byline above, because I don't want to take credit ;)

-Steve


Re: [OT] What kind of Editor, IDE you are using and which one do you like for D language?

2019-12-26 Thread Russel Winder via Digitalmars-d-learn
On Tue, 2019-12-24 at 09:52 -0800, H. S. Teoh via Digitalmars-d-learn
wrote:
> On Tue, Dec 24, 2019 at 10:18:49AM +, Russel Winder via
> Digitalmars-d-learn wrote:

[…]
> Haha, well, a *real* hardcore retro guy would be using a magnet, a
> pin,
> and a *really* steady hand, to flip individual bits on an exposed
> harddisk platter to create the executable in the filesystem directly,
> one bit at a time.
> 
> Of course, one could also just use emacs:
> 
>   https://xkcd.com/378/
> 
> :-D

One always returns to using Emacs for text editing – it is the One True
Editor™ (and kitchen sink).

[…]
> It wasn't so much wrong highlighting for me, it was the fact that it
> was
> highlighted at all.  I find the kaleidoscopic colors extremely
> distracting and disruptive to my focusing on the textual content of
> the
> code.  Not to mention that the colors usually clash horribly with my
> chosen foreground/background color scheme in my terminal, which only
> adds unreadable bits of text to the problem.

Emacs and JetBrains CLion seem to work fine for me in both light-on-
dark and dark-on-light mode, so syntax highlighting works for me for
the editors I use.

I keep trying VIM, Atom, VSCode, SublimeText, Geany, etc. from time to
time, but I get bored trying to get them set up to be even remotely
sensible and just go back to Emacs.

[…]
> 
> Actually, I wouldn't mind a syntax-oriented editor, if one could be
> made
> that wasn't artificially restrictive in terms of editing various
> different languages and various different flavors of different
> languages, such that it could be used as a general tool.

There is a movement to try and bring back what could be described as
SOEs, but I am not seeing that much traction as yet. The incumbent
editors that use vast quantities of CPU to reconstruct ASTs on the fly
seem to dominate mindset.

[…]
> 
> This madness is nothing compared to the utter, gibbering insanity of
> modern web design, in which modern 8-core CPUs with GHz speeds and
> GBs
> of memory run dead-simple applications like word processors at the
> *same* speeds (if not worse!) as WordStar would run back in 1980 on
> an 8
> *Hz* CPU with 64KB of RAM.  With exactly the same lag between
> keystrokes, and the same (lack of) reliability requiring frequent
> backups and incessant restarting.
> 
> Now *that* I call a mad, mad world.  The madness of IDEs parsing and
> reparsing the same AST over and over again umpteen times per second
> doesn't even begin to scratch the surface of *this* madness. I just
> can't wait to see some poor sod attempt to reimplement a modern IDE
> in
> Javascript and succeed at reproducing 1980's IDE speeds and (lack of)
> quality.  And of course the masses would slobber all over it and hail
> it
> as "progress".  The browser king has no clothes, and everybody sees
> invisible.

I can only agree with this rant. The modern world of software has
increasingly become about doing less and less useful to the end user
with more and more hardware resources.
 
-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk



signature.asc
Description: This is a digitally signed message part


Re: array of functions/delegates

2019-12-26 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/24/19 8:52 AM, MoonlightSentinel wrote:

On Tuesday, 24 December 2019 at 07:37:02 UTC, Rumbu wrote:

I am trying to create an array of functions inside a struct.

struct S {
  void f1() {}
  void f2() {}

  alias Func = void function();

 immutable Func[2] = [, ]

}

What I got: Error: non-constant expression ''

Tried also with delegates (since I am in a struct context but I got: 
no `this` to create delegate `f1`.


So, is there any way to have an array of functions without adding them 
at runtime?


You can set funcs within the constructor but not as a default 
initializer because they have to be compile time constants 
(https://dlang.org/spec/struct.html#default_struct_init)


struct S
{
     void f1() {}
     void f2() {}

     alias Func = void delegate();

     immutable Func[2] funcs;

     this(bool)
     {
     funcs = [, ];
     }
}

 creates a delegate which contain a function pointer and the context 
pointer (struct, closure, ...). In this example the latter contains a 
pointer to a concrete instance of S which is a usually a runtime value. 
(https://dlang.org/spec/type.html#delegates)


Just FYI, doing this is very suspicious. Storing a delegate to a struct 
means you have a context pointer to that struct. And structs can usually 
move around freely. Meaning that f1 and f2 are still going to refer to 
the original struct, even if it has been copied, and even if the struct 
has been deallocated (i.e. it was on a stack frame that no longer exists).


-Steve


Re: What kind of Editor, IDE you are using and which one do you like for D language?

2019-12-26 Thread Ron Tarrant via Digitalmars-d-learn

On Thursday, 26 December 2019 at 10:32:10 UTC, Andre Pany wrote:

I am not sure wheter you talk about the same issue but the 
explorer view was also the only reason VSC was totally unusable 
for me. The lack of file/folder icons really questionable.

Recently I found out that it is possible to configure them.


Interesting. I'll have to look into that. Thanks, Andre.


Re: What kind of Editor, IDE you are using and which one do you like for D language?

2019-12-26 Thread Andre Pany via Digitalmars-d-learn

On Thursday, 26 December 2019 at 10:15:17 UTC, Ron Tarrant wrote:
On Wednesday, 25 December 2019 at 13:32:45 UTC, Mike Parker 
wrote:


For a while, typing in VS Code was clunky compared to Sublime. 
I gave it a spin every couple of months to see how it was 
shaping up and eventually I stopped noticing the difference.


Ah! Good to know. Thanks, Mike. Once they add a proper file 
explorer sidebar, I may switch.


I am not sure wheter you talk about the same issue but the 
explorer view was also the only reason VSC was totally unusable 
for me. The lack of file/folder icons really questionable.

Recently I found out that it is possible to configure them.

Kind regards
Andre


Re: What kind of Editor, IDE you are using and which one do you like for D language?

2019-12-26 Thread Ron Tarrant via Digitalmars-d-learn

On Wednesday, 25 December 2019 at 13:32:45 UTC, Mike Parker wrote:

For a while, typing in VS Code was clunky compared to Sublime. 
I gave it a spin every couple of months to see how it was 
shaping up and eventually I stopped noticing the difference.


Ah! Good to know. Thanks, Mike. Once they add a proper file 
explorer sidebar, I may switch.