Skip to content

SetAttributes ​

Turns on one of the Wolfram-named properties Attributes can report.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageSetAttributes!
SetAttributes(f, attr)Turns attrattr on for ff's operator definition, in place.
SetAttributes(f, {attr1, attr2, ...})Turns on several attributes at once.
Typed signatures
TypePackageApplies
(symbol, any) -> anycombinatoricsalways

Domain: Collections

Details
  • Only {Flat,HoldAll,Listable,Orderless}\{Flat, HoldAll, Listable, Orderless\} can actually be turned on — see Attributes for why those four and no others. Declines (stays unevaluated) for an undeclared ff, or any attribute name outside that set, rather than silently accepting a change that didn't happen.
  • A declared head is Protected: SetAttributes leaves the call unevaluated and says SetAttributes::write (Tag f in f is Protected.), where Wolfram, whose Protected guards definitions rather than attributes, makes the change. Only a symbol of your own, defined first, takes attributes.
  • Always returns NothingNothing, like Wolfram's own NullNull.

Examples

Basic #

define a head of your own, turn Orderless on, then read it back with Attributes

live ↗
InLast([userHead(x):−x,SetAttributes(userHead,Orderless),Attributes(userHead)])\mathrm{Last}(\bigl\lbrack\mathrm{userHead}(x)\coloneq x, \mathrm{SetAttributes}(\mathrm{userHead}, \mathrm{Orderless}), \mathrm{Attributes}(\mathrm{userHead})\bigr\rbrack)Out[Orderless]\bigl\lbrack\mathrm{Orderless}\bigr\rbrack

Wolfram needs no definition before a symbol takes attributes; here the head is defined first, since SetAttributes leaves an undeclared symbol alone.

a declared head is Protected: the call stays unevaluated and says SetAttributes::write

live ↗
InSetAttributes(HarmonicMean,Orderless)\mathrm{SetAttributes}(\mathrm{HarmonicMean}, \mathrm{Orderless})OutSetAttributes(HarmonicMean,Orderless)\mathrm{SetAttributes}(\mathrm{HarmonicMean}, \mathrm{Orderless})
Properties #
live ↗
InAttributes(SetAttributes)\mathrm{Attributes}(\mathrm{SetAttributes})Out[HoldAll,Protected]\bigl\lbrack\mathrm{HoldAll}, \mathrm{Protected}\bigr\rbrack
About
Examples3
Checked againstWolfram Language 2 differ
CrosswalkWolfram Language

See also: Attributes, ClearAttributes