String interpolation with code containing strings

2 views
Skip to first unread message

Rodrigo de Salvo Braz

unread,
Mar 15, 2008, 3:38:23 AM3/15/08
to Nemerle Forum
Hi,

I notice that

Nemerle.IO.print("This is string interpolation: $(if (true) "true";
else "false";)");

won't compile. I guess the nested strings confuse the parser. Is this
a bug? In principle it seems that it can be avoided although it may
complicate the parser.

I am asking because I was considering writing a note about it in the
"Grokking" section.

Thanks!

Rodrigo

VladD2

unread,
Mar 15, 2008, 5:24:57 AM3/15/08
to nemer...@googlegroups.com
Hi,

2008/3/15, Rodrigo de Salvo Braz <rodri...@gmail.com>:


> won't compile. I guess the nested strings confuse the parser. Is this
> a bug?

No. This is by design. Use nested string instead:
Nemerle.IO.print(<#This is string interpolation: $(if (true) "true";
else "false";)#>);

> In principle it seems that it can be avoided although it may
> complicate the parser.

The "print" is a macro which take string in parameter. You try pass to
it following literals:
1) "This is string interpolation: $(if (true) "
2) true
3) "; else "
4) false
5) ";)"

Reply all
Reply to author
Forward
0 new messages