rakitzis / rc

rc shell -- independent re-implementation for Unix of the Plan 9 shell (from circa 1992)
Other
258 stars 24 forks source link

Is rc omitting () as one of multiple patterns in ~ #24

Closed borkovic closed 8 years ago

borkovic commented 8 years ago

The man page gives an example for testing for undefined var: ~ $foo (). I tried testing for several values at once with one pattern being (). Rc seems to ignore the pattern ().

rc/ $ rc -x
; whatis x
whatis x
x not found
; if (~ $x 1 () 0) { echo yes} else { echo no}
~ () 1 0
echo no
no

The test against single () seems to be correct:

; if (~ $x ()) { echo yes } else { echo no }
~ () ()
echo yes
yes

I observed a similar behavior with switch.

rc/ $ rc -x
; switch ($x) { case 1 () 0; echo yes }
; switch ($x) { case () ; echo yes }
echo yes
yes
; 

Did I miss something in the man page or is this a real problem? I suspect the patterns are combined into one list, and the middle element is omitted just as it would be for list (1 () 0). It was a surprise though.

TobyGoodwin commented 8 years ago

Umm. It's a "feature", although an unfortunate one.

Lists are flat in rc, which means that there is no way for a list to contain the empty list. A list can only contain strings.

It should be documented though. I'll fix that. Thanks!

TobyGoodwin commented 8 years ago

fixed in 43d2c19d