Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: 4.1: multi-parameter for loop

Peter Stephenson wrote:

> ...
> My main worry is that the wordcode stuff is as clear as mud to me.  In
> particular, I don't know what WC_FOR_SKIP is doing, why it divides the data
> size(?) by 4, and whether it needs changing when there's more stuff in
> the for structure.

>From zsh.h:

  #define WC_FOR_TYPE(C)      (wc_data(C) & 3)
  #define WC_FOR_PPARAM       0
  #define WC_FOR_LIST         1
  #define WC_FOR_COND         2
  #define WC_FOR_SKIP(C)      (wc_data(C) >> 2)
  #define WCB_FOR(T,O)        wc_bld(WC_FOR, ((T) | ((O) << 2)))

For for-loops the data field contains 1) the type of the loop
(positional params, a list of values or a condition) and 2) the offset
to the code after the loop.  The type is stored in the lowest two bits,
the offset is the rest, hence the `>> 2' to get the offset.

And since par_for() calculates the offset at the very end, it already
takes into account your parameter list.

I'd like to have something like this *a lot*.  I've missed it several
times already, I just didn't think of enhancing the for loop syntax.
I don't have any strong feelings pro or contra one of the suggested
syntaxes.  Similar like Bart's `foreach' suggestion, one could also use
`for (a b) in ...' to make this `save', trying to make it look like one
of these tuple assignments that are possible in some languages.  Of
course, people could then come and think that `(a b)=(1 2)' should work,


Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx

Messages sorted by: Reverse Date, Date, Thread, Author