2

Is there a way to set attributes for a function which holds for all arguments when currying?

When evaluating, e.g.,

SetAttributes[ x, NHoldAll ]
N[ x[1], 10 ]
N[ x[1][1],10 ]

I get

x[1]
x[1][1.000000000]

and I'm looking for some way to get

x[1]
x[1][1]

instead.

The first argument of SetAttributes should be a symbol so evaluating SetAttributes[x[i_]] or SetAttributes[x[1]] doesn't work. None of the documentation on attributes and functions related to currying gives any indication of how to do this.

Gert
  • 1,530
  • 8
  • 22
  • The attribute HoldAll only covers x[..]. If you give an additional argument, this is evaluated by N. To achieve your aim, you must define a second function. – Daniel Huber Sep 07 '22 at 12:12
  • The thing is that in my case the x[1][j] represent variables in the first step of a method which solves subsets of equations, substitutes solutions, solves new subsets etc. The i'th step introduces new variables x[i][j] (j = 1, ... ). I can't just define x[ a, b ] as a second function since x[i] is passed as a symbol name of a variable... – Gert Sep 07 '22 at 12:16
  • But you can define a new function, e.g.: g[j_]=x[1][j] or even g[i_,j_]= x[i][j] and give g the Attribute: HoldAll. – Daniel Huber Sep 07 '22 at 13:06
  • 1
    @LeonidShifrin, it does. Thanks :) – Gert Sep 07 '22 at 15:32

0 Answers0