Skip to main content
19 votes

How do you set attributes on SubValues?

This is an old discussion but is about an issue that resurfaces every now and then. One of the best (for a given sense of elegance) answers is the one posted on Stack Overflow ...
Batracos's user avatar
  • 2,105
16 votes
Accepted

Is it safe to Unprotect everything? What are the implications?

The reason is to prevent users to mess with it. Unprotecting something is not necessarily dangerous, but unprotecting everything definitely is. Performance is probably not the issue. The real danger ...
Henrik Schumacher's user avatar
16 votes
Accepted

Why is listable not an attribute of the Set function?

Listable is not included because Set is not Listable, imagine what would happen: ...
Kuba's user avatar
  • 137k
15 votes

Is it safe to Unprotect everything? What are the implications?

There is a typesetting step after formatting, and MakeBoxes definitions do not require unprotecting Hold, you will just add more ...
Kuba's user avatar
  • 137k
14 votes
Accepted

Why can I define N[MySymbol] := ...?

Values of this type are actually stored in an analog to DownValues called NValues. Here's an example: ...
b3m2a1's user avatar
  • 46.9k
13 votes
Accepted

Does function call via @ ignore HoldFirst attribute?

andre has given a good answer. I will add a little further clarification. The function f[#]& is a different function than the function ...
m_goldberg's user avatar
  • 108k
12 votes

Does function call via @ ignore HoldFirst attribute?

This is intended, but is one of the main premature evaluation case when one works with unevaluated expression. Particularly f @ expression is not equivalent to <...
andre314's user avatar
  • 18.6k
11 votes
Accepted

Why isn't Orderless an Attribute of And?

As you mentioned, And is not Orderless just for efficiency; its arguments are evaluated one by one to prevent unnecessary ...
JungHwan Min's user avatar
  • 4,684
11 votes
Accepted

Confusion about HoldFirst attribute of Set

The problem is not related to Set in general but to how Set works with Part on a left hand ...
Kuba's user avatar
  • 137k
11 votes

How to make a function with two patterns listable?

A few comments: Values of the form f[][] are called SubValues. For example, if one defines ...
user293787's user avatar
  • 11.9k
10 votes

Does function call via @ ignore HoldFirst attribute?

There are two separate issues here, which you are confusing. Does function call via @ ignore HoldFirst attribute? No, it doesn't. f[x] and ...
Szabolcs's user avatar
  • 236k
10 votes

Confusion about HoldFirst attribute of Set

Kuba's answer explains why the first form does not work, but it does not address why the second form does work. That has been discussed in other questions DownValue assignment using Apply Why is the ...
Mr.Wizard's user avatar
  • 272k
9 votes
Accepted

Map vs listable

The main difference can been seen when dealing with list of lists. Consider the following list: lis = {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}}; Lets create a ...
RunnyKine's user avatar
  • 33.2k
9 votes
Accepted

How do I restore HoldAll, HoldFirst, HoldRest attributes of Inactivated functions

Introduction I'm not aware of any way to hold evaluation of arguments in expression of form Inactive[f][arguments], which is how inactivated expressions look like. ...
jkuczm's user avatar
  • 15.1k
9 votes

How to differentiate formally?

Starting in M11.1, this works: sum[n_] = Sum[i x[i],{i,1,n}]; D[sum[n],x[2]] //InputForm Piecewise[{{2, n >= 2}}, 0]
Carl Woll's user avatar
  • 131k
9 votes
Accepted

FullForm of b/c and c/b with different order

Times has the Attribute Orderless: Attributes[Times] ...
Mr.Wizard's user avatar
  • 272k
9 votes

partial numerical evaluation

You can set x to be numeric, and then search for numeric subexpressions to be replaced. For example: ...
Carl Woll's user avatar
  • 131k
8 votes
Accepted

About OneIdentity

What the documentation means is that for a symbol f with attribute OneIdentity, pattern forms like ...
Silvia's user avatar
  • 27.6k
8 votes
Accepted

Recursion depth exceeded in pattern matching with attribute Flat

I find Flat hard to work with. Despite seeing it in use numerous times I'm never quite sure what it will do until I try it, so maybe I'm not the person to answer ...
Mr.Wizard's user avatar
  • 272k
8 votes

Flat attribute : example I don't understand

To understand what has happened, let's just define: ClearAll[f]; SetAttributes[f, {Flat}]; f[x_] := Hold[x]; f[1] (*Returns Hold[f[1]]*) The reason for this ...
Anton.Sakovich's user avatar
8 votes

Is it possible to make listable Experimental`NumericalFunction?

I do not know a way to make Experimental`NumericalFunction listable itself, but depending of your goals you can achieve the same behavior in several ways. The ...
Alexey Popkov's user avatar
8 votes
Accepted

How to construct the HoldAll version of Information[]?

According to the documentation, the special form ??test calls Information["test"]. Therefore, one could modify OPs <...
user293787's user avatar
  • 11.9k
7 votes
Accepted

head of a sequence

Head[Sequence[b, c]] returns an error (Head::argx: Head called with 2 arguments; 1 argument is expected) on my system (MMA 12.0, Win10-64). This makes sense because ...
MarcoB's user avatar
  • 67.4k
7 votes
Accepted

How to define a function to be numeric when the input is purely symbolic

Instead of unprotecting NumericQ, one can define an upvalue for h: ...
user293787's user avatar
  • 11.9k
7 votes
Accepted

How to make a function with two patterns listable?

Here's an alternative to Listable. It's somewhat the opposite to Listable, but it's also the opposite to unlistable. More like ...
Michael E2's user avatar
  • 237k
6 votes

Pure function with attributes of arbitrary number of arguments: Is it possible?

This is the answer merged from this more recent question The form in question I meant the form Function[Null, body-using-slots, attrs] as ciao correctly noted....
Leonid Shifrin's user avatar
6 votes

Pattern does not match with Orderless head

The following is an expansion of the explanation given by Mr.Wizard. The pattern-matcher works on the base of the assumption that Orderless attribute is already ...
Alexey Popkov's user avatar
6 votes

Why does `Block` reset `Attributes`?

Block does something very simple: it just (temporarily) removes all definitions directly associated with a symbol, and nothing else. That includes: ...
Szabolcs's user avatar
  • 236k
6 votes

Why does `Block` reset `Attributes`?

It is illustrative to compare Block, Internal`InheritedBlock, Module, and ...
rcollyer's user avatar
  • 34k

Only top scored, non community-wiki answers of a minimum length are eligible