Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Mike Parker via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 20:27:44 UTC, Ron Tarrant wrote:

On Tuesday, 1 January 2019 at 18:10:49 UTC, Mike Parker wrote:


We're using Mivhak Syntax Highlighter on the D Blog.

OOTB, or...?

I couldn't find a list of supported languages.


It supports D out of the box.


Re: static foreach direct use of variables

2019-01-01 Thread Michelle Long via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 21:34:08 UTC, Paul Backus wrote:

On Tuesday, 1 January 2019 at 21:14:09 UTC, Michelle Long wrote:

auto foo(S s)
{
static foreach(k, p; [s, this])
for(int i = 0; i < p.length; i++)
...
}

The idea is to provide single for loop structure for each of 
the variables(in this case s and this).


You can do this with `std.meta.AliasSeq`:

string[] a = ["lions", "tigers", "bears"];
int[] b = [123, 456, 789];

static foreach(array; AliasSeq!(a, b)) {
foreach (item; array) {
writeln(item);
}
}


I tried that but it didn't work... I will try again.


Re: Subtypes with tighter constraints

2019-01-01 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 01 Jan 2019 14:05:43 +, Victor Porton wrote:
> In Ada2012 there are "subtypes". Subtypes can have tighter constraints
> (such as type invariants) than their base types.
> 
> I have a struct X in D. Is it possible to define a type equivalent to X
> except that having tighter invariants?

In D, structs don't participate in inheritance. Classes do, but invariants 
aren't inherited; they're specific to the class in which the function is 
defined. (Which is probably a bug and I filed https://issues.dlang.org/
show_bug.cgi?id=19537.)

I see three ways to make this work today:

1. Use alias this to wrap the struct. Add invariants that deal with the 
wrapped struct's fields.
2. Use compile-time reflection to copy the fields over, then manually copy 
the invariants over and add more.
3. Use a class. Define a virtual function like 'doInvariant()`. Call it 
from the base class's invariant{} block.

> As I understand if I derive Y from X, then it is no more X; that is I
> cannot use X (even provided it matches Y invariants) where I need Y. So
> in D it is impossible, right?

With classes, a derived class instance can be used anywhere you expect a 
base class instance. The reverse is not true.


Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Ron Tarrant via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 20:43:13 UTC, Adam D. Ruppe wrote:

Realistically, if you use Java or C++ highlighting, it will 
look plenty good enough for D too.


Yeah, I was thinking that. I'd imagine it would be missing a few 
keywords, though.


So take a look down my highlight test page for my adrdox 
generator:


http://dpldocs.info/experimental-docs/adrdox.highlight.html


That's pretty cool. Thanks. However, I'm not seeing anyway to 
grab this and use it. I clicked on links, but didn't really find 
my way to a better understanding.


(which btw i also happen to use for my new blog 
http://dpldocs.info/this-week-in-d/Blog.Posted_2018_12_31.html )


I'll have to check that out.

I wrote like 30 lines of code and very simple definitions to 
support all the languages in that test. And it is plenty good 
enough.


Cool. And I can download this? I don't know if I'm being dim, but 
I really don't see how to.


Of course, it DOES support D, extremely fully - it has a 
full-blown D lexer in there. But tbh if I use the C family 
highlighter for D you usually can't tell the difference.


No doubt! :)


Re: static foreach direct use of variables

2019-01-01 Thread Paul Backus via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 21:14:09 UTC, Michelle Long wrote:

auto foo(S s)
{
static foreach(k, p; [s, this])
for(int i = 0; i < p.length; i++)
...
}

The idea is to provide single for loop structure for each of 
the variables(in this case s and this).


You can do this with `std.meta.AliasSeq`:

string[] a = ["lions", "tigers", "bears"];
int[] b = [123, 456, 789];

static foreach(array; AliasSeq!(a, b)) {
foreach (item; array) {
writeln(item);
}
}


Re: static foreach direct use of variables

2019-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 21:14:09 UTC, Michelle Long wrote:

auto foo(S s)
{
static foreach(k, p; [s, this])
for(int i = 0; i < p.length; i++)
...
}


try

static foreach(...) {{
 stuff
}}


The double {{ and double }} are intentional.



static foreach direct use of variables

2019-01-01 Thread Michelle Long via Digitalmars-d-learn

auto foo(S s)
{
static foreach(k, p; [s, this])
for(int i = 0; i < p.length; i++)
...
}

The idea is to provide single for loop structure for each of the 
variables(in this case s and this).


The is to avoid string mixins which are pathetic for this kind of 
work.


The point is that instead of having to do

for(int i = 0; i < s.length; i++)
 ...
for(int i = 0; i < this.length; i++)
 ...

in which case ... might be very long.

Sure one can create a function and all that mess but the compiler 
should be able to do symbol replacement very naturally and easily.






Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 20:27:44 UTC, Ron Tarrant wrote:

I couldn't find a list of supported languages.


Realistically, if you use Java or C++ highlighting, it will look 
plenty good enough for D too.


So take a look down my highlight test page for my adrdox 
generator:


http://dpldocs.info/experimental-docs/adrdox.highlight.html

(which btw i also happen to use for my new blog 
http://dpldocs.info/this-week-in-d/Blog.Posted_2018_12_31.html )



I wrote like 30 lines of code and very simple definitions to 
support all the languages in that test. And it is plenty good 
enough.


Of course, it DOES support D, extremely fully - it has a 
full-blown D lexer in there. But tbh if I use the C family 
highlighter for D you usually can't tell the difference.


Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Ron Tarrant via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 18:32:24 UTC, Andre Pany wrote:

If your reason for not choosing WordPress is related to 
security concerns you could also consider this approach.


Not so much a security concern, I'm just looking for the path of 
least resistance. If that's WP, that's fine, but if it's another 
road, so be it.






Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Ron Tarrant via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 18:10:49 UTC, Mike Parker wrote:


We're using Mivhak Syntax Highlighter on the D Blog.

OOTB, or...?

I couldn't find a list of supported languages.



Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Ron Tarrant via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 18:07:22 UTC, Neia Neutuladh wrote:

I believe I use Enlighter for that: 
https://wordpress.org/plugins/enlighter/
Did you have to massage it? I don't see D in its list of 
supported languages.




Low order hashes

2019-01-01 Thread Michelle Long via Digitalmars-d-learn
I need to hash a few strings to a byte, short, or int. hashOf 
works for int only on x86.


What would be a nice way to accomplish this? Collisions are not 
good but not catastrophic. Mainly I need a unique ID to emulate 
enums. I might just chop off the extra bits or mash them up 
somehow and it will probably work but hoping for something more 
solid.




Re: Subtypes with tighter constraints

2019-01-01 Thread Alex via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 14:05:43 UTC, Victor Porton wrote:
In Ada2012 there are "subtypes". Subtypes can have tighter 
constraints (such as type invariants) than their base types.


I have a struct X in D. Is it possible to define a type 
equivalent to X except that having tighter invariants?


As I understand if I derive Y from X, then it is no more X;

1. As Ada is strongly typed, this is the same there, no?
2. You cannot derive structs in D. Therefore, I assume, that you 
meant that X and Y are classes.


that is I cannot use X (even provided it matches Y invariants) 
where I need Y. So in D it is impossible, right?


It is possible, as invariants are inherited implicitly, see
https://dlang.org/spec/contracts.html#Invariants
paragraph 9.

´´´
import std.experimental.all;

void main()
{
auto x = new X();
auto y = new Y();
x.d = 0.0;
y.d = 1.0;
x.fun;
y.fun;
}

class X
{
double d;

invariant
{
assert(!d.isNaN);
}
}

class Y : X
{
invariant
{
assert(d > 0);
}
}

void fun(T)(T t)
{
assert(t);
}
´´´


Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Andre Pany via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 14:46:15 UTC, Ron Tarrant wrote:
I've found a ton of syntax highlighter plugins for WordPress, 
but none that admit to supporting D. Anyone know of one?


Or, short of that, perhaps a different site build/management 
tool (read: not WordPress) with decent D syntax highlighting...


Or, one that can be adapted without rolling my sleeves much 
past my wrists.


I run WordPress on my localhost and use a static site generator 
to create plain html files. These files I can simply upload using 
ftp. Therefore I have a nice ui for editing the content and also 
do not have to care about security and vulnerabilities.


If your reason for not choosing WordPress is related to security 
concerns you could also consider this approach.


Kind regards
Andre


Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Mike Parker via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 14:46:15 UTC, Ron Tarrant wrote:
I've found a ton of syntax highlighter plugins for WordPress, 
but none that admit to supporting D. Anyone know of one?


Or, short of that, perhaps a different site build/management 
tool (read: not WordPress) with decent D syntax highlighting...


Or, one that can be adapted without rolling my sleeves much 
past my wrists.


We're using Mivhak Syntax Highlighter on the D Blog.


Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 01 Jan 2019 14:46:15 +, Ron Tarrant wrote:
> I've found a ton of syntax highlighter plugins for WordPress, but none
> that admit to supporting D. Anyone know of one?

I believe I use Enlighter for that:
https://wordpress.org/plugins/enlighter/


Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Ron Tarrant via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 17:09:51 UTC, rjframe wrote:

I started using SilverStripe 7 or 8 years ago, and have never 
had a reason to look for anything else. It doesn't have the 
ecosystem of WordPress and never seemed to get much following 
outside New Zealand, but it's well- designed and makes working 
with PHP not-horrible (and sometimes almost pleasant). I'm not 
familiar enough with WordPress to make any comparison.


I've documented my syntax highlighting setup[0] but it assumes 
familiarity with SilverStripe; reading through the official 
examples should be enough:


https://www.ryanjframe.com/blog/syntax-highlighting-in-silverstripe/


--Ryan


Thanks, Ryan. I'll take a look.


Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread rjframe via Digitalmars-d-learn
On Tue, 01 Jan 2019 16:48:00 +, Ron Tarrant wrote:

> SilverStripe, on the surface, seems quite WordPress-alike. Did you find
> advantages over WordPress, or is it personal preference?
> How's the syntax highlighting? (I skimmed the video, but didn't see any
> mention of this.)
> 
> PrismJS looks promising.

I started using SilverStripe 7 or 8 years ago, and have never had a reason 
to look for anything else. It doesn't have the ecosystem of WordPress and 
never seemed to get much following outside New Zealand, but it's well-
designed and makes working with PHP not-horrible (and sometimes almost 
pleasant). I'm not familiar enough with WordPress to make any comparison.

I've documented my syntax highlighting setup[0] but it assumes familiarity 
with SilverStripe; reading through the official examples should be enough:

https://www.ryanjframe.com/blog/syntax-highlighting-in-silverstripe/


--Ryan


Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Ron Tarrant via Digitalmars-d-learn

On Tuesday, 1 January 2019 at 15:36:11 UTC, rjframe wrote:

I use SilverStripe instead of Wordpress, but if WordPress uses 
TinyMCE you can use the codesample plugin[0] with PrismJS[1], 
which does support D (though I don't know if it actively gets 
updates).



[0]: https://www.tiny.cloud/docs/plugins/codesample/
[1]: http://prismjs.com/


SilverStripe, on the surface, seems quite WordPress-alike. Did 
you find advantages over WordPress, or is it personal preference? 
How's the syntax highlighting? (I skimmed the video, but didn't 
see any mention of this.)


PrismJS looks promising.



Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread rjframe via Digitalmars-d-learn
On Tue, 01 Jan 2019 14:46:15 +, Ron Tarrant wrote:

> I've found a ton of syntax highlighter plugins for WordPress, but none
> that admit to supporting D. Anyone know of one?
> 
> Or, short of that, perhaps a different site build/management tool (read:
> not WordPress) with decent D syntax highlighting...
> 
> Or, one that can be adapted without rolling my sleeves much past my
> wrists.

I use SilverStripe instead of Wordpress, but if WordPress uses TinyMCE you 
can use the codesample plugin[0] with PrismJS[1], which does support D 
(though I don't know if it actively gets updates).


[0]: https://www.tiny.cloud/docs/plugins/codesample/
[1]: http://prismjs.com/


Re: D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Ron Tarrant via Digitalmars-d-learn

And while we're on the subject, a couple of related questions:

1) I'm currently using AgilityHoster which gives me a free site 
and $18/year domain registration. Any better deals out there 
without sacrificing UX?


2) Anyone have experience with Github Pages?

3) Or if anyone cares to share experiences with a particular 
hosting service from the POV of running a coding/programming blog?




D-oriented Syntax Highlighting Plugin for WordPress?

2019-01-01 Thread Ron Tarrant via Digitalmars-d-learn
I've found a ton of syntax highlighter plugins for WordPress, but 
none that admit to supporting D. Anyone know of one?


Or, short of that, perhaps a different site build/management tool 
(read: not WordPress) with decent D syntax highlighting...


Or, one that can be adapted without rolling my sleeves much past 
my wrists.




Subtypes with tighter constraints

2019-01-01 Thread Victor Porton via Digitalmars-d-learn
In Ada2012 there are "subtypes". Subtypes can have tighter 
constraints (such as type invariants) than their base types.


I have a struct X in D. Is it possible to define a type 
equivalent to X except that having tighter invariants?


As I understand if I derive Y from X, then it is no more X; that 
is I cannot use X (even provided it matches Y invariants) where I 
need Y. So in D it is impossible, right?


I think in D it's impossible, but want to be sure and so ask.