Q:

Can I set in Zsh an environment variable just for a subshell or a compound command?

I would like to run two commands, x and y, and define an environmentvariable V just for these too. Is there an easy way to do it in zsh? The "bash-like" solution, i.e.
(export V=myvalue; x; y)

is cumbersome and works only with a subshell, not a compound. However, the following two versions are syntactically invalid:
V=myvalue ( x ; y ) # No!
V=myvalue { x ; y } # No!No!No!

A:

It is not possible without at least some extra code.
The modification of the environment by prepending variable assignments works only with Simple Commands. Meaning that the first word after the variable assignments needs to be the name of a simple (as in "not complex") command. Complex commands include { list } and ( list ) contstructs. (See the documentation on Complex Commands for a complete list)
If you want to modify the environment for a specific list of commands without changing the environment of your current shell, I can think of two ways to achive that

As mentioned in the question there is the rather straight-forward solution by runnig a subshell and exporting the variable explicitly:
(export V=myvalue; x; y)

You can use eval to avoid creating a subshell:
V=myvalue eval "x; y"
V=myvalue eval x\; y

This also saves three to four characters compared to the first solution. The main drawback seems to be that completion does not work very well inside the argument list for eval.

