Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Flat attribute and order of function definitions

1 view
Skip to first unread message

Diego Fabregat

unread,
Nov 21, 2009, 3:36:20 AM11/21/09
to
Hi all,

Playing with some function definitions and attributes of functions I
got to a behaviour that I don't understand (example below). Depending
on the order I define function f1 and its attributes, it works or it
crashes. I know that the order of the definitions matters, so this is
kind of expected, but I would like to understand why this happens. Can
you point me to some reference that explains it?

Here you have the example:


In[1]:= Clear[f1]

In[2]:= ClearAttributes[f1, Flat]

In[3]:= f1[expr_] := expr

In[4]:= SetAttributes[f1, Flat]

In[5]:= ?f1

Global`f1

Attributes[f1]={Flat}

f1[expr_]:=expr

In[6]:= f1[c]

Out[6]= c

In[7]:= Clear[f1]

In[8]:= ClearAttributes[f1, Flat]

In[9]:= ?f1

Global`f1

In[10]:= SetAttributes[f1, Flat]

In[11]:= f1[expr_] := expr

In[12]:= ?f1

Global`f1

Attributes[f1]={Flat}

f1[expr_]:=expr

In[13]:= f1[c]

During evaluation of In[13]:= $IterationLimit::itlim: Iteration limit
of 4096 exceeded. >>

Out[13]= Hold[f1[c]]

Leonid Shifrin

unread,
Nov 22, 2009, 6:10:49 AM11/22/09
to
Hi Diego,

This looks like a bug to me. I experimented a bit - in the second case the
behavior persists even after the Flat attribute has been removed, and the
remaining definition for f1 looks innocent - should just return the value as
in the first case.

Regards,
Leonid

Diego Fabregat

unread,
Nov 24, 2009, 5:46:23 AM11/24/09
to
Thanks Leonid.

Should I report this behaviour somehow? Will some developer see this
post and decide whether it is a bug or not?

By the way, just in case this is needed, I'm using Mathematica 6.0.0
on Mac Os X x86 (32-bit).


Regards,
Diego

On Nov 22, 12:10 pm, Leonid Shifrin <lsh...@gmail.com> wrote:
> Hi Diego,
>

> This looks like a bug to me. I experimented a bit - in the second case th=


e
> behavior persists even after the Flat attribute has been removed, and the

> remaining definition for f1 looks innocent - should just return the value=


as
> in the first case.
>
> Regards,
> Leonid
>

> On Sat, Nov 21, 2009 at 12:35 AM, Diego Fabregat <d.fabre...@gmail.com>wr=

0 new messages