Re: Strange behavior when using pattern match and HoldAll

• To: mathgroup at smc.vnet.net
• Subject: [mg104742] Re: [mg104709] Strange behavior when using pattern match and HoldAll
• From: Leonid Shifrin <lshifr at gmail.com>
• Date: Sun, 8 Nov 2009 06:48:35 -0500 (EST)
• References: <200911071150.GAA10146@smc.vnet.net>

```Leo,

Hold-attributes do affect the pattern-matching. Have a look at

http://www.mathprogramming-intro.org/book/node408.html

where I specifically discuss this topic using an example similar to yours.

Regards,
Leonid

On Sat, Nov 7, 2009 at 3:50 AM, dnquark <dnquark at gmail.com> wrote:

> I am using HoldAll with a function that I would like to modify a list
> passed to it, as described on
> http://forums.wolfram.com/student-support/topics/21247
> I wrote this:
>
> Clear[test]; Remove[test];
> SetAttributes[test, HoldAll]
> test[list_List, val_] := list[[2]] = val;
>
> This doesn't work:
> lst = {4, 5, 6};
> test[lst, 99];
> lst
>
> gives {4,5,6}
>
> However, test[list_, val_] := list[[2]] = val  works.
>
> Similarly,
> Clear[foo]; Remove[foo];
> SetAttributes[foo, HoldAll]
> foo[list_List] := list[[2]];
> lst={1,2,3}; foo[lst]
>
> doesn't work.
> Can someone explain why HoldAll changes the behavior of the function
> depending on whether the argument pattern is specified as x_ or
> x_List?..
>
> Thanks,
> --Leo
>
>

```

• Prev by Date: Re: Complex solutions to simple equations
• Next by Date: Re: Function returns null
• Previous by thread: Strange behavior when using pattern match and HoldAll
• Next by thread: Re: Strange behavior when using pattern match and HoldAll