Re: Newbie Question: Is it allowed for the function to change the value of parameters?
  Home FAQ Contact Sign in
comp.lang.functional only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.functional Profile…
 Up
Re: Newbie Question: Is it allowed for the function to change the value of parameters?         


Author: Bruno Desthuilliers
Date: Jul 21, 2007 23:28

beginner a écrit :
> Hi,
>
> I am really new to functional programming. I am just wondering if it
> is theoretically allowed to for the function to change the value of
> the parameters?

This would be a side effect. The point of FP is to avoid side effects.
> Haskell's list seems to be immutable so it is not a problem. What if I
> use python:
>
> def f(list):
> list.append("a")


in Python, avoid using the builtin type names for identifiers

> will change the list passed in. Is this generally acceptable practice
> in functional programming?

No. A true FP solution would be to return a new list:
Show full article (1.02Kb)
94 Comments
Re: Newbie Question: Is it allowed for the function to change the value of parameters?         


Author: Joachim Durchholz
Date: Jul 27, 2007 04:36

Bruno Desthuilliers schrieb:
> beginner a écrit :
>> Hi,
>>
>> I am really new to functional programming. I am just wondering if it
>> is theoretically allowed to for the function to change the value of
>> the parameters?
>
> This would be a side effect. The point of FP is to avoid side effects.

No, no, no. Then Lisp, SML, OCaml and Clean wouldn't be FPLs.
Show full article (1.19Kb)
no comments
Re: Newbie Question: Is it allowed for the function to change the value of parameters?         


Author: Ulf Wiger
Date: Jul 27, 2007 05:17

>>>>> "JD" == Joachim Durchholz durchholz.org> writes:
JD> These things don't go well with side effects - if you construct
JD> a function and pass it around, you lose a great deal of control
JD> when it will be evaluated, and that means you can't easily
JD> control the order in which the side effects will happen. So many
JD> FPLs indeed try to restrict or control side effects (Haskell,
JD> Clean), others rely on "common sense" and simply make
JD> side-effect-free programming easy (OCaml, SML, some
JD> styles/schools of Lisp programming).

There are places where higher order functions and side effects
go well together (these fall into the latter category, where the
programmer must exercise caution.

The Erlang-based distributed real-time dbms, Mnesia, uses
function objects to encapsulate database transactions, e.g.
Show full article (3.29Kb)
no comments
Re: Newbie Question: Is it allowed for the function to change the value of parameters?         


Author: Joachim Durchholz
Date: Jul 27, 2007 08:34

Ulf Wiger schrieb:
>>>>>> "JD" == Joachim Durchholz durchholz.org> writes:
>
>> These things don't go well with side effects - if you construct
>> a function and pass it around, you lose a great deal of control
>> when it will be evaluated, and that means you can't easily
>> control the order in which the side effects will happen. So many
>> FPLs indeed try to restrict or control side effects (Haskell,
>> Clean), others rely on "common sense" and simply make
>> side-effect-free programming easy (OCaml, SML, some
>> styles/schools of Lisp programming).
>
> There are places where higher order functions and side effects
> go well together (these fall into the latter category, where the
> programmer must exercise caution.

That's exactly where I get wary :-)

(Thanks for the rest of the post, it's still interesting.)

Regards,
Jo
no comments
Re: Newbie Question: Is it allowed for the function to change the value of parameters?         


Author: Jon Harrop
Date: Jul 27, 2007 09:44

Ulf Wiger wrote:
> As a general rule, this type of programming is evil and
> should be used as sparingly as possible.

Ironically, a Hindley-Milner type checker is one of the few programs where
mutable refs work very well in an otherwise functional setting. :-)

--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?usenet
no comments
Re: Newbie Question: Is it allowed for the function to change the value of parameters?         


Author: David Formosa (aka ? the Platypus)
Date: Jul 28, 2007 16:37

On Fri, 27 Jul 2007 13:36:15 +0200, Joachim Durchholz
durchholz.org> wrote:

[...]
> The point of FPLs is higher-order functions (functions that take
> functions as arguments), and constructing functions at run-time and
> passing them around as values ("functions as first-class citizens",
> "functions are values").

By that reasoning Perl is a FPL.

[...]
> Of course, some people define FP as "free from side effects". But I
> think this definition is less useful than the other one.

And all FP have to have some support for side effects else how are
they going to do I/O?
no comments
Re: Newbie Question: Is it allowed for the function to change the value of parameters?         


Author: Joachim Durchholz
Date: Jul 29, 2007 02:12

David Formosa (aka ? the Platypus) schrieb:
> On Fri, 27 Jul 2007 13:36:15 +0200, Joachim Durchholz
> durchholz.org> wrote:
>
> [...]
>
>> The point of FPLs is higher-order functions (functions that take
>> functions as arguments), and constructing functions at run-time and
>> passing them around as values ("functions as first-class citizens",
>> "functions are values").
>
> By that reasoning Perl is a FPL.

You can have an FPL with yucky syntax.
>> Of course, some people define FP as "free from side effects". But I
>> think this definition is less useful than the other one.
>
> And all FP have to have some support for side effects else how are
> they going to do I/O?
Show full article (1.44Kb)
no comments
Re: Newbie Question: Is it allowed for the function to change the value of parameters?         


Author: Bruno Desthuilliers
Date: Jul 25, 2007 13:02

Joachim Durchholz a écrit :
> Bruno Desthuilliers schrieb:
>
>> beginner a écrit :
>>
>>> Hi,
>>>
>>> I am really new to functional programming. I am just wondering if it
>>> is theoretically allowed to for the function to change the value of
>>> the parameters?
>>
>>
>> This would be a side effect. The point of FP is to avoid side effects.
>
>
> No, no, no. Then Lisp, SML, OCaml and Clean wouldn't be FPLs.

Are they ?-)

(FWIW, I've been almost flamed the last time I labelled Lisp as a
functional language on c.l.lisp)
Show full article (1.33Kb)
no comments
Re: Newbie Question: Is it allowed for the function to change the value of parameters?         


Author: Markus E.L.
Date: Jul 31, 2007 06:04

> Joachim Durchholz a écrit :
>> Bruno Desthuilliers schrieb:
>>
>>> beginner a écrit :
>>>
>>>> Hi,
>>>>
>>>> I am really new to functional programming. I am just wondering if it
>>>> is theoretically allowed to for the function to change the value of
>>>> the parameters?
>>>
>>>
>>> This would be a side effect. The point of FP is to avoid side effects.
>> No, no, no. Then Lisp, SML, OCaml and Clean wouldn't be FPLs.
>
> Are they ?-)
>
> (FWIW, I've been almost flamed the last time I labelled Lisp as a
> functional language on c.l.lisp)
Show full article (1.19Kb)
no comments
Re: Newbie Question: Is it allowed for the function to change the value of parameters?         


Author: Rainer Joswig
Date: Jul 31, 2007 18:32

In article ,
development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de (Markus
E.L.) wrote:
>> Joachim Durchholz a
6 Comments

RELATED THREADS
SubjectArticles qty Group
Hypergeometric functions and beta functionssci.math ·
1 2 3 4 5 6 7 8 9