2
$\begingroup$

I'll try to make this question more clear in a little while. In the mean time, I'll ask directly the question which motivated it: Latin Square from submatrix

Original Question

I want, for instance, to obtain the code

{#[[1]],
 #2[[1]],
 #3[[1]],
 ...
 #999[[1]]}

and I'm not sure how to do it. If I run

Activate[Part[Inactive[Slot][#], 2] & /@ Range@999]

I get what I want, since Slot[n] has no second part. How do I get the input code for a part of an expression that may or may not exist without having it wrapped or inactive?


This problem arose when writing code to solve for missing matrix entries; each missing entry got assigned a numbered Slot. I may type this specific example up, but in the mean time here's a contrived example:

thelist=Table[#[[i]],{i,10}]&
(*Out[]={1,i[[2]],i[[3]],...,i[[10]]}*)

The desired output is

(*Out[]={i[[1]],i[[2]],i[[3]],...,i[[10]]}*)
$\endgroup$
2
  • $\begingroup$ Does Indexed have the effect you want? $\endgroup$
    – mikado
    Commented Feb 26, 2022 at 21:25
  • $\begingroup$ I'm looking to use Part in a later piece of code to extract elements, I just don't want to manually type it. $\endgroup$
    – Adam
    Commented Feb 26, 2022 at 21:28

1 Answer 1

3
$\begingroup$

I'm not sure what you are trying to do, but does the following help?

thelist = Table[Indexed[#, i], {i, 10}] &
(* Table[Indexed[#1, i], {i, 10}] & *)

thelist[Range[10, 20]]
(* {10, 11, 12, 13, 14, 15, 16, 17, 18, 19} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.