Skip to content
Prev 174708 / 398506 Next

If statement generates two outputs

Berwin A Turlach wrote:
yet another bug??
well, you can't do it with, e.g., ':==', because you'd get a *syntactic*
error (while ':=' gives a semantic error):

    a :== 1
    # syntactic error: unexpected '=' in ':='

    ':==' = function(a, b) NULL
    a :== 1
    # syntactic error again, of course

it's indeed surprising that it works with ':=' but not with, e.g., ':>'.

and in cases like ':-' you'd in fact use two operators (so an
'overloading' won't work for these):

    ':-' = function(a, b) a - if(a > b) b else 0
    2 :- 1
    # 2 1 0 -1
    # not 1

it's interesting to note that

    a :< b
    # error: unexpected '<' in ':<'

will tell you what's unexpected, while

    a :% b
    # error: unexpected input in 'a :% b'

    a :_ b
    # error: unexpected input in 'a :_'

will leave you wondering what's wrong there.



vQ