How to evaluate an expression and use the result in newcommand?

This checks whether #2 is an (unsigned) integer and in this case does the operation; otherwise it just appends +1.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\seq}{mmm}
 {
  \chelsea_seq:nnn { #1 } { #2 } { #3 }
 }

\cs_new_protected:Nn \chelsea_seq:nnn
 {
  #1\sb{#2}, % first item
  \regex_match:nnTF { \A [0-9]+ \Z } { #2 }
   {% #2 is a number
    #1\sb{ \int_eval:n { #2 + 1 } }
   }
   {% #2 is not a number
    #1\sb{ #2+1 }
   }
  ,\dots,#1\sb{#3}
 }

\ExplSyntaxOff

\begin{document}

$\seq{v}{0}{N}$

$\seq{v}{1}{N}$

$\seq{w}{n}{N}$

\end{document}

enter image description here


Your objective is straightforward to achieve if you can use LuaLaTeX.

enter image description here

% !TEX TS-program = lualatex
\documentclass{article}  
\newcommand{\seq}[3]{#1_{#2}, #1_{\directlua{tex.sprint(#2+1)}}, \dots ,#1_{#3}}
\begin{document}
$\seq{v}{0}{N}$
\end{document}

Tags:

Macros

Calc