Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm aware that this may be closed as offtopic but there are people around with "offtopic" knowledge :)

So, in List context we can: #[[n ;; ]] and #[[ ;; n]], but we can't do this in context of Sequence. Only ##n is available.

One may do

f[n_] := Unevaluated[##][[;; n]] &
f[2][1, 2, 3, 4]
Sequence[1, 2]

but it is not what I'm looking for.

It is very often when I would like to use it. Of course thare are no problems with workarounds. I'm just curious.

p.s. Syntax is an issue for sure, I thought something like ###2 could stand for this but ### is automatically interpreted as ##1 #1.

share|improve this question
    
Just a note, f[1][1] won't work. Even more minor: f[1][1, 2, 3] gives Sequence[1], whereas ##3 &[1, 2, 3] gives 3. Oh well it would be nice to see an answer/"response" :). –  Jacob Akkerboom Mar 21 at 12:24
    
@JacobAkkerboom good points. :) –  Kuba Mar 21 at 12:29

1 Answer 1

How about something like:

seqChopper[seq_Sequence, span_Span] := Sequence @@ ((List@seq)[[span]])

SetAttributes[seqChopper, SequenceHold]

seqChopper[Sequence[1, 2, 3, 4, 5], 2 ;;]
seqChopper[Sequence[1, 2, 3, 4, 5], 2 ;; -2]
seqChopper[Sequence[1, 2, 3, 4, 5], -2 ;; 1 ;; -2]

(*
Sequence[2, 3, 4, 5]
Sequence[2, 3, 4]
Sequence[4, 2]
*)
share|improve this answer
1  
f[n_] := Unevaluated[##][[n]] & will do too. What I'm interested in is rather "why" there is nothing built-in than w workaround. +1 for SequenceHold I've not seent it for a while., –  Kuba Mar 21 at 10:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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