This is a good idea and if i remember correctly it's a similar syntax as
was used in m5. Another advantage, if macro syntax could be changed
temporarily, a curried function could be serialized easily.
On Jun 2, 2016 07:10, "Li Wei" <[email protected]> wrote:
> Hello All,
> I have an idea for the new ${} syntax for m4 2.0. If we were to allow
> for arguments in ${1,2,3} like macro(a,b,c), then we could have argument
> list splicing. (Like array splices in other languages.) My hope is that we
> can use this opportunity to both make the things that were impossible or
> difficult in m4 easy and fast. The format would be:
> ${FROM, TO, ALT-TEXT}
> FROM, and TO are evaluated with `eval' syntax
> Only arguments in the inclusive range FROM..TO are expanded. `${3,5}' ->
> `$3,$4,$5'
> If either FROM, or TO are negative, then they would be relative to the
> last argument `${1,-1}' -> `$@'
> If TO < FROM then the expanded order is reversed (e.g. `${4,2}' ->
> `$4',`$3',`$2' )
> When TO is missing, it is set to FROM, so that `${3}' -> `${3, 3}' -> `$3'.
> As a special rule if ALT-TEXT is missing, and either FROM or TO is 0 then
> a macro call syntax is expanded.
> `${0}' -> `${0,0}' -> `$0'
> `${0,N}' -> `$0($N,...,$-1)'
> `${N,0}' -> `$0($1,...,$N)'
> As a bonus feature, if ALT-TEXT is given and $# is within the range
> START,STOP then ALT-TEXT is expanded.
> If ALT-TEXT is given then 0 looses its earlier special meaning.
> This feature is somewhat like bash's ${VAR:+alt text} syntax.
> `${2,2,`arg 2 was given'}'
> `${0,4,`4 or fewer args were given'}'
> The special values `#', `*', and `@' are also allowed with the following
> meanings (I may have gone off the deep end here):
>
> Examples:
> ${1} -> "The first argument"
> ${-1} -> "The last argument"
> ${0} -> "Macro name"
> ${#} -> "Number of arguments"
> ${*} -> "unquoted arguments separated by `,' "
> ${@} -> "quoted arguments separated by `,' "
>
> ${N,N} -> as above
> ${N,0} -> "call syntax `$0($1,...,$N)' "
> ${N,#} -> RESERVED
> ${N,*} -> " $1, ..., $N unquoted like $*"
> ${N,@} -> " `$1',...,`$N' quoted like $@"
>
> ${0, N} -> " `$0($N,...,$-1)' "
> ${0, 0} -> "same as `$0' "
> ${0,#, `f'} -> "Map: f(`$1'),...,f(`$N')"
> ${0,*} -> "same as `$0($*)' "
> ${0,@} -> "same as `$0($@)' "
>
> ${#, N} -> "return eval expression N"
> ${#,0} -> " return `0' "
> ${#, #} -> "same as $#"
> ${#, *} -> "concatenate $1$2...$N "
> ${#, @} -> "concatenate `$1'`$2'...`$N' "
>
> ${*, N} -> " $N,...,$-1 unquoted like $*"
> ${*,0, `:'} -> "join $1:,...,:$N "
> ${*, #, `PRE-', `-POST'} -> " `PRE-$1-POST,...,PRE-$N-POST' "
> ${*, *} -> "same as $*"
> ${*, @} -> " ``$1'',...``$N'' "
>
> ${@, N} -> " `$N',...,`$-1' quoted like $@"
> ${@,0, `-'} -> "join `$1'-,...,-`$N' "
> ${@, #, `PRE-', `-POST'} -> "`PRE-'`$1'`-POST',...,`PRE-'`$N'`-POST' "
> ${@, *} -> " ``$1',...,`$N'' "
> ${@, @} -> "same as $@"
>
> -=Li Wei=-
>