New answers tagged

0

The following does what you say you want myVector to do, but I'm not sure that's what you really want, since you're playing with the "Notation`" package. But maybe it is. Function: myVectors[comp_List, names_List] := MapThread[Function[{vec, name}, Set[OverVector[name], vec]], {comp, names}]; Example: myVectors[{{a, b}, {c, d}}, {v1, v2}] (* {{a, b}...


0

Maybe this could help: (* If your data are saved in an array... *) f={1.2,2.2,3.1,4.3}; (* generate the letters and assign the values: *) ToExpression[Table["a"<>ToString[i]<>"="<>ToString[f[[i]]],{i,1,Dimensions[f][[1]]}]]; {a1,a2,a3,a4} Out[3]= {1.2, 2.2, 3.1, 4.3} OR... (* Generate Random data... *) F = Table[RandomReal[{-3, 3}],...


1

You could use a combination of Evaluate and FromLetterNumber Evaluate[ToExpression[FromLetterNumber[Range[26]]]] = Array[func, 26] Or, Thread is another option. Thread[f1[ToExpression[FromLetterNumber[Range[26]]], Array[f2, 26]]] /. f1 -> Set


8

First of all, please note that coding this way in Mathematica is asking for trouble. Use of (lots of) mutable variables is strongly discouraged. The following will show you why: Clearing all symbols a to z in case they have been assigned some values is not trivial to do automatically in one go as it necessitates the manipulation of the order of standard ...


2

Since Set have HoldFirst Attribute, f @@ {k, l, m, n} will not be evaluated. You can do Evaluate[f @@ {k, l, m, n}] = 1


2

Expressions that simply evaluate with messages are not returned wrapped in Hold, and there is no problem assigning these to a Symbol: expr = Map[1, 2, 3, 4]; ?expr Map::nonopt: Options expected (instead of 4) beyond position 3 in Map[1,2,3,4]. An option must be a rule or a list of rules. >> Global`expr expr = Map[1, 2, 3, 4] Your use of Return ...


4

From the scoping point of view the variables on the RHS of an immediate (Set) assignment aren't scoped at the evaluation time because they can evaluate to their global values. So it is completely correct that they aren't highlighted as local variables. It doesn't matter that after evaluation these variables may be scoped if global values for them were not ...


1

The quite ambiguous answer to your question is: "Yes, you (and we) can!". Sometimes we might simply let Mathematica complain or turn complaints off using Quiet... So note this: rndmi = RandomInteger[100,10]; (* immediately assigns a list of 10 numbers to rndmi *) v[i_Integer] = Quiet @ rndmi[[ i ]] {99, 93, 50, 56, 83, 40, 53, 62, 18, 90}[[i]] That ...


4

It is a bug that the local variable c isn't shared with Condition when the latter appears at the LHS outside of the KeyValuePattern. The following simplified examples demonstrate the bug: gfail1[KeyValuePattern@{"c" -> c_}] /; c == 0 := 0 gfail2[KeyValuePattern@{"c" -> c_} /; c == 0] := 0 gfail1[<|"c" -> 0|>] gfail2[<|"c" -> 0|>] ...


2

Consider test[p : KeyValuePattern@{"c" -> c_List}] /; First[p["c"]] == 0 := $Succeeded test[p : KeyValuePattern@{"c" -> c_List}] := $Failed then test[<|"c" -> {0, 1}|>] $Succeeded test[<|"c" -> {1, 1}|>] $Failed Perhaps that is form you are looking for.



Top 50 recent answers are included