www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Using import in map

reply Jacob Carlborg <doob me.com> writes:
Is this supposed to work:

enum foo = ["foo"].map!((string e) => import(e));

When I compile the above code with 2.066.1 I get the following error:

main.d(1): Error: variable e cannot be read at compile time
main.d(1): Error: file name argument must be a string, not (__error)

-- 
/Jacob Carlborg
Jan 31 2015
parent reply "Stefan Koch" <uplink.coder googlemail.com> writes:
On Saturday, 31 January 2015 at 19:52:11 UTC, Jacob Carlborg 
wrote:
 Is this supposed to work:

 enum foo = ["foo"].map!((string e) => import(e));

 When I compile the above code with 2.066.1 I get the following 
 error:

 main.d(1): Error: variable e cannot be read at compile time
 main.d(1): Error: file name argument must be a string, not 
 (__error)
I think this is not supposed to work. try staticMap maybe ?
Jan 31 2015
parent reply Jacob Carlborg <doob me.com> writes:
On 2015-01-31 20:54, Stefan Koch wrote:

 I think this is not supposed to work.
 try staticMap maybe ?
Yes, staticMap worked, thanks. I filed a bug [1]. If I recall correctly, if the compiler outputs a message which includes "__error" it's a bug. [1] -- /Jacob Carlborg
Jan 31 2015
parent reply "Dicebot" <public dicebot.lv> writes:
On Saturday, 31 January 2015 at 21:09:44 UTC, Jacob Carlborg 
wrote:
 On 2015-01-31 20:54, Stefan Koch wrote:

 I think this is not supposed to work.
 try staticMap maybe ?
Yes, staticMap worked, thanks. I filed a bug [1]. If I recall correctly, if the compiler outputs a message which includes "__error" it's a bug. [1]
Is it? "__error" is simply a placeholder for type of expression that can't be deduced because of compilation error. Original snippet shouldn't compiler because landa argument is run-time one but `import` must work at CT.
Feb 01 2015
next sibling parent "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"Dicebot"  wrote in message news:jscikdikdbjxlkcwybtd forum.dlang.org...

 Yes, staticMap worked, thanks. I filed a bug [1]. If I recall correctly, 
 if the compiler outputs a message which includes "__error" it's a bug.
 Is it? "__error" is simply a placeholder for type of expression that can't 
 be deduced because of compilation error.
Yeah, only the first error should be shown and the second should be supressed because it refers to an earlier error.
Feb 01 2015
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2015-02-01 11:53, Dicebot wrote:

 Original snippet shouldn't compiler because landa argument is run-time
 one but `import` must work at CT.
It is resolved at compile time. Is this a CTFE vs CT problem? -- /Jacob Carlborg
Feb 01 2015
parent "Dicebot" <public dicebot.lv> writes:
On Sunday, 1 February 2015 at 12:21:59 UTC, Jacob Carlborg wrote:
 On 2015-02-01 11:53, Dicebot wrote:

 Original snippet shouldn't compiler because landa argument is 
 run-time
 one but `import` must work at CT.
It is resolved at compile time. Is this a CTFE vs CT problem?
CTFE function is still considered runtime function in terms of restrictions because generally there is no way to tell what context it will be evaluated in. In this specific case it is clear but making use of it would require brand new language spec. Your code is similar to this: int foo (string s) { pragma(msg, s); return 42; } enum ct = foo("str");
Feb 01 2015