2011/7/28 √iktor Ҡlang :
>
>
> On Thu, Jul 28, 2011 at 7:38 PM, HamsterofDeath wrote:
>>
>> hi there,
>> why isn't slurp (on file) parameterless? what's the side effect?
>
> Reading from the file system?
If you replace slurp with the contents of the file, it doesn't affect
the rest of the program. The problem here is that a file is equivalent
to a mutable object.
Am 28.07.2011 19:53, schrieb Daniel Sobral:
> 2011/7/28 √iktor Ҡlang :
>>
>> On Thu, Jul 28, 2011 at 7:38 PM, HamsterofDeath wrote:
>>> hi there,
>>> why isn't slurp (on file) parameterless? what's the side effect?
>> Reading from the file system?
if that's a side effect, reading a variable from memory also is
> If you replace slurp with the contents of the file, it doesn't affect
> the rest of the program. The problem here is that a file is equivalent
> to a mutable object.
>
so the braces are a warning that the result of the call might change?
On Thu, Jul 28, 2011 at 15:41, HamsterofDeath wrote:
>
> Am 28.07.2011 19:53, schrieb Daniel Sobral:
>> 2011/7/28 √iktor Ҡlang :
>>>
>>> On Thu, Jul 28, 2011 at 7:38 PM, HamsterofDeath wrote:
>>>> hi there,
>>>> why isn't slurp (on file) parameterless? what's the side effect?
>>> Reading from the file system?
> if that's a side effect, reading a variable from memory also is
>> If you replace slurp with the contents of the file, it doesn't affect
>> the rest of the program. The problem here is that a file is equivalent
>> to a mutable object.
>>
> so the braces are a warning that the result of the call might change?
Yes. A call to the same method with the same parameters ought to
result in the same value in a side effect-less environment.
Hello,There is a difference between memory & files. Files are an abstraction, and don't necessarily represent actual static data on a disk. For example, cat << EOF > abc.scala
val f = scala.tools.nsc.io.File("abc")println(f.slurp())println(f.slurp())EOFmkfifo abcscala abc.scala &echo "Hello, world" > abc
echo "Goodbye, world" > abc In this case, reading from abc causes side effects. Memory is different, since the CPU, OS, compilers, and run-time VMs go to great lengths to ensure the protection of our memory from these kind of side-effects and outside interference.
Re: slurp
On Thu, Jul 28, 2011 at 7:38 PM, HamsterofDeath <h-star [at] gmx [dot] de> wrote:
Reading from the file system?
--
Viktor Klang
Akka Tech LeadTypesafe - Enterprise-Grade Scala from the Experts
Twitter: @viktorklang
Re: slurp
2011/7/28 √iktor Ҡlang :
>
>
> On Thu, Jul 28, 2011 at 7:38 PM, HamsterofDeath wrote:
>>
>> hi there,
>> why isn't slurp (on file) parameterless? what's the side effect?
>
> Reading from the file system?
If you replace slurp with the contents of the file, it doesn't affect
the rest of the program. The problem here is that a file is equivalent
to a mutable object.
Re: slurp
Am 28.07.2011 19:53, schrieb Daniel Sobral:
> 2011/7/28 √iktor Ҡlang :
>>
>> On Thu, Jul 28, 2011 at 7:38 PM, HamsterofDeath wrote:
>>> hi there,
>>> why isn't slurp (on file) parameterless? what's the side effect?
>> Reading from the file system?
if that's a side effect, reading a variable from memory also is
> If you replace slurp with the contents of the file, it doesn't affect
> the rest of the program. The problem here is that a file is equivalent
> to a mutable object.
>
so the braces are a warning that the result of the call might change?
Re: slurp
On Thu, Jul 28, 2011 at 15:41, HamsterofDeath wrote:
>
> Am 28.07.2011 19:53, schrieb Daniel Sobral:
>> 2011/7/28 √iktor Ҡlang :
>>>
>>> On Thu, Jul 28, 2011 at 7:38 PM, HamsterofDeath wrote:
>>>> hi there,
>>>> why isn't slurp (on file) parameterless? what's the side effect?
>>> Reading from the file system?
> if that's a side effect, reading a variable from memory also is
>> If you replace slurp with the contents of the file, it doesn't affect
>> the rest of the program. The problem here is that a file is equivalent
>> to a mutable object.
>>
> so the braces are a warning that the result of the call might change?
Yes. A call to the same method with the same parameters ought to
result in the same value in a side effect-less environment.
Re: slurp
cat << EOF > abc.scala val f = scala.tools.nsc.io.File("abc")println(f.slurp())println(f.slurp())EOFmkfifo abcscala abc.scala &echo "Hello, world" > abc echo "Goodbye, world" > abc
In this case, reading from abc causes side effects. Memory is different, since the CPU, OS, compilers, and run-time VMs go to great lengths to ensure the protection of our memory from these kind of side-effects and outside interference.