logo       

Re: Escaping cannot be mixed with values: msg#00060

lang.scala

Subject: Re: Escaping cannot be mixed with values

Hello Molár,

First of all sorry for answering this late. You are right, the phonebook3 example contained several errors, some syntactic, and some logical.

Since it would be too embarrassing to go through the errors :-o, I just put an updated version on http://lamp.epfl.ch/~emir/projects/scalaxbook/scalaxbook.docbk.html

The error message you give in the subject line is a known limitation - you cannot mix sequences with values in order to get a new sequence.

Recalling that the last parameter of Elem is of type Node*, it means you can do
Elem(........., myList:_*)
to pass a value that is already a sequence but you cannot do
Elem(........., myfirstNode, mySecondNode, mySeq:_*)
in order to construct a new sequence from new values and existing sequences.
The workaround is to construct a list yourself, before passing it in an escaped fashion e.g.
Elem(........., ( myfirstNode :: mySecondNode :: mySeq.toList ):_*).

Since Scala >= 1.4 there is a method `concat' in trait Seq that allows sequences to be concated in constant time (but it will make iteration a bit slower). So you can avoid the `.toList' if you fear performance will be negatively affected.

I had that feature (mixing sequences and values) built in for a while (the compiler would construct the list for you), but we decided that it was to hard to specify and to sequence-specific. No nice xduce style embedded sequences, I am afraid.

hope this helps.
Burak

Molnár Balázs wrote:

Hello,

I am new to Scala and tried some of the XML examples I found on the net.
One of the examples I began was the "phonebook3" example changing the phone number. I noticed the example did
not work as I expected so I replaced the XML literals to Elem construction style - to get a correct syntax highlighting in JEdit - and this is the part I have a problem with:
---------------------
else // was present and changed
/* original XML literal style code:
<entry>
<name>{ Name }</name>
<phone where={ Where }>{ ch2 }</phone>
</entry>
*/
Elem(null, "entry", Null, TopScope,
/* Elem(null, "name", Null, TopScope, Text(Name)), <- this I could not used together with escaping ch2 */
ch2:_*)
-------------------

The original code attempts to replace the <phone ...> entries but instead embeds the changed <phone ..> entries represented by 'ch2' within a 'dummy' <phone...> entry. The solution to the problem would seem to uncomment the line before the last
-------------------
/* Elem(null, "name", Null, TopScope, Text(Name)), */
-------------------

but then I recieved an error message saying:
-------------------
/phonebook3.scala:59: escaping cannot be mixed with values ch2:_*)
-------------------

True, I wanted to place a name entry followed by the sequence of the new phone numbers stored in 'ch2'.

Can someone help a beginner how to solve this ?

regards,
Balazs








--
Burak Emir

http://lamp.epfl.ch/~emir




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise