This page is no longer maintained — Please continue to the home page at www.scala-lang.org

slurp

5 replies
H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.

hi there,
why isn't slurp (on file) parameterless? what's the side effect?

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: slurp


On Thu, Jul 28, 2011 at 7:38 PM, HamsterofDeath <h-star [at] gmx [dot] de> wrote:
hi there,
why isn't slurp (on file) parameterless? what's the side effect?

Reading from the file system?

--
Viktor Klang

Akka Tech LeadTypesafe - Enterprise-Grade Scala from the Experts

Twitter: @viktorklang
dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
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.

H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
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?

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
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.

Tom Switzer
Joined: 2011-07-19,
User offline. Last seen 42 years 45 weeks ago.
Re: slurp
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.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland