Logged In: YES

user_id=501686

Originator: NO

From what I can tell, the parser indeed looks to see if the first argument of "if" is a Boolean expression, but the test is weak -- it only detects non-Boolean expressions for operators which are declared non-Boolean via the POS property. The parser's test appear to pass patently non-Boolean expressions such as numbers.

e.g.

prefix ("@@", 100, expr, expr);

if @@ 1 then a else b;

=> Incorrect syntax: Found algebraic expression where logical expression expected

Same result with other operators which have POS = $EXPR e.g.: + . ^ ^^

Maybe changing NUD-CALL in src/nparse.lisp is enough. Here is the current version:

(defun nud-call (op)

(let ((tem (and (symbolp op) (getl op '(nud)))) res)

(setq res

(if (null tem)

(if (operatorp op)

(mread-synerr "~A is not a prefix operator" (mopstrip op))

(cons '$any op))

(funcall (cadr tem) op)))

res))

Here is a version which causes if 1234 then a else b; to trigger an error:

(defun nud-call (op)

(let ((tem (and (symbolp op) (getl op '(nud)))) res)

(setq res

(if (null tem)

(if (operatorp op)

(mread-synerr "~A is not a prefix operator" (mopstrip op))

(if ($numberp op) (cons '$expr op) (cons '$any op))) ;; changed this line

(funcall (cadr tem) op)))

res))

Probably ($NUMBERP OP) should be something more complicated. We want to rule out numbers, strings, what else? Maybe objects such as matrices, lists, and sets?