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

Re: Re assignment to Val

37 replies
Kevin Wright
Joined: 2009-06-09,
User offline. Last seen 49 weeks 3 days ago.
can you post the actual code snippet where this is happening?

On Mon, Jul 6, 2009 at 11:22 PM, Joob <travaildereligion@hotmail.com> wrote:

Hello everyone,

I'm new to scala so please don't take anything for granted with me :)

Anyway,
I'm getting this error "Reassignment to val"

Let me explain the context : My application is a simple phonebook and a few
commands on it
I have a list of Adress, which is empty at first, but you can fill it up
eventually with user input entries.

Since lists cannot be modified, the code I'm writing for the "add entry
function" goes something like this:

I create a new Adress object from user input
I put it in a List by itself
I create a new List from the Phonebook List where I filter out an identical
entry to the one I'm about to put in
I merge the two new Lists
I try to do something like : PhonebookList = newList

this is where I get my error.
Everything up to there seems fine.

Can anyone help me ?
--
View this message in context: http://www.nabble.com/Reassignment-to-Val-tp24363871p24363871.html
Sent from the Scala - User mailing list archive at Nabble.com.


Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

var tempAdr = new Adresse(tempNom, tempNum, tempRue, tempVille);
var tempAdreListe = List(tempAdr)

var tempB = botin.filter(n => n.individu != tempNom);
var resultat = tempB ::: tempAdreListe;

botin = resultat

The variable names I use are in french
sorry :(
but its not very complicated I believe

Kevin Wright-4 wrote:
>
> can you post the actual code snippet where this is happening?
>
> On Mon, Jul 6, 2009 at 11:22 PM, Joob
> wrote:
>
>>
>> Hello everyone,
>>
>> I'm new to scala so please don't take anything for granted with me :)
>>
>> Anyway,
>> I'm getting this error "Reassignment to val"
>>
>> Let me explain the context : My application is a simple phonebook and a
>> few
>> commands on it
>> I have a list of Adress, which is empty at first, but you can fill it up
>> eventually with user input entries.
>>
>> Since lists cannot be modified, the code I'm writing for the "add entry
>> function" goes something like this:
>>
>> I create a new Adress object from user input
>> I put it in a List by itself
>> I create a new List from the Phonebook List where I filter out an
>> identical
>> entry to the one I'm about to put in
>> I merge the two new Lists
>> I try to do something like : PhonebookList = newList
>>
>> this is where I get my error.
>> Everything up to there seems fine.
>>
>> Can anyone help me ?
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24363871.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>
var tempAdr = new Adresse(tempNom, tempNum, tempRue, tempVille);
var tempAdreListe = List(tempAdr)

var tempB = botin.filter(n => n.individu != tempNom);
var resultat = tempB ::: tempAdreListe;

botin = resultat

Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Re assignment to Val

On Monday July 6 2009, Joob wrote:
> Hello everyone,
>
> I'm new to scala so please don't take anything for granted with me :)

Well, you see, computers are these electronical machines that we use to
make like difficult for others...

> Anyway,
> I'm getting this error "Reassignment to val"

A "val" is an "immutable" record of a value. By immutable we mean it
cannot be reassigned. There are lots of positive virtues to defining
programs in terms of immutable data, but it's sometimes challenging to
do so. Unlike Haskell, which is considered a "pure" functional language
that strictly forbids such "side-effects" and "mutable state," Scala
doesn't force you to use immutable data. When you feel the need to be
able to reassign the value in a field or local variable (or function /
method parameter), you can use a "var" instead of a val.

> ...
>
> Can anyone help me ?

Anything could happen...

Randall Schulz

Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Re assignment to Val

On Monday July 6 2009, Joob wrote:
> var tempAdr = new Adresse(tempNom, tempNum, tempRue, tempVille);
> var tempAdreListe = List(tempAdr)
>
> var tempB = botin.filter(n => n.individu != tempNom);
> var resultat = tempB ::: tempAdreListe;
>
> botin = resultat
>
>
> The variable names I use are in french
> sorry :(
> but its not very complicated I believe

Where does the diagnostic occur? Where and how is "botin" declared?

Randall Schulz

Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re assignment to Val

Hello everyone,

I'm new to scala so please don't take anything for granted with me :)

Anyway,
I'm getting this error "Reassignment to val"

Let me explain the context : My application is a simple phonebook and a few
commands on it
I have a list of Adress, which is empty at first, but you can fill it up
eventually with user input entries.

Since lists cannot be modified, the code I'm writing for the "add entry
function" goes something like this:

I create a new Adress object from user input
I put it in a List by itself
I create a new List from the Phonebook List where I filter out an identical
entry to the one I'm about to put in
I merge the two new Lists
I try to do something like : PhonebookList = newList

this is where I get my error.
Everything up to there seems fine.

Can anyone help me ?

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

Where is botin declared?

-------------------------------------
Joob wrote:

var tempAdr = new Adresse(tempNom, tempNum, tempRue, tempVille);
var tempAdreListe = List(tempAdr)

var tempB = botin.filter(n => n.individu != tempNom);
var resultat = tempB ::: tempAdreListe;

botin = resultat

The variable names I use are in french
sorry :(
but its not very complicated I believe

Kevin Wright-4 wrote:
>
> can you post the actual code snippet where this is happening?
>
> On Mon, Jul 6, 2009 at 11:22 PM, Joob
> wrote:
>
>>
>> Hello everyone,
>>
>> I'm new to scala so please don't take anything for granted with me :)
>>
>> Anyway,
>> I'm getting this error "Reassignment to val"
>>
>> Let me explain the context : My application is a simple phonebook and a
>> few
>> commands on it
>> I have a list of Adress, which is empty at first, but you can fill it up
>> eventually with user input entries.
>>
>> Since lists cannot be modified, the code I'm writing for the "add entry
>> function" goes something like this:
>>
>> I create a new Adress object from user input
>> I put it in a List by itself
>> I create a new List from the Phonebook List where I filter out an
>> identical
>> entry to the one I'm about to put in
>> I merge the two new Lists
>> I try to do something like : PhonebookList = newList
>>
>> this is where I get my error.
>> Everything up to there seems fine.
>>
>> Can anyone help me ?
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24363871.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>
var tempAdr = new Adresse(tempNom, tempNum, tempRue, tempVille);
var tempAdreListe = List(tempAdr)

var tempB = botin.filter(n => n.individu != tempNom);
var resultat = tempB ::: tempAdreListe;

botin = resultat

Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

the error occurs at

botin = resultat

Randall Schulz wrote:
>
> On Monday July 6 2009, Joob wrote:
>> var tempAdr = new Adresse(tempNom, tempNum, tempRue, tempVille);
>> var tempAdreListe = List(tempAdr)
>>
>> var tempB = botin.filter(n => n.individu != tempNom);
>> var resultat = tempB ::: tempAdreListe;
>>
>> botin = resultat
>>
>>
>> The variable names I use are in french
>> sorry :(
>> but its not very complicated I believe
>
> Where does the diagnostic occur? Where and how is "botin" declared?
>
>
> Randall Schulz
>
>

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

Is PhonebookList a val or singleton object? They are immutable.
Change a val to a var.

-------------------------------------
Kevin Wright wrote:

can you post the actual code snippet where this is happening?

On Mon, Jul 6, 2009 at 11:22 PM, Joob wrote:

>
> Hello everyone,
>
> I'm new to scala so please don't take anything for granted with me :)
>
> Anyway,
> I'm getting this error "Reassignment to val"
>
> Let me explain the context : My application is a simple phonebook and a few
> commands on it
> I have a list of Adress, which is empty at first, but you can fill it up
> eventually with user input entries.
>
> Since lists cannot be modified, the code I'm writing for the "add entry
> function" goes something like this:
>
> I create a new Adress object from user input
> I put it in a List by itself
> I create a new List from the Phonebook List where I filter out an identical
> entry to the one I'm about to put in
> I merge the two new Lists
> I try to do something like : PhonebookList = newList
>
> this is where I get my error.
> Everything up to there seems fine.
>
> Can anyone help me ?
> --
> View this message in context:
> http://www.nabble.com/Reassignment-to-Val-tp24363871p24363871.html
> Sent from the Scala - User mailing list archive at Nabble.com.
>
>

Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Re assignment to Val

On Monday July 6 2009, Joob wrote:
> the error occurs at
>
> botin = resultat

Then I venture to guess that it is the val that you need to make a var.

In fact, I know it is, 'cause a statement like that in isolation will
alway be illegal for a val, since they get their values at the point of
declaration, never later.

Randall Schulz

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

A variable is a name that references an object. When you pass an object to a function the object is available to the function under another name. If that name would be a var it would allow you to assign another object to the function's variable name but main's variable would still point to the old object.
Two options are return the new value from the function, or pass a mutable container.

-------------------------------------
Joob wrote:

Well,

I declared the list as a "var" in my main

However it is a function parameter where I have the error

What do I have to do to make sure it stays a "var" and not a "val" ?
(If that is what I have to do, maybe I'm misunderstanding)

Randall Schulz wrote:
>
> On Monday July 6 2009, Joob wrote:
>> Hello everyone,
>>
>> I'm new to scala so please don't take anything for granted with me :)
>
> Well, you see, computers are these electronical machines that we use to
> make like difficult for others...
>
>
>> Anyway,
>> I'm getting this error "Reassignment to val"
>
> A "val" is an "immutable" record of a value. By immutable we mean it
> cannot be reassigned. There are lots of positive virtues to defining
> programs in terms of immutable data, but it's sometimes challenging to
> do so. Unlike Haskell, which is considered a "pure" functional language
> that strictly forbids such "side-effects" and "mutable state," Scala
> doesn't force you to use immutable data. When you feel the need to be
> able to reassign the value in a field or local variable (or function /
> method parameter), you can use a "var" instead of a val.
>
>
>> ...
>>
>> Can anyone help me ?
>
> Anything could happen...
>
>
> Randall Schulz
>
>

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

But that won't help.

-------------------------------------
Randall R Schulz wrote:

On Monday July 6 2009, Joob wrote:
> Well,
>
> I declared the list as a "var" in my main
>
> However it is a function parameter where I have the error
>
> What do I have to do to make sure it stays a "var" and not a "val" ?
> (If that is what I have to do, maybe I'm misunderstanding)

You may prefix a formal parameter name with "var" to make it
reassignable.

Randall Schulz

Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

Well,

I declared the list as a "var" in my main

However it is a function parameter where I have the error

What do I have to do to make sure it stays a "var" and not a "val" ?
(If that is what I have to do, maybe I'm misunderstanding)

Randall Schulz wrote:
>
> On Monday July 6 2009, Joob wrote:
>> Hello everyone,
>>
>> I'm new to scala so please don't take anything for granted with me :)
>
> Well, you see, computers are these electronical machines that we use to
> make like difficult for others...
>
>
>> Anyway,
>> I'm getting this error "Reassignment to val"
>
> A "val" is an "immutable" record of a value. By immutable we mean it
> cannot be reassigned. There are lots of positive virtues to defining
> programs in terms of immutable data, but it's sometimes challenging to
> do so. Unlike Haskell, which is considered a "pure" functional language
> that strictly forbids such "side-effects" and "mutable state," Scala
> doesn't force you to use immutable data. When you feel the need to be
> able to reassign the value in a field or local variable (or function /
> method parameter), you can use a "var" instead of a val.
>
>
>> ...
>>
>> Can anyone help me ?
>
> Anything could happen...
>
>
> Randall Schulz
>
>

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Re assignment to Val
If it is a function parameter, then the main's botin is no longer visible. When you "change" botin, you are trying to change the function parameter, which is not possible (no workaround either).   You should use the full path when trying to change botin:   scala> object a {
     | var x = 0;
     | def f(x: Int) = { a.x = x }
     | }
defined module a scala> a.x
res18: Int = 0 scala> a.f(5) scala> a.x
res20: Int = 5   See how I access a's x inside f?   By the way, by changing the a "global" variable from inside a function you are doing the worst possible sin known to functional programming. Scala allows you to do that, but I advise you to try to change that.

On Mon, Jul 6, 2009 at 7:38 PM, Joob <travaildereligion@hotmail.com> wrote:

Well,

I declared the list as a "var" in my main

However it is a function parameter where I have the error

What do I have to do to make sure it stays a "var" and not a "val" ?
(If that is what I have to do, maybe I'm misunderstanding)



Randall Schulz wrote:
>
> On Monday July 6 2009, Joob wrote:
>> Hello everyone,
>>
>> I'm new to scala so please don't take anything for granted with me :)
>
> Well, you see, computers are these electronical machines that we use to
> make like difficult for others...
>
>
>> Anyway,
>> I'm getting this error "Reassignment to val"
>
> A "val" is an "immutable" record of a value. By immutable we mean it
> cannot be reassigned. There are lots of positive virtues to defining
> programs in terms of immutable data, but it's sometimes challenging to
> do so. Unlike Haskell, which is considered a "pure" functional language
> that strictly forbids such "side-effects" and "mutable state," Scala
> doesn't force you to use immutable data. When you feel the need to be
> able to reassign the value in a field or local variable (or function /
> method parameter), you can use a "var" instead of a val.
>
>
>> ...
>>
>> Can anyone help me ?
>
> Anything could happen...
>
>
> Randall Schulz
>
>

--
View this message in context: http://www.nabble.com/Reassignment-to-Val-tp24363871p24364035.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Re assignment to Val

On Monday July 6 2009, Joob wrote:
> Well,
>
> I declared the list as a "var" in my main
>
> However it is a function parameter where I have the error
>
> What do I have to do to make sure it stays a "var" and not a "val" ?
> (If that is what I have to do, maybe I'm misunderstanding)

You may prefix a formal parameter name with "var" to make it
reassignable.

Randall Schulz

Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Re assignment to Val

On Monday July 6 2009, Randall R Schulz wrote:
> On Monday July 6 2009, Joob wrote:
> > Well,
> >
> > I declared the list as a "var" in my main
> >
> > However it is a function parameter where I have the error
> >
> > What do I have to do to make sure it stays a "var" and not a "val"
> > ? (If that is what I have to do, maybe I'm misunderstanding)
>
> You may prefix a formal parameter name with "var" to make it
> reassignable.

That was a lie.

I was thinking of primary constructor parameters, which may be prefixed
by val or var to create fields directly.

Randall Schulz

Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

Daniel Sobral wrote:
>
> If it is a function parameter, then the main's botin is no longer visible.
> When you "change" botin, you are trying to change the function parameter,
> which is not possible (no workaround either).
>
> You should use the full path when trying to change botin:
>
> scala> object a {
> | var x = 0;
> | def f(x: Int) = { a.x = x }
> | }
> defined module a
> scala> a.x
> res18: Int = 0
> scala> a.f(5)
> scala> a.x
> res20: Int = 5
>
> See how I access a's x inside f?
>
> By the way, by changing the a "global" variable from inside a function you
> are doing the worst possible sin known to functional programming. Scala
> allows you to do that, but I advise you to try to change that.
>
>
>
>

So, if i understand correctly (and that's a pretty big if), I should have a
class that has the List as a parameter and a function that allows me to
change it ? Then if I pass the object as a parameter I can still use the
function to make the changes i want ? Won't I have the same problem as
before ?

And I'm not sure how to change my code so I can avoid commiting the worst
possible sin in functional programming :(

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

What language(s) are you coming from?

-------------------------------------
Joob wrote:

Daniel Sobral wrote:
>
> If it is a function parameter, then the main's botin is no longer visible.
> When you "change" botin, you are trying to change the function parameter,
> which is not possible (no workaround either).
>
> You should use the full path when trying to change botin:
>
> scala> object a {
> | var x = 0;
> | def f(x: Int) = { a.x = x }
> | }
> defined module a
> scala> a.x
> res18: Int = 0
> scala> a.f(5)
> scala> a.x
> res20: Int = 5
>
> See how I access a's x inside f?
>
> By the way, by changing the a "global" variable from inside a function you
> are doing the worst possible sin known to functional programming. Scala
> allows you to do that, but I advise you to try to change that.
>
>
>
>

So, if i understand correctly (and that's a pretty big if), I should have a
class that has the List as a parameter and a function that allows me to
change it ? Then if I pass the object as a parameter I can still use the
function to make the changes i want ? Won't I have the same problem as
before ?

And I'm not sure how to change my code so I can avoid commiting the worst
possible sin in functional programming :(

Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

Java, Actionscript, Ruby
Theyre all object oriented, I guess that's why I have trouble with
functional programing

However Scala has some object oriented features as well as functional so I
thought it wouldn't be too complicated, but anyway...

Naftoli Gugenhem wrote:
>
> What language(s) are you coming from?
>
> -------------------------------------
> Joob wrote:
>
>
>
>
> Daniel Sobral wrote:
>>
>> If it is a function parameter, then the main's botin is no longer
>> visible.
>> When you "change" botin, you are trying to change the function parameter,
>> which is not possible (no workaround either).
>>
>> You should use the full path when trying to change botin:
>>
>> scala> object a {
>> | var x = 0;
>> | def f(x: Int) = { a.x = x }
>> | }
>> defined module a
>> scala> a.x
>> res18: Int = 0
>> scala> a.f(5)
>> scala> a.x
>> res20: Int = 5
>>
>> See how I access a's x inside f?
>>
>> By the way, by changing the a "global" variable from inside a function
>> you
>> are doing the worst possible sin known to functional programming. Scala
>> allows you to do that, but I advise you to try to change that.
>>
>>
>>
>>
>
> So, if i understand correctly (and that's a pretty big if), I should have
> a
> class that has the List as a parameter and a function that allows me to
> change it ? Then if I pass the object as a parameter I can still use the
> function to make the changes i want ? Won't I have the same problem as
> before ?
>
> And I'm not sure how to change my code so I can avoid commiting the worst
> possible sin in functional programming :(
>

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

How would you solve your problem in Java? In Java modifying a parameter doesn't affect the variable passed to the function.
vals are Java's final. In Java I believe it is recommended that function parameters should be final.

-------------------------------------
Joob wrote:

Java, Actionscript, Ruby
Theyre all object oriented, I guess that's why I have trouble with
functional programing

However Scala has some object oriented features as well as functional so I
thought it wouldn't be too complicated, but anyway...

Naftoli Gugenhem wrote:
>
> What language(s) are you coming from?
>
> -------------------------------------
> Joob wrote:
>
>
>
>
> Daniel Sobral wrote:
>>
>> If it is a function parameter, then the main's botin is no longer
>> visible.
>> When you "change" botin, you are trying to change the function parameter,
>> which is not possible (no workaround either).
>>
>> You should use the full path when trying to change botin:
>>
>> scala> object a {
>> | var x = 0;
>> | def f(x: Int) = { a.x = x }
>> | }
>> defined module a
>> scala> a.x
>> res18: Int = 0
>> scala> a.f(5)
>> scala> a.x
>> res20: Int = 5
>>
>> See how I access a's x inside f?
>>
>> By the way, by changing the a "global" variable from inside a function
>> you
>> are doing the worst possible sin known to functional programming. Scala
>> allows you to do that, but I advise you to try to change that.
>>
>>
>>
>>
>
> So, if i understand correctly (and that's a pretty big if), I should have
> a
> class that has the List as a parameter and a function that allows me to
> change it ? Then if I pass the object as a parameter I can still use the
> function to make the changes i want ? Won't I have the same problem as
> before ?
>
> And I'm not sure how to change my code so I can avoid commiting the worst
> possible sin in functional programming :(
>

Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

oh
so I should simply return the List and store it ?
that does make more sense, come to think of it...

Naftoli Gugenhem wrote:
>
> How would you solve your problem in Java? In Java modifying a parameter
> doesn't affect the variable passed to the function.
> vals are Java's final. In Java I believe it is recommended that function
> parameters should be final.
>
> -------------------------------------
> Joob wrote:
>
>
> Java, Actionscript, Ruby
> Theyre all object oriented, I guess that's why I have trouble with
> functional programing
>
> However Scala has some object oriented features as well as functional so I
> thought it wouldn't be too complicated, but anyway...
>
>
>
> Naftoli Gugenhem wrote:
>>
>> What language(s) are you coming from?
>>
>> -------------------------------------
>> Joob wrote:
>>
>>
>>
>>
>> Daniel Sobral wrote:
>>>
>>> If it is a function parameter, then the main's botin is no longer
>>> visible.
>>> When you "change" botin, you are trying to change the function
>>> parameter,
>>> which is not possible (no workaround either).
>>>
>>> You should use the full path when trying to change botin:
>>>
>>> scala> object a {
>>> | var x = 0;
>>> | def f(x: Int) = { a.x = x }
>>> | }
>>> defined module a
>>> scala> a.x
>>> res18: Int = 0
>>> scala> a.f(5)
>>> scala> a.x
>>> res20: Int = 5
>>>
>>> See how I access a's x inside f?
>>>
>>> By the way, by changing the a "global" variable from inside a function
>>> you
>>> are doing the worst possible sin known to functional programming. Scala
>>> allows you to do that, but I advise you to try to change that.
>>>
>>>
>>>
>>>
>>
>> So, if i understand correctly (and that's a pretty big if), I should have
>> a
>> class that has the List as a parameter and a function that allows me to
>> change it ? Then if I pass the object as a parameter I can still use the
>> function to make the changes i want ? Won't I have the same problem as
>> before ?
>>
>> And I'm not sure how to change my code so I can avoid commiting the worst
>> possible sin in functional programming :(
>>

Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

But what if I have my main calling a function calling another function which
modifies the list,
or any other scenario where the object wouldn't be directly accessible ?

My application goes through the main only once, then loops in another
function that accepts user input to apply various operations to the list, by
calling other operation-specific function such as "add entry" "delete entry"
etc

Daniel Sobral wrote:
>
> Well, if that's possible, yes, that's what you should do.
>
> On Tue, Jul 7, 2009 at 12:59 AM, Joob
> wrote:
>
>>
>> oh
>> so I should simply return the List and store it ?
>> that does make more sense, come to think of it...
>>
>>
>>
>
>
>

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Re assignment to Val
Well, if that's possible, yes, that's what you should do.

On Tue, Jul 7, 2009 at 12:59 AM, Joob <travaildereligion@hotmail.com> wrote:

oh
so I should simply return the List and store it ?
that does make more sense, come to think of it...



Naftoli Gugenhem wrote:
>
> How would you solve your problem in Java? In Java modifying a parameter
> doesn't affect the variable passed to the function.
> vals are Java's final. In Java I believe it is recommended that function
> parameters should be final.
>
> -------------------------------------
> Joob<travaildereligion@hotmail.com> wrote:
>
>
> Java, Actionscript, Ruby
> Theyre all object oriented, I guess that's why I have trouble with
> functional programing
>
> However Scala has some object oriented features as well as functional so I
> thought it wouldn't be too complicated, but anyway...
>
>
>
> Naftoli Gugenhem wrote:
>>
>> What language(s) are you coming from?
>>
>> -------------------------------------
>> Joob<travaildereligion@hotmail.com> wrote:
>>
>>
>>
>>
>> Daniel Sobral wrote:
>>>
>>> If it is a function parameter, then the main's botin is no longer
>>> visible.
>>> When you "change" botin, you are trying to change the function
>>> parameter,
>>> which is not possible (no workaround either).
>>>
>>> You should use the full path when trying to change botin:
>>>
>>> scala> object a {
>>>      | var x = 0;
>>>      | def f(x: Int) = { a.x = x }
>>>      | }
>>> defined module a
>>> scala> a.x
>>> res18: Int = 0
>>> scala> a.f(5)
>>> scala> a.x
>>> res20: Int = 5
>>>
>>> See how I access a's x inside f?
>>>
>>> By the way, by changing the a "global" variable from inside a function
>>> you
>>> are doing the worst possible sin known to functional programming. Scala
>>> allows you to do that, but I advise you to try to change that.
>>>
>>>
>>>
>>>
>>
>> So, if i understand correctly (and that's a pretty big if), I should have
>> a
>> class that has the List as a parameter and a function that allows me to
>> change it ?  Then if I pass the object as a parameter I can still use the
>> function to make the changes i want ?  Won't I have the same problem as
>> before ?
>>
>> And I'm not sure how to change my code so I can avoid commiting the worst
>> possible sin in functional programming :(
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366622.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366689.html
> Sent from the Scala - User mailing list archive at Nabble.com.
>
>
>

--
View this message in context: http://www.nabble.com/Reassignment-to-Val-tp24363871p24366796.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

You always have two choices: either those functions can return relevant information, or they can modify a var that the function and its caller have access to. The first way I believe is more FP, the second more OOP.
By the way scala makes the first easy even when the function has to return multiple values, using tuples or case classes with pattern matching.

-------------------------------------
Joob wrote:

But what if I have my main calling a function calling another function which
modifies the list,
or any other scenario where the object wouldn't be directly accessible ?

My application goes through the main only once, then loops in another
function that accepts user input to apply various operations to the list, by
calling other operation-specific function such as "add entry" "delete entry"
etc

Daniel Sobral wrote:
>
> Well, if that's possible, yes, that's what you should do.
>
> On Tue, Jul 7, 2009 at 12:59 AM, Joob
> wrote:
>
>>
>> oh
>> so I should simply return the List and store it ?
>> that does make more sense, come to think of it...
>>
>>
>>
>
>
>

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Re assignment to Val
You do not need to keep a var with the list. You can just pass the resulting list back and forth, but, at this point, I don't think that can be taught in this list. You need to see a lot of functional code to get the idea.
So, instead, I'll suggest something for which many here will condemn me (seriously!). Put this object somewhere:
object Botin {  var botin: ... = Nil}
And then assign the results to Botin.botin. It will fix your immediate problem, but programming this way will bring you many other problems.
On Tue, Jul 7, 2009 at 1:08 AM, Joob <travaildereligion@hotmail.com> wrote:

But what if I have my main calling a function calling another function which
modifies the list,
or any other scenario where the object wouldn't be directly accessible ?

My application goes through the main only once, then loops in another
function that accepts user input to apply various operations to the list, by
calling other operation-specific function such as "add entry" "delete entry"
etc



Daniel Sobral wrote:
>
> Well, if that's possible, yes, that's what you should do.
>
> On Tue, Jul 7, 2009 at 12:59 AM, Joob <travaildereligion@hotmail.com>
> wrote:
>
>>
>> oh
>> so I should simply return the List and store it ?
>> that does make more sense, come to think of it...
>>
>>
>>
>
>
>

--
View this message in context: http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
Kevin Wright
Joined: 2009-06-09,
User offline. Last seen 49 weeks 3 days ago.
Re: Re assignment to Val
Immutable values can't be changed, ever, this is by design.
It might first look like you cant doing a lot of things, but to see how this idea works it helps to think about the way that numbers behave.

Take the expression "1 + 2": This takes 1, adds 2, and returns a NEW number, 3
In this case, neither 1 nor 2 have changed, you can use them in other parts of your program and they will mean the same thing they always did.

The same idea can be used with lists:
val x = List(2, 3, 4)
val y = 1 :: x

y is now a new list containing 1, 2, 3, 4, the meaning of x is unchanged
(note: it's always better to work at the head of lists for reasons of performance, but that's a different discussion)

I can also say
val z = y map (n => 2 * n)
This now gives me ANOTHER new list, containing 2, 4, 6, 8, once again x and y are unchanged


Thinking like this is one of the core ideas behind functional programming.

If you have good reason to work differently and you want to have a list x that can change but still be called x, then you have two options:
You can use a MutableList, where x is still a val (as it always point to the same, mutable, list), but the contents of that list can now be modified.
Or you can use a var, where x points to an immutable list, but you can exchange that list for another one at any time.

the only real difference is that you can supply a mutable list to a function, and have the function update it for you.  However, it's better design use an immutable list for the function argument, and have it return another NEW immutable list which has the modifications in.


On Tue, Jul 7, 2009 at 5:18 AM, Naftoli Gugenhem <naftoligug@gmail.com> wrote:
You always have two choices: either those functions can return relevant information, or they can modify a var that the function and its caller have access to. The first way I believe is more FP, the second more OOP.
By the way scala makes the first easy even when the function has to return multiple values, using tuples or case classes with pattern matching.

-------------------------------------
Joob<travaildereligion@hotmail.com> wrote:


But what if I have my main calling a function calling another function which
modifies the list,
or any other scenario where the object wouldn't be directly accessible ?

My application goes through the main only once, then loops in another
function that accepts user input to apply various operations to the list, by
calling other operation-specific function such as "add entry" "delete entry"
etc



Daniel Sobral wrote:
>
> Well, if that's possible, yes, that's what you should do.
>
> On Tue, Jul 7, 2009 at 12:59 AM, Joob <travaildereligion@hotmail.com>
> wrote:
>
>>
>> oh
>> so I should simply return the List and store it ?
>> that does make more sense, come to think of it...
>>
>>
>>
>
>
>

--
View this message in context: http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
Sent from the Scala - User mailing list archive at Nabble.com.


Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

I have tried this method, but now I get an error when I try to use a List
method on Botin.botin
this is the code :

var tempB = Botin.botin.filter(n => n.individu != tempNom);

The error I get is : value filter is not a member of object List.
If i understand correctly this means that "filter" is not recognized as
neither a parameter of botin nor a function that can be applied to a List,
which is odd to me since "filter" is a function that can be applied to a
List no ?

p.s.: I'm using netbeans at the moment and when I type "Botin.botin." it
then shows the possible function calls I can make, I recognize a few from
the Scala Library for List such as "apply" but "filter" and a few others are
missing.

Daniel Sobral wrote:
>
> You do not need to keep a var with the list. You can just pass the
> resulting
> list back and forth, but, at this point, I don't think that can be taught
> in
> this list. You need to see a lot of functional code to get the idea.
> So, instead, I'll suggest something for which many here will condemn me
> (seriously!). Put this object somewhere:
>
> object Botin {
> var botin: ... = Nil
> }
>
> And then assign the results to Botin.botin. It will fix your immediate
> problem, but programming this way will bring you many other problems.
>
> On Tue, Jul 7, 2009 at 1:08 AM, Joob
> wrote:
>
>>
>> But what if I have my main calling a function calling another function
>> which
>> modifies the list,
>> or any other scenario where the object wouldn't be directly accessible ?
>>
>> My application goes through the main only once, then loops in another
>> function that accepts user input to apply various operations to the list,
>> by
>> calling other operation-specific function such as "add entry" "delete
>> entry"
>> etc
>>
>>
>>
>> Daniel Sobral wrote:
>> >
>> > Well, if that's possible, yes, that's what you should do.
>> >
>> > On Tue, Jul 7, 2009 at 12:59 AM, Joob
>> > wrote:
>> >
>> >>
>> >> oh
>> >> so I should simply return the List and store it ?
>> >> that does make more sense, come to think of it...
>> >>
>> >>
>> >>
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>

Kevin Wright
Joined: 2009-06-09,
User offline. Last seen 49 weeks 3 days ago.
Re: Re assignment to Val
We'll need to see some more code (especially the Botin object definition you used). Also what version of scala are you using?

On Thu, Jul 9, 2009 at 4:45 PM, Joob <travaildereligion@hotmail.com> wrote:

I have tried this method, but now I get an error when I try to use a List
method on Botin.botin
this is the code :

var tempB = Botin.botin.filter(n => n.individu != tempNom);

The error I get is : value filter is not a member of object List.
If i understand correctly this means that "filter" is not recognized as
neither a parameter of botin nor a function that can be applied to a List,
which is odd to me since "filter" is a function that can be applied to a
List no ?

p.s.: I'm using netbeans at the moment and when I type "Botin.botin." it
then shows the possible function calls I can make, I recognize a few from
the Scala Library for List such as "apply" but "filter" and a few others are
missing.



Daniel Sobral wrote:
>
> You do not need to keep a var with the list. You can just pass the
> resulting
> list back and forth, but, at this point, I don't think that can be taught
> in
> this list. You need to see a lot of functional code to get the idea.
> So, instead, I'll suggest something for which many here will condemn me
> (seriously!). Put this object somewhere:
>
> object Botin {
>   var botin: ... = Nil
> }
>
> And then assign the results to Botin.botin. It will fix your immediate
> problem, but programming this way will bring you many other problems.
>
> On Tue, Jul 7, 2009 at 1:08 AM, Joob <travaildereligion@hotmail.com>
> wrote:
>
>>
>> But what if I have my main calling a function calling another function
>> which
>> modifies the list,
>> or any other scenario where the object wouldn't be directly accessible ?
>>
>> My application goes through the main only once, then loops in another
>> function that accepts user input to apply various operations to the list,
>> by
>> calling other operation-specific function such as "add entry" "delete
>> entry"
>> etc
>>
>>
>>
>> Daniel Sobral wrote:
>> >
>> > Well, if that's possible, yes, that's what you should do.
>> >
>> > On Tue, Jul 7, 2009 at 12:59 AM, Joob <travaildereligion@hotmail.com>
>> > wrote:
>> >
>> >>
>> >> oh
>> >> so I should simply return the List and store it ?
>> >> that does make more sense, come to think of it...
>> >>
>> >>
>> >>
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>
> --
> Daniel C. Sobral
>
> Something I learned in academia: there are three kinds of academic
> reviews:
> review by name, review by reference and review by value.
>
>

--
View this message in context: http://www.nabble.com/Reassignment-to-Val-tp24363871p24412446.html
Sent from the Scala - User mailing list archive at Nabble.com.


Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

This is how I declared my Botin object

object Botin {
var botin = List
}

the version is Scala 2.7.3 (Default)

and also, I thought of this recently, how do I declare the botin list as a
list that contains "Adresses",
"Adresses" being a class that I made just for storing a couple of variables
together, because when I tried something like

var tempAdr = new Adresse(tempNom, tempNum, tempRue, tempVille);
var tempAdreListe = List(tempAdr)
Botin.botin = tempAdreListe

I got an error saying type mismatch :

found : List[tp2scala.Main.Adresse]
required : object List

I tried the following syntax :

object Botin {
var botin = List[tp2scala.Main.Adresse]
}

but I get an error saying:

missing arguments for method apply in object List;
follow this method with `_' if you want to treat it as a partially applied
function

Kevin Wright-4 wrote:
>
> We'll need to see some more code (especially the Botin object definition
> you
> used). Also what version of scala are you using?
>
> On Thu, Jul 9, 2009 at 4:45 PM, Joob
> wrote:
>
>>
>> I have tried this method, but now I get an error when I try to use a List
>> method on Botin.botin
>> this is the code :
>>
>> var tempB = Botin.botin.filter(n => n.individu != tempNom);
>>
>> The error I get is : value filter is not a member of object List.
>> If i understand correctly this means that "filter" is not recognized as
>> neither a parameter of botin nor a function that can be applied to a
>> List,
>> which is odd to me since "filter" is a function that can be applied to a
>> List no ?
>>
>> p.s.: I'm using netbeans at the moment and when I type "Botin.botin." it
>> then shows the possible function calls I can make, I recognize a few from
>> the Scala Library for List such as "apply" but "filter" and a few others
>> are
>> missing.
>>
>>
>>
>> Daniel Sobral wrote:
>> >
>> > You do not need to keep a var with the list. You can just pass the
>> > resulting
>> > list back and forth, but, at this point, I don't think that can be
>> taught
>> > in
>> > this list. You need to see a lot of functional code to get the idea.
>> > So, instead, I'll suggest something for which many here will condemn me
>> > (seriously!). Put this object somewhere:
>> >
>> > object Botin {
>> > var botin: ... = Nil
>> > }
>> >
>> > And then assign the results to Botin.botin. It will fix your immediate
>> > problem, but programming this way will bring you many other problems.
>> >
>> > On Tue, Jul 7, 2009 at 1:08 AM, Joob
>> > wrote:
>> >
>> >>
>> >> But what if I have my main calling a function calling another function
>> >> which
>> >> modifies the list,
>> >> or any other scenario where the object wouldn't be directly accessible
>> ?
>> >>
>> >> My application goes through the main only once, then loops in another
>> >> function that accepts user input to apply various operations to the
>> list,
>> >> by
>> >> calling other operation-specific function such as "add entry" "delete
>> >> entry"
>> >> etc
>> >>
>> >>
>> >>
>> >> Daniel Sobral wrote:
>> >> >
>> >> > Well, if that's possible, yes, that's what you should do.
>> >> >
>> >> > On Tue, Jul 7, 2009 at 12:59 AM, Joob
>>
>> >> > wrote:
>> >> >
>> >> >>
>> >> >> oh
>> >> >> so I should simply return the List and store it ?
>> >> >> that does make more sense, come to think of it...
>> >> >>
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
>> >> Sent from the Scala - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>> > --
>> > Daniel C. Sobral
>> >
>> > Something I learned in academia: there are three kinds of academic
>> > reviews:
>> > review by name, review by reference and review by value.
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24412446.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Re assignment to Val
Are you sure you have a Scala List, not a Java one?

On Thu, Jul 9, 2009 at 12:45 PM, Joob <travaildereligion@hotmail.com> wrote:

I have tried this method, but now I get an error when I try to use a List
method on Botin.botin
this is the code :

var tempB = Botin.botin.filter(n => n.individu != tempNom);

The error I get is : value filter is not a member of object List.
If i understand correctly this means that "filter" is not recognized as
neither a parameter of botin nor a function that can be applied to a List,
which is odd to me since "filter" is a function that can be applied to a
List no ?

p.s.: I'm using netbeans at the moment and when I type "Botin.botin." it
then shows the possible function calls I can make, I recognize a few from
the Scala Library for List such as "apply" but "filter" and a few others are
missing.



Daniel Sobral wrote:
>
> You do not need to keep a var with the list. You can just pass the
> resulting
> list back and forth, but, at this point, I don't think that can be taught
> in
> this list. You need to see a lot of functional code to get the idea.
> So, instead, I'll suggest something for which many here will condemn me
> (seriously!). Put this object somewhere:
>
> object Botin {
>   var botin: ... = Nil
> }
>
> And then assign the results to Botin.botin. It will fix your immediate
> problem, but programming this way will bring you many other problems.
>
> On Tue, Jul 7, 2009 at 1:08 AM, Joob <travaildereligion@hotmail.com>
> wrote:
>
>>
>> But what if I have my main calling a function calling another function
>> which
>> modifies the list,
>> or any other scenario where the object wouldn't be directly accessible ?
>>
>> My application goes through the main only once, then loops in another
>> function that accepts user input to apply various operations to the list,
>> by
>> calling other operation-specific function such as "add entry" "delete
>> entry"
>> etc
>>
>>
>>
>> Daniel Sobral wrote:
>> >
>> > Well, if that's possible, yes, that's what you should do.
>> >
>> > On Tue, Jul 7, 2009 at 12:59 AM, Joob <travaildereligion@hotmail.com>
>> > wrote:
>> >
>> >>
>> >> oh
>> >> so I should simply return the List and store it ?
>> >> that does make more sense, come to think of it...
>> >>
>> >>
>> >>
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>
> --
> Daniel C. Sobral
>
> Something I learned in academia: there are three kinds of academic
> reviews:
> review by name, review by reference and review by value.
>
>

--
View this message in context: http://www.nabble.com/Reassignment-to-Val-tp24363871p24412446.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

hmm
How do I check that :o ?

p.s.: I am prepared for various insults and bashing :)

Daniel Sobral wrote:
>
> Are you sure you have a Scala List, not a Java one?
>
> On Thu, Jul 9, 2009 at 12:45 PM, Joob
> wrote:
>
>>
>> I have tried this method, but now I get an error when I try to use a List
>> method on Botin.botin
>> this is the code :
>>
>> var tempB = Botin.botin.filter(n => n.individu != tempNom);
>>
>> The error I get is : value filter is not a member of object List.
>> If i understand correctly this means that "filter" is not recognized as
>> neither a parameter of botin nor a function that can be applied to a
>> List,
>> which is odd to me since "filter" is a function that can be applied to a
>> List no ?
>>
>> p.s.: I'm using netbeans at the moment and when I type "Botin.botin." it
>> then shows the possible function calls I can make, I recognize a few from
>> the Scala Library for List such as "apply" but "filter" and a few others
>> are
>> missing.
>>
>>
>>
>> Daniel Sobral wrote:
>> >
>> > You do not need to keep a var with the list. You can just pass the
>> > resulting
>> > list back and forth, but, at this point, I don't think that can be
>> taught
>> > in
>> > this list. You need to see a lot of functional code to get the idea.
>> > So, instead, I'll suggest something for which many here will condemn me
>> > (seriously!). Put this object somewhere:
>> >
>> > object Botin {
>> > var botin: ... = Nil
>> > }
>> >
>> > And then assign the results to Botin.botin. It will fix your immediate
>> > problem, but programming this way will bring you many other problems.
>> >
>> > On Tue, Jul 7, 2009 at 1:08 AM, Joob
>> > wrote:
>> >
>> >>
>> >> But what if I have my main calling a function calling another function
>> >> which
>> >> modifies the list,
>> >> or any other scenario where the object wouldn't be directly accessible
>> ?
>> >>
>> >> My application goes through the main only once, then loops in another
>> >> function that accepts user input to apply various operations to the
>> list,
>> >> by
>> >> calling other operation-specific function such as "add entry" "delete
>> >> entry"
>> >> etc
>> >>
>> >>
>> >>
>> >> Daniel Sobral wrote:
>> >> >
>> >> > Well, if that's possible, yes, that's what you should do.
>> >> >
>> >> > On Tue, Jul 7, 2009 at 12:59 AM, Joob
>>
>> >> > wrote:
>> >> >
>> >> >>
>> >> >> oh
>> >> >> so I should simply return the List and store it ?
>> >> >> that does make more sense, come to think of it...
>> >> >>
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
>> >> Sent from the Scala - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>> > --
>> > Daniel C. Sobral
>> >
>> > Something I learned in academia: there are three kinds of academic
>> > reviews:
>> > review by name, review by reference and review by value.
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24412446.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

The key clue is that "filter is not a member of _object_ List." It's a member of _class_ List. The question is why the compiler is looking in the object and not the class, for which it would help to see your decaration of Botin.botin.

-------------------------------------
Kevin Wright wrote:

We'll need to see some more code (especially the Botin object definition you
used). Also what version of scala are you using?

On Thu, Jul 9, 2009 at 4:45 PM, Joob wrote:

>
> I have tried this method, but now I get an error when I try to use a List
> method on Botin.botin
> this is the code :
>
> var tempB = Botin.botin.filter(n => n.individu != tempNom);
>
> The error I get is : value filter is not a member of object List.
> If i understand correctly this means that "filter" is not recognized as
> neither a parameter of botin nor a function that can be applied to a List,
> which is odd to me since "filter" is a function that can be applied to a
> List no ?
>
> p.s.: I'm using netbeans at the moment and when I type "Botin.botin." it
> then shows the possible function calls I can make, I recognize a few from
> the Scala Library for List such as "apply" but "filter" and a few others
> are
> missing.
>
>
>
> Daniel Sobral wrote:
> >
> > You do not need to keep a var with the list. You can just pass the
> > resulting
> > list back and forth, but, at this point, I don't think that can be taught
> > in
> > this list. You need to see a lot of functional code to get the idea.
> > So, instead, I'll suggest something for which many here will condemn me
> > (seriously!). Put this object somewhere:
> >
> > object Botin {
> > var botin: ... = Nil
> > }
> >
> > And then assign the results to Botin.botin. It will fix your immediate
> > problem, but programming this way will bring you many other problems.
> >
> > On Tue, Jul 7, 2009 at 1:08 AM, Joob
> > wrote:
> >
> >>
> >> But what if I have my main calling a function calling another function
> >> which
> >> modifies the list,
> >> or any other scenario where the object wouldn't be directly accessible ?
> >>
> >> My application goes through the main only once, then loops in another
> >> function that accepts user input to apply various operations to the
> list,
> >> by
> >> calling other operation-specific function such as "add entry" "delete
> >> entry"
> >> etc
> >>
> >>
> >>
> >> Daniel Sobral wrote:
> >> >
> >> > Well, if that's possible, yes, that's what you should do.
> >> >
> >> > On Tue, Jul 7, 2009 at 12:59 AM, Joob
> >> > wrote:
> >> >
> >> >>
> >> >> oh
> >> >> so I should simply return the List and store it ?
> >> >> that does make more sense, come to think of it...
> >> >>
> >> >>
> >> >>
> >> >
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
> >> Sent from the Scala - User mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > Daniel C. Sobral
> >
> > Something I learned in academia: there are three kinds of academic
> > reviews:
> > review by name, review by reference and review by value.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Reassignment-to-Val-tp24363871p24412446.html
> Sent from the Scala - User mailing list archive at Nabble.com.
>
>

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Re assignment to Val
If you use "=", you are assigning a value to the var. If you used ":", then you would be declaring a type (though you'd have to assign a value too). Try this instead:   var botin = List.empty[tp2scala.Main.Adresse]   Or whatever other type you think it's appropriate for botin.

On Thu, Jul 9, 2009 at 1:35 PM, Joob <travaildereligion@hotmail.com> wrote:

This is how I declared my Botin object

object Botin {
       var botin = List
   }

the version is Scala 2.7.3 (Default)


and also, I thought of this recently, how do I declare the botin list as a
list that contains "Adresses",
"Adresses" being a class that I made just for storing a couple of variables
together, because when I tried something like

       var tempAdr = new Adresse(tempNom, tempNum, tempRue, tempVille);
       var tempAdreListe = List(tempAdr)
       Botin.botin = tempAdreListe

I got an error saying type mismatch :

found : List[tp2scala.Main.Adresse]
required : object List

I tried the following syntax :

object Botin {
       var botin = List[tp2scala.Main.Adresse]
   }

but I get an error saying:

missing arguments for method apply in object List;
follow this method with `_' if you want to treat it as a partially applied
function




Kevin Wright-4 wrote:
>
> We'll need to see some more code (especially the Botin object definition
> you
> used). Also what version of scala are you using?
>
> On Thu, Jul 9, 2009 at 4:45 PM, Joob <travaildereligion@hotmail.com>
> wrote:
>
>>
>> I have tried this method, but now I get an error when I try to use a List
>> method on Botin.botin
>> this is the code :
>>
>> var tempB = Botin.botin.filter(n => n.individu != tempNom);
>>
>> The error I get is : value filter is not a member of object List.
>> If i understand correctly this means that "filter" is not recognized as
>> neither a parameter of botin nor a function that can be applied to a
>> List,
>> which is odd to me since "filter" is a function that can be applied to a
>> List no ?
>>
>> p.s.: I'm using netbeans at the moment and when I type "Botin.botin." it
>> then shows the possible function calls I can make, I recognize a few from
>> the Scala Library for List such as "apply" but "filter" and a few others
>> are
>> missing.
>>
>>
>>
>> Daniel Sobral wrote:
>> >
>> > You do not need to keep a var with the list. You can just pass the
>> > resulting
>> > list back and forth, but, at this point, I don't think that can be
>> taught
>> > in
>> > this list. You need to see a lot of functional code to get the idea.
>> > So, instead, I'll suggest something for which many here will condemn me
>> > (seriously!). Put this object somewhere:
>> >
>> > object Botin {
>> >   var botin: ... = Nil
>> > }
>> >
>> > And then assign the results to Botin.botin. It will fix your immediate
>> > problem, but programming this way will bring you many other problems.
>> >
>> > On Tue, Jul 7, 2009 at 1:08 AM, Joob <travaildereligion@hotmail.com>
>> > wrote:
>> >
>> >>
>> >> But what if I have my main calling a function calling another function
>> >> which
>> >> modifies the list,
>> >> or any other scenario where the object wouldn't be directly accessible
>> ?
>> >>
>> >> My application goes through the main only once, then loops in another
>> >> function that accepts user input to apply various operations to the
>> list,
>> >> by
>> >> calling other operation-specific function such as "add entry" "delete
>> >> entry"
>> >> etc
>> >>
>> >>
>> >>
>> >> Daniel Sobral wrote:
>> >> >
>> >> > Well, if that's possible, yes, that's what you should do.
>> >> >
>> >> > On Tue, Jul 7, 2009 at 12:59 AM, Joob
>> <travaildereligion@hotmail.com>
>> >> > wrote:
>> >> >
>> >> >>
>> >> >> oh
>> >> >> so I should simply return the List and store it ?
>> >> >> that does make more sense, come to think of it...
>> >> >>
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
>> >> Sent from the Scala - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>> > --
>> > Daniel C. Sobral
>> >
>> > Something I learned in academia: there are three kinds of academic
>> > reviews:
>> > review by name, review by reference and review by value.
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24412446.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>

--
View this message in context: http://www.nabble.com/Reassignment-to-Val-tp24363871p24413490.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Re assignment to Val
I meant to do that instead of "var botin = List". If you did change that, then please post the error message and relevant line.

On Thu, Jul 9, 2009 at 1:49 PM, Joob <travaildereligion@hotmail.com> wrote:

I get a similar error saying that the value "empty" is not a member of object
List



Daniel Sobral wrote:
>
> If you use "=", you are assigning a value to the var. If you used ":",
> then
> you would be declaring a type (though you'd have to assign a value too).
> Try
> this instead:
>
> var botin = List.empty[tp2scala.Main.Adresse]
>
> Or whatever other type you think it's appropriate for botin.
>
> On Thu, Jul 9, 2009 at 1:35 PM, Joob <travaildereligion@hotmail.com>
> wrote:
>
>>
>> This is how I declared my Botin object
>>
>> object Botin {
>>        var botin = List
>>    }
>>
>> the version is Scala 2.7.3 (Default)
>>
>>
>> and also, I thought of this recently, how do I declare the botin list as
>> a
>> list that contains "Adresses",
>> "Adresses" being a class that I made just for storing a couple of
>> variables
>> together, because when I tried something like
>>
>>        var tempAdr = new Adresse(tempNom, tempNum, tempRue, tempVille);
>>        var tempAdreListe = List(tempAdr)
>>        Botin.botin = tempAdreListe
>>
>> I got an error saying type mismatch :
>>
>> found : List[tp2scala.Main.Adresse]
>> required : object List
>>
>> I tried the following syntax :
>>
>> object Botin {
>>        var botin = List[tp2scala.Main.Adresse]
>>    }
>>
>> but I get an error saying:
>>
>> missing arguments for method apply in object List;
>> follow this method with `_' if you want to treat it as a partially
>> applied
>> function
>>
>>
>>
>>
>> Kevin Wright-4 wrote:
>> >
>> > We'll need to see some more code (especially the Botin object
>> definition
>> > you
>> > used). Also what version of scala are you using?
>> >
>> > On Thu, Jul 9, 2009 at 4:45 PM, Joob <travaildereligion@hotmail.com>
>> > wrote:
>> >
>> >>
>> >> I have tried this method, but now I get an error when I try to use a
>> List
>> >> method on Botin.botin
>> >> this is the code :
>> >>
>> >> var tempB = Botin.botin.filter(n => n.individu != tempNom);
>> >>
>> >> The error I get is : value filter is not a member of object List.
>> >> If i understand correctly this means that "filter" is not recognized
>> as
>> >> neither a parameter of botin nor a function that can be applied to a
>> >> List,
>> >> which is odd to me since "filter" is a function that can be applied to
>> a
>> >> List no ?
>> >>
>> >> p.s.: I'm using netbeans at the moment and when I type "Botin.botin."
>> it
>> >> then shows the possible function calls I can make, I recognize a few
>> from
>> >> the Scala Library for List such as "apply" but "filter" and a few
>> others
>> >> are
>> >> missing.
>> >>
>> >>
>> >>
>> >> Daniel Sobral wrote:
>> >> >
>> >> > You do not need to keep a var with the list. You can just pass the
>> >> > resulting
>> >> > list back and forth, but, at this point, I don't think that can be
>> >> taught
>> >> > in
>> >> > this list. You need to see a lot of functional code to get the idea.
>> >> > So, instead, I'll suggest something for which many here will condemn
>> me
>> >> > (seriously!). Put this object somewhere:
>> >> >
>> >> > object Botin {
>> >> >   var botin: ... = Nil
>> >> > }
>> >> >
>> >> > And then assign the results to Botin.botin. It will fix your
>> immediate
>> >> > problem, but programming this way will bring you many other
>> problems.
>> >> >
>> >> > On Tue, Jul 7, 2009 at 1:08 AM, Joob <travaildereligion@hotmail.com>
>> >> > wrote:
>> >> >
>> >> >>
>> >> >> But what if I have my main calling a function calling another
>> function
>> >> >> which
>> >> >> modifies the list,
>> >> >> or any other scenario where the object wouldn't be directly
>> accessible
>> >> ?
>> >> >>
>> >> >> My application goes through the main only once, then loops in
>> another
>> >> >> function that accepts user input to apply various operations to the
>> >> list,
>> >> >> by
>> >> >> calling other operation-specific function such as "add entry"
>> "delete
>> >> >> entry"
>> >> >> etc
>> >> >>
>> >> >>
>> >> >>
>> >> >> Daniel Sobral wrote:
>> >> >> >
>> >> >> > Well, if that's possible, yes, that's what you should do.
>> >> >> >
>> >> >> > On Tue, Jul 7, 2009 at 12:59 AM, Joob
>> >> <travaildereligion@hotmail.com>
>> >> >> > wrote:
>> >> >> >
>> >> >> >>
>> >> >> >> oh
>> >> >> >> so I should simply return the List and store it ?
>> >> >> >> that does make more sense, come to think of it...
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >>
>> >> >> --
>> >> >> View this message in context:
>> >> >> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
>> >> >> Sent from the Scala - User mailing list archive at Nabble.com.
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >> > --
>> >> > Daniel C. Sobral
>> >> >
>> >> > Something I learned in academia: there are three kinds of academic
>> >> > reviews:
>> >> > review by name, review by reference and review by value.
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/Reassignment-to-Val-tp24363871p24412446.html
>> >> Sent from the Scala - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24413490.html
>>   Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>
> --
> Daniel C. Sobral
>
> Something I learned in academia: there are three kinds of academic
> reviews:
> review by name, review by reference and review by value.
>
>

--
View this message in context: http://www.nabble.com/Reassignment-to-Val-tp24363871p24413774.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

I get a similar error saying that the value "empty" is not a member of object
List

Daniel Sobral wrote:
>
> If you use "=", you are assigning a value to the var. If you used ":",
> then
> you would be declaring a type (though you'd have to assign a value too).
> Try
> this instead:
>
> var botin = List.empty[tp2scala.Main.Adresse]
>
> Or whatever other type you think it's appropriate for botin.
>
> On Thu, Jul 9, 2009 at 1:35 PM, Joob
> wrote:
>
>>
>> This is how I declared my Botin object
>>
>> object Botin {
>> var botin = List
>> }
>>
>> the version is Scala 2.7.3 (Default)
>>
>>
>> and also, I thought of this recently, how do I declare the botin list as
>> a
>> list that contains "Adresses",
>> "Adresses" being a class that I made just for storing a couple of
>> variables
>> together, because when I tried something like
>>
>> var tempAdr = new Adresse(tempNom, tempNum, tempRue, tempVille);
>> var tempAdreListe = List(tempAdr)
>> Botin.botin = tempAdreListe
>>
>> I got an error saying type mismatch :
>>
>> found : List[tp2scala.Main.Adresse]
>> required : object List
>>
>> I tried the following syntax :
>>
>> object Botin {
>> var botin = List[tp2scala.Main.Adresse]
>> }
>>
>> but I get an error saying:
>>
>> missing arguments for method apply in object List;
>> follow this method with `_' if you want to treat it as a partially
>> applied
>> function
>>
>>
>>
>>
>> Kevin Wright-4 wrote:
>> >
>> > We'll need to see some more code (especially the Botin object
>> definition
>> > you
>> > used). Also what version of scala are you using?
>> >
>> > On Thu, Jul 9, 2009 at 4:45 PM, Joob
>> > wrote:
>> >
>> >>
>> >> I have tried this method, but now I get an error when I try to use a
>> List
>> >> method on Botin.botin
>> >> this is the code :
>> >>
>> >> var tempB = Botin.botin.filter(n => n.individu != tempNom);
>> >>
>> >> The error I get is : value filter is not a member of object List.
>> >> If i understand correctly this means that "filter" is not recognized
>> as
>> >> neither a parameter of botin nor a function that can be applied to a
>> >> List,
>> >> which is odd to me since "filter" is a function that can be applied to
>> a
>> >> List no ?
>> >>
>> >> p.s.: I'm using netbeans at the moment and when I type "Botin.botin."
>> it
>> >> then shows the possible function calls I can make, I recognize a few
>> from
>> >> the Scala Library for List such as "apply" but "filter" and a few
>> others
>> >> are
>> >> missing.
>> >>
>> >>
>> >>
>> >> Daniel Sobral wrote:
>> >> >
>> >> > You do not need to keep a var with the list. You can just pass the
>> >> > resulting
>> >> > list back and forth, but, at this point, I don't think that can be
>> >> taught
>> >> > in
>> >> > this list. You need to see a lot of functional code to get the idea.
>> >> > So, instead, I'll suggest something for which many here will condemn
>> me
>> >> > (seriously!). Put this object somewhere:
>> >> >
>> >> > object Botin {
>> >> > var botin: ... = Nil
>> >> > }
>> >> >
>> >> > And then assign the results to Botin.botin. It will fix your
>> immediate
>> >> > problem, but programming this way will bring you many other
>> problems.
>> >> >
>> >> > On Tue, Jul 7, 2009 at 1:08 AM, Joob
>> >> > wrote:
>> >> >
>> >> >>
>> >> >> But what if I have my main calling a function calling another
>> function
>> >> >> which
>> >> >> modifies the list,
>> >> >> or any other scenario where the object wouldn't be directly
>> accessible
>> >> ?
>> >> >>
>> >> >> My application goes through the main only once, then loops in
>> another
>> >> >> function that accepts user input to apply various operations to the
>> >> list,
>> >> >> by
>> >> >> calling other operation-specific function such as "add entry"
>> "delete
>> >> >> entry"
>> >> >> etc
>> >> >>
>> >> >>
>> >> >>
>> >> >> Daniel Sobral wrote:
>> >> >> >
>> >> >> > Well, if that's possible, yes, that's what you should do.
>> >> >> >
>> >> >> > On Tue, Jul 7, 2009 at 12:59 AM, Joob
>> >>
>> >> >> > wrote:
>> >> >> >
>> >> >> >>
>> >> >> >> oh
>> >> >> >> so I should simply return the List and store it ?
>> >> >> >> that does make more sense, come to think of it...
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >>
>> >> >> --
>> >> >> View this message in context:
>> >> >> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
>> >> >> Sent from the Scala - User mailing list archive at Nabble.com.
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >> > --
>> >> > Daniel C. Sobral
>> >> >
>> >> > Something I learned in academia: there are three kinds of academic
>> >> > reviews:
>> >> > review by name, review by reference and review by value.
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/Reassignment-to-Val-tp24363871p24412446.html
>> >> Sent from the Scala - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24413490.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>

Joob
Joined: 2009-07-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Re assignment to Val

object Botin {
var botin = List.empty[tp2scala.Main.Adresse]

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Re assignment to Val
Mmmm. You have "List" defined somewhere as something other than the class. Ok, replace that with:
var botin = _root_.scala.List.empty[tp2scala.Main.Adresse]
On Thu, Jul 9, 2009 at 1:56 PM, Joob <travaildereligion@hotmail.com> wrote:

   object Botin {
       var botin = List.empty[tp2scala.Main.Adresse]
<--- Error Line
   }

error msg :

value empty is not a member of object List



Daniel Sobral wrote:
>
> I meant to do that instead of "var botin = List". If you did change that,
> then please post the error message and relevant line.
>
> On Thu, Jul 9, 2009 at 1:49 PM, Joob <travaildereligion@hotmail.com>
> wrote:
>
>>
>> I get a similar error saying that the value "empty" is not a member of
>> object
>> List
>>
>>
>>
>> Daniel Sobral wrote:
>> >
>> > If you use "=", you are assigning a value to the var. If you used ":",
>> > then
>> > you would be declaring a type (though you'd have to assign a value
>> too).
>> > Try
>> > this instead:
>> >
>> > var botin = List.empty[tp2scala.Main.Adresse]
>> >
>> > Or whatever other type you think it's appropriate for botin.
>> >
>> > On Thu, Jul 9, 2009 at 1:35 PM, Joob <travaildereligion@hotmail.com>
>> > wrote:
>> >
>> >>
>> >> This is how I declared my Botin object
>> >>
>> >> object Botin {
>> >>        var botin = List
>> >>    }
>> >>
>> >> the version is Scala 2.7.3 (Default)
>> >>
>> >>
>> >> and also, I thought of this recently, how do I declare the botin list
>> as
>> >> a
>> >> list that contains "Adresses",
>> >> "Adresses" being a class that I made just for storing a couple of
>> >> variables
>> >> together, because when I tried something like
>> >>
>> >>        var tempAdr = new Adresse(tempNom, tempNum, tempRue,
>> tempVille);
>> >>        var tempAdreListe = List(tempAdr)
>> >>        Botin.botin = tempAdreListe
>> >>
>> >> I got an error saying type mismatch :
>> >>
>> >> found : List[tp2scala.Main.Adresse]
>> >> required : object List
>> >>
>> >> I tried the following syntax :
>> >>
>> >> object Botin {
>> >>        var botin = List[tp2scala.Main.Adresse]
>> >>    }
>> >>
>> >> but I get an error saying:
>> >>
>> >> missing arguments for method apply in object List;
>> >> follow this method with `_' if you want to treat it as a partially
>> >> applied
>> >> function
>> >>
>> >>
>> >>
>> >>
>> >> Kevin Wright-4 wrote:
>> >> >
>> >> > We'll need to see some more code (especially the Botin object
>> >> definition
>> >> > you
>> >> > used). Also what version of scala are you using?
>> >> >
>> >> > On Thu, Jul 9, 2009 at 4:45 PM, Joob <travaildereligion@hotmail.com>
>> >> > wrote:
>> >> >
>> >> >>
>> >> >> I have tried this method, but now I get an error when I try to use
>> a
>> >> List
>> >> >> method on Botin.botin
>> >> >> this is the code :
>> >> >>
>> >> >> var tempB = Botin.botin.filter(n => n.individu != tempNom);
>> >> >>
>> >> >> The error I get is : value filter is not a member of object List.
>> >> >> If i understand correctly this means that "filter" is not
>> recognized
>> >> as
>> >> >> neither a parameter of botin nor a function that can be applied to
>> a
>> >> >> List,
>> >> >> which is odd to me since "filter" is a function that can be applied
>> to
>> >> a
>> >> >> List no ?
>> >> >>
>> >> >> p.s.: I'm using netbeans at the moment and when I type
>> "Botin.botin."
>> >> it
>> >> >> then shows the possible function calls I can make, I recognize a
>> few
>> >> from
>> >> >> the Scala Library for List such as "apply" but "filter" and a few
>> >> others
>> >> >> are
>> >> >> missing.
>> >> >>
>> >> >>
>> >> >>
>> >> >> Daniel Sobral wrote:
>> >> >> >
>> >> >> > You do not need to keep a var with the list. You can just pass
>> the
>> >> >> > resulting
>> >> >> > list back and forth, but, at this point, I don't think that can
>> be
>> >> >> taught
>> >> >> > in
>> >> >> > this list. You need to see a lot of functional code to get the
>> idea.
>> >> >> > So, instead, I'll suggest something for which many here will
>> condemn
>> >> me
>> >> >> > (seriously!). Put this object somewhere:
>> >> >> >
>> >> >> > object Botin {
>> >> >> >   var botin: ... = Nil
>> >> >> > }
>> >> >> >
>> >> >> > And then assign the results to Botin.botin. It will fix your
>> >> immediate
>> >> >> > problem, but programming this way will bring you many other
>> >> problems.
>> >> >> >
>> >> >> > On Tue, Jul 7, 2009 at 1:08 AM, Joob <
>> travaildereligion@hotmail.com>
>> >> >> > wrote:
>> >> >> >
>> >> >> >>
>> >> >> >> But what if I have my main calling a function calling another
>> >> function
>> >> >> >> which
>> >> >> >> modifies the list,
>> >> >> >> or any other scenario where the object wouldn't be directly
>> >> accessible
>> >> >> ?
>> >> >> >>
>> >> >> >> My application goes through the main only once, then loops in
>> >> another
>> >> >> >> function that accepts user input to apply various operations to
>> the
>> >> >> list,
>> >> >> >> by
>> >> >> >> calling other operation-specific function such as "add entry"
>> >> "delete
>> >> >> >> entry"
>> >> >> >> etc
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> Daniel Sobral wrote:
>> >> >> >> >
>> >> >> >> > Well, if that's possible, yes, that's what you should do.
>> >> >> >> >
>> >> >> >> > On Tue, Jul 7, 2009 at 12:59 AM, Joob
>> >> >> <travaildereligion@hotmail.com>
>> >> >> >> > wrote:
>> >> >> >> >
>> >> >> >> >>
>> >> >> >> >> oh
>> >> >> >> >> so I should simply return the List and store it ?
>> >> >> >> >> that does make more sense, come to think of it...
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >>
>> >> >> >> --
>> >> >> >> View this message in context:
>> >> >> >>
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24366861.html
>> >> >> >> Sent from the Scala - User mailing list archive at Nabble.com.
>> >> >> >>
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >> > --
>> >> >> > Daniel C. Sobral
>> >> >> >
>> >> >> > Something I learned in academia: there are three kinds of
>> academic
>> >> >> > reviews:
>> >> >> > review by name, review by reference and review by value.
>> >> >> >
>> >> >> >
>> >> >>
>> >> >> --
>> >> >> View this message in context:
>> >> >> http://www.nabble.com/Reassignment-to-Val-tp24363871p24412446.html
>> >> >> Sent from the Scala - User mailing list archive at Nabble.com.
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/Reassignment-to-Val-tp24363871p24413490.html
>> >>   Sent from the Scala - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>> > --
>> > Daniel C. Sobral
>> >
>> > Something I learned in academia: there are three kinds of academic
>> > reviews:
>> > review by name, review by reference and review by value.
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Reassignment-to-Val-tp24363871p24413774.html
>>   Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>
> --
> Daniel C. Sobral
>
> Something I learned in academia: there are three kinds of academic
> reviews:
> review by name, review by reference and review by value.
>
>

--
View this message in context: http://www.nabble.com/Reassignment-to-Val-tp24363871p24413969.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Re assignment to Val

On Thursday July 9 2009, Daniel Sobral wrote:
> If you use "=", you are assigning a value to the var. If you used
> ":", then you would be declaring a type (though you'd have to assign
> a value too). Try this instead:
>
> var botin = List.empty[tp2scala.Main.Adresse]

It's probably a good idea to check if you're referring to 2.8-specific
classes or methods. The "empty" method in object List is a 2.8 thing.

> Or whatever other type you think it's appropriate for botin.

Randall Schulz

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Re assignment to Val
I usually do, but it so happens that this time I didn't. I apologize, Joob. Use one of the following instead:   var botin = List[tp2scala.Main.Adresse]() or var botin = Nil[tp2scala.main.Adresse]

On Thu, Jul 9, 2009 at 3:03 PM, Randall R Schulz <rschulz@sonic.net> wrote:
On Thursday July 9 2009, Daniel Sobral wrote:
> If you use "=", you are assigning a value to the var. If you used
> ":", then you would be declaring a type (though you'd have to assign
> a value too). Try this instead:
>
> var botin = List.empty[tp2scala.Main.Adresse]

It's probably a good idea to check if you're referring to 2.8-specific
classes or methods. The "empty" method in object List is a 2.8 thing.


> Or whatever other type you think it's appropriate for botin.


Randall Schulz



--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.

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