Escape strings for compiler

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Escape strings for compiler

NorbertHartl
Hi,

I tried to compile a method that returns a string.  Is there a method to escape a string in a way that the compiler treats it as a string and not as code?

thanks,

Norbert


_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Escape strings for compiler

Marcus Denker-4

On Jul 26, 2010, at 10:09 AM, Norbert Hartl wrote:

> Hi,
>
> I tried to compile a method that returns a string.  Is there a method to escape a string in a way that the compiler treats it as a string and not as code?
>


If you want to return something that again can be evaluated as a string, you can use double quotes inside:

Compiler evaluate: ' '' evaluate me, I am a String '' '  


--
Marcus Denker  -- http://www.marcusdenker.de
INRIA Lille -- Nord Europe. Team RMoD.


_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Escape strings for compiler

NorbertHartl

On 26.07.2010, at 10:27, Marcus Denker wrote:


On Jul 26, 2010, at 10:09 AM, Norbert Hartl wrote:

Hi,

I tried to compile a method that returns a string.  Is there a method to escape a string in a way that the compiler treats it as a string and not as code?



If you want to return something that again can be evaluated as a string, you can use double quotes inside:

Compiler evaluate: ' '' evaluate me, I am a String '' '  

I want to compile a method

myString
^ 'arbitrary string'

So the problem is more of how would you do what you suggested having the string: evaluate me, I'm a String ?

Norbert

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Escape strings for compiler

Marcus Denker-4

On Jul 26, 2010, at 10:38 AM, Norbert Hartl wrote:

>
> On 26.07.2010, at 10:27, Marcus Denker wrote:
>
>>
>> On Jul 26, 2010, at 10:09 AM, Norbert Hartl wrote:
>>
>>> Hi,
>>>
>>> I tried to compile a method that returns a string.  Is there a method to escape a string in a way that the compiler treats it as a string and not as code?
>>>
>>
>>
>> If you want to return something that again can be evaluated as a string, you can use double quotes inside:
>>
>> Compiler evaluate: ' '' evaluate me, I am a String '' '  
>>
> I want to compile a method
>
> myString
> ^ 'arbitrary string'
>
> So the problem is more of how would you do what you suggested having the string: evaluate me, I'm a String ?

If you alreadu have a string and you want to print it in a way that they compiler can evaluate it back, you can just
use #printString on the string.

printString calls storeOn:, which doubles any contained quotes and puts quotes around. This is called when doing
a "print it", too.

So one gets a bit confusted when doing a "print it" of 'hello' printString... it's called twice :-)

        Marcus

--
Marcus Denker  -- http://www.marcusdenker.de
INRIA Lille -- Nord Europe. Team RMoD.


_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Escape strings for compiler

Marcus Denker-4

On Jul 26, 2010, at 10:56 AM, Marcus Denker wrote:

>
> On Jul 26, 2010, at 10:38 AM, Norbert Hartl wrote:
>
>>
>> On 26.07.2010, at 10:27, Marcus Denker wrote:
>>
>>>
>>> On Jul 26, 2010, at 10:09 AM, Norbert Hartl wrote:
>>>
>>>> Hi,
>>>>
>>>> I tried to compile a method that returns a string.  Is there a method to escape a string in a way that the compiler treats it as a string and not as code?
>>>>
>>>
>>>
>>> If you want to return something that again can be evaluated as a string, you can use double quotes inside:
>>>
>>> Compiler evaluate: ' '' evaluate me, I am a String '' '  
>>>
>> I want to compile a method
>>
>> myString
>> ^ 'arbitrary string'
>>
>> So the problem is more of how would you do what you suggested having the string: evaluate me, I'm a String ?
>
> If you alreadu have a string and you want to print it in a way that they compiler can evaluate it back, you can just
> use #printString on the string.
>
#storeString is even better... as it does not shorten very long strings ;-)



--
Marcus Denker  -- http://www.marcusdenker.de
INRIA Lille -- Nord Europe. Team RMoD.


_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Escape strings for compiler

NorbertHartl

On 26.07.2010, at 11:00, Marcus Denker wrote:


On Jul 26, 2010, at 10:56 AM, Marcus Denker wrote:


On Jul 26, 2010, at 10:38 AM, Norbert Hartl wrote:


On 26.07.2010, at 10:27, Marcus Denker wrote:


On Jul 26, 2010, at 10:09 AM, Norbert Hartl wrote:

Hi,

I tried to compile a method that returns a string.  Is there a method to escape a string in a way that the compiler treats it as a string and not as code?



If you want to return something that again can be evaluated as a string, you can use double quotes inside:

Compiler evaluate: ' '' evaluate me, I am a String '' '  

I want to compile a method

myString
^ 'arbitrary string'

So the problem is more of how would you do what you suggested having the string: evaluate me, I'm a String ?

If you alreadu have a string and you want to print it in a way that they compiler can evaluate it back, you can just
use #printString on the string.

#storeString is even better... as it does not shorten very long strings ;-)

Well... yes! :) It was indeed a longer xml document that I wanted to store

thanks, works good,

Norbert


_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users