0

for example,

(cond ((< 2 1) 2 )((< 1 2 ) 1)) has value 1. OK;

But, I saw that (cond (diverge 1) (ture 0)) is undefined, if diverge does not terminate' in my major book.

What's the diverge in lisp??

I don't know that.

Also, I don't know exactly what is side effects in lisp.

Vinay Prajapati
  • 7,199
  • 9
  • 45
  • 86
StackQ
  • 99
  • 1
  • 11

2 Answers2

4

Assuming the code you originally meant is

(cond ((diverge 1) (ture 0)))

then the result of that expression is undefined (or better, diverging, too) when we assume diverge to be an - as its name suggests - diverging operation.

A diverging operation is one that does not converge to a result, like for example an infinite loop.

There's no diverge defined in the Common Lisp standard (what practical purpose would it have?), so your book is just omitting the "implementation details" of an diverging computation by wrapping it in a operation and naming it appropriately.

Note that the original code can expose the same behaviour if one assumes diverge to be a symbol macro.

Daniel Jour
  • 15,896
  • 2
  • 36
  • 63
  • OP's code could be valid and never terminates, provided there is something like `(define-symbol-macro diverge (loop))` elsewhere ;-) – coredump Mar 28 '16 at 13:03
  • Ah yes, symbol macros. I wanted to keep the complexity low, but added a note :) – Daniel Jour Mar 28 '16 at 15:16
2

As shown, diverge and ture would name variables that are evaluated as booleans. The value of the entire expression is 1 if diverge is true, 0 if ture is true, and nil if neither is true.

Since you did not show the context, especially how diverge and ture are bound, more cannot be said about your snippet.

Maybe you meant something like (cond ((diverge 1) (ture 0))). Then diverge would be an operator. It is not defined in the Common Lisp standard, so it most likely comes from somewhere else in your book.

Svante
  • 50,694
  • 11
  • 78
  • 122