Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread Ivan Kazmenko via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 10:46:54 UTC, Gary Willoughby wrote: After reading the following thread: http://forum.dlang.org/thread/nczgumcdfystcjqyb...@forum.dlang.org I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. [1]:

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread Idan Arye via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 11:03:09 UTC, bearophile wrote: Gary Willoughby: I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. Is this OK? void main() { import std.stdio, std.algorithm, std.range, std.conv, std.functional;

Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread Gary Willoughby via Digitalmars-d-learn
After reading the following thread: http://forum.dlang.org/thread/nczgumcdfystcjqyb...@forum.dlang.org I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. [1]: http://en.wikipedia.org/wiki/Fizz_buzz

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread bearophile via Digitalmars-d-learn
Gary Willoughby: I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. Is this OK? void main() { import std.stdio, std.algorithm, std.range, std.conv, std.functional; 100 .iota .map!(i = ((i + 1) % 15).predSwitch(

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread w0rp via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 10:46:54 UTC, Gary Willoughby wrote: After reading the following thread: http://forum.dlang.org/thread/nczgumcdfystcjqyb...@forum.dlang.org I wondered if it was possible to write a classic fizzbuzz[1] example using a UFCS chain? I've tried and failed. [1]:

Re: Readonly-to-outside variable

2015-04-28 Thread Baz via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 19:30:06 UTC, tcak wrote: Is there any way to define a variable or an attribute as read-only without defining a getter function/method for it? Thoughts behind this question are: 1. For every reading, another function call process for CPU while it could directly

Runtime metaprogramming in D

2015-04-28 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Is it possible to write self-modifying code in D, who will perform at runtime? Or is it a characteristic of languages that compile to bytecode?

Re: Fuzzy Levenshtein variant of std.conv.to

2015-04-28 Thread via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 16:20:24 UTC, Per Nordlöw wrote: I update my Github repo. I had forgotten to push my latest changes.

Re: @disable assignment of [] literal?

2015-04-28 Thread Meta via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 07:43:28 UTC, Kagamin wrote: Looks like it does: http://dpaste.dzfl.pl/a851acca63d9 That compiler error is because `ArrayWrapper!(int[]) = []` matches both `this(int[])` and `this(ArrayWrapper[])`, although... that might be workable.

Re: Parseing single JSON value from webpage

2015-04-28 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 29 April 2015 at 02:34:20 UTC, William Dunne wrote: Sorry for the noob question. I'm currently trying to parse this bit of json: Array ( [meta] = Array ( [level1trust] = 1 [level2trust] = 9 ) [connections] = Array (

Parseing single JSON value from webpage

2015-04-28 Thread William Dunne via Digitalmars-d-learn
Sorry for the noob question. I'm currently trying to parse this bit of json: Array ( [meta] = Array ( [level1trust] = 1 [level2trust] = 9 ) [connections] = Array ( [level1] = Array ( [from]

Re: Runtime metaprogramming in D

2015-04-28 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 29 April 2015 at 01:38:17 UTC, Dennis Ritchie wrote: Hi, Is it possible to write self-modifying code in D, who will perform at runtime? Not easily. Just the obvious approach to invoke the compiler and run/load the created executable / shared library. Or is it a

Re: Create a case-insensitive startsWith

2015-04-28 Thread Justin Whear via Digitalmars-d-learn
On Tue, 28 Apr 2015 21:45:07 +, PhilipDaniels wrote: Beginner question. Given if (startsWith(input, 0x, 0X)) How do I turn that into a case-insensitive startsWith? startsWith says it takes a predicate but I can't figure out how to pass it one. The examples all use a == b !? These

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread wobbles via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 11:04:12 UTC, w0rp wrote: On Tuesday, 28 April 2015 at 10:46:54 UTC, Gary Willoughby wrote: After reading the following thread: http://forum.dlang.org/thread/nczgumcdfystcjqyb...@forum.dlang.org I wondered if it was possible to write a classic fizzbuzz[1] example

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 13:59:48 UTC, Ivan Kazmenko wrote: On Tuesday, 28 April 2015 at 10:46:54 UTC, Gary Willoughby wrote: After reading the following thread: http://forum.dlang.org/thread/nczgumcdfystcjqyb...@forum.dlang.org I wondered if it was possible to write a classic fizzbuzz[1]

Fuzzy Levenshtein variant of std.conv.to

2015-04-28 Thread via Digitalmars-d-learn
At https://github.com/nordlow/justd/blob/master/conv_ex.d I'm trying to figure out how to best implement a fuzzy variant of std.conv.to when converting a string to an enum. I'm almost there but I'm uncertain how to best pick the index of the smallest element in `distances` and then convert

Re: Is there something like apply?

2015-04-28 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-04-28 17:52:57 +, Adam D. Ruppe said: This can also be automated with a bit of code in a lot of cases: import std.traits; ParameterTypeTuple!foo params; foreach(index, ref param; params) { params[index] = args[index]; } foo(params); Move that into a helper function and you

Re: Create a case-insensitive startsWith

2015-04-28 Thread weaselcat via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 21:45:10 UTC, PhilipDaniels wrote: Beginner question. Given if (startsWith(input, 0x, 0X)) How do I turn that into a case-insensitive startsWith? startsWith says it takes a predicate but I can't figure out how to pass it one. The examples all use a == b !?

Create a case-insensitive startsWith

2015-04-28 Thread PhilipDaniels via Digitalmars-d-learn
Beginner question. Given if (startsWith(input, 0x, 0X)) How do I turn that into a case-insensitive startsWith? startsWith says it takes a predicate but I can't figure out how to pass it one. The examples all use a == b !? These attempts below, and other things I have tried, fail with

Re: @disable assignment of [] literal?

2015-04-28 Thread Kagamin via Digitalmars-d-learn
Looks like it does: http://dpaste.dzfl.pl/a851acca63d9

[dvm] Can't install compilers on Mac

2015-04-28 Thread Chris via Digitalmars-d-learn
I keep getting this message. Why? Fetching: http://ftp.digitalmars.com/dmd.2.067.0.zip [] 56256/54884 KB Installing: dmd-2.067.0 An unknown error occurred: tango.core.Exception.IOException@/Users/doob/development/d/tango/tango/core/Exception.d(59):

Is there something like apply?

2015-04-28 Thread Robert M. Münch via Digitalmars-d-learn
Hi, I have the following problem: I have the parameters for a function in an array. Now I want to call a function with a specific arity and use the parameters from the array to call it. Like this pseudo-code: args = [10, 20]; def foo(a, b): return a + b; print(foo(*args)); Is something

Re: Is there something like apply?

2015-04-28 Thread Adam D. Ruppe via Digitalmars-d-learn
Easiest is to just do it by hand: foo(args[0], args[1]); This can also be automated with a bit of code in a lot of cases: import std.traits; ParameterTypeTuple!foo params; foreach(index, ref param; params) { params[index] = args[index]; } foo(params); Move that into a helper function

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 16:06:16 UTC, Andrea Fontana wrote: On Tuesday, 28 April 2015 at 13:59:48 UTC, Ivan Kazmenko wrote: On Tuesday, 28 April 2015 at 10:46:54 UTC, Gary Willoughby wrote: After reading the following thread:

Re: Is there something like apply?

2015-04-28 Thread Ali Çehreli via Digitalmars-d-learn
On 04/28/2015 10:48 AM, Robert M. Münch wrote: Hi, I have the following problem: I have the parameters for a function in an array. Now I want to call a function with a specific arity and use the parameters from the array to call it. Like this pseudo-code: args = [10, 20]; def foo(a, b):

Readonly-to-outside variable

2015-04-28 Thread tcak via Digitalmars-d-learn
Is there any way to define a variable or an attribute as read-only without defining a getter function/method for it? Thoughts behind this question are: 1. For every reading, another function call process for CPU while it could directly read the value from memory. 2. Repetition of same name

Re: Readonly-to-outside variable

2015-04-28 Thread Justin Whear via Digitalmars-d-learn
On Tue, 28 Apr 2015 19:30:04 +, tcak wrote: Is there any way to define a variable or an attribute as read-only without defining a getter function/method for it? Thoughts behind this question are: 1. For every reading, another function call process for CPU while it could directly read