Re: [Factor-talk] when-empty

2017-03-01 Thread Björn Lindqvist
It is because when-zero preserves the value on the stack if it isn't zero. I think it is easier to see the mistake if you forego using the when-* combinators: : check0 ( n -- ) 0 = [ call-fail ] [ ] if ; : check0 ( n -- ) [ call-fail ] [ ] if-zero ; Both quotations supplied to if-zero has effect

Re: [Factor-talk] when-empty

2017-03-01 Thread Alexander Ilin
Continuing with this example, here's what I stumbled upon (again), and found confusing (once more): This works as expected: ```: check0 ( n -- ) 0 = [ call-fail ] when ;``` This fails to compile: ```: check0 ( n -- ) [ call-fail ] when-zero ;``` But according to the documented stack effect (at leas

Re: [Factor-talk] when-empty

2017-03-01 Thread Alexander Ilin
Here's a slightly better stack effect documentation: `when-zero ( ..a n quot: ( ..a -- ..b ) -- ..b )` But IIUC the actual stack effect is one of these: `when-zero ( ..a 0 quot: ( ..a -- ..b ) -- ..b )``when-zero ( ..a n#0 quot: ( ..a -- ..b ) -- ..a n )` where # denotes inequality. Am I right? How

Re: [Factor-talk] when-empty

2017-03-01 Thread John Benediktsson
A stack effect of ( seq quot -- ) doesn't say what the quot is expected to do... You can play around with it and see how it works: IN: scratchpad "abc" [ "empty" ] when-empty . "abc" IN: scratchpad "" [ "empty" ] when-empty . "empty" We should improve the docs here because they