Re: How to make delayed functions from text info

*To*: mathgroup at smc.vnet.net*Subject*: [mg81149] Re: How to make delayed functions from text info*From*: Szabolcs Horvát <szhorvat at gmail.com>*Date*: Fri, 14 Sep 2007 03:32:20 -0400 (EDT)*References*: <fcb39b$fca$1@smc.vnet.net>

P_ter wrote: > Hello, > I have a list like this t1= {{"AA", {15.}, {19.}, 4.}, {"AC", {17.}, {21.}, 4.}} > It means: AA[b_,t_]:= If[15<t<=19,b,0] Etc. > The problem is that I have a few hundred of these elements in a list. But when I do: > (ToExpression[#[[1]]][b_,t_]:= Evaluate[If[#[[2,1]]< t<= #[[3,1]],b,0]])& /@ t1 > I get out {Null, Null}, although AA and AC exist with ?AA,?AC This is because SetDelayed[] (i.e. :=) evaluates to Null when the assignment was successful. > But I want to see these delayed functions in a list: > lst = {AA[b_,t_]:=If[15.<t<=19.,b,0],AC[b_,t_]:=If[17.<t<=21.,b,0] > ...} > I would like to say: lst[[1]] and get this delayed function. Is that possible? > Also I wonder if ?(AA,AC) could be done, such that I get all the definitions in a row. Any idea? The simplest solutions I can think of are the following (after the functions "AA", "AC", etc. have been defined): Information /@ t1[[All, 1]] DownValues /@ ToExpression /@ t1[[All, 1]] If you really need a list of expressions that *look like* function definitions (but do not actually define the functions), try t1 /. {name_, {min_}, {max_}, _} -> HoldForm[name[b_, t_] := If[min < t <= max, b, 0]] (The argument renaming is caused by SetDelayed being embedded in Rule.) -- Szabolcs