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

Re: Case statement with ";|" [not implemented]



On Jan 18, 11:53am, Gerald Lai wrote:
}
} My question is, shouldn't there be a way to do this:
} ===
}   case $mycase in
}       0)
}           echo "mycase is 0"
}           ;;
} 
}       1)
}           echo "mycase is 1"
}           ;|
} 
}       2)
}           echo "mycase is 2"
}           ;|
} 
}       *)
}           echo "mycase is 1 or 2"
}   esac
} ===
} Note that ";|" provides an OR-like separator (as opposed to the AND-like
} ";&" separator)

This analogy doesn't work.  Semantically, the test for whether $mycase
matches any one of the labels occurs once at the top of the statement.
Control then jumps into the body as if with a GOTO, and thereafter all
you're able to change with ;& is how early you exit from the body.  It
isn't anything like AND / OR.

By comparison, your proposed ;| requires the interpreter to reproduce
the pattern match test at every label, which implies storing the result
of expanding $mycase, etc.  Most languages don't allow one to hide quite
that much complexity behind syntactic sugar.



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