1

I'm trying to return a default value when the other conditionals are not met with the cond statement. How can I achieve this in PicoLisp?

(de fib (n)
  (cond
    ((= n 0) 0)
    ((= n 1) 1)
    (+ (fib (- n 1)) (fib (- n 2))) ) )

(prinl (fib 1)) # prints 1
(prinl (fib 5)) # prints nothing
(bye)

Example coded with this reference code.

(let (Foo "bar")
  (cond
    ((not Foo) "No foo for you")
    ((lst? Foo) (map 'my-list-function Foo))
    ((= Foo "bar") "Foobar")
    "Nothing is true" ) )
A1rPun
  • 16,287
  • 7
  • 57
  • 90

1 Answers1

2

You have to use the T global to return a default value with cond.

(de fib (n)
  (cond
    ((= n 0) 0)
    ((= n 1) 1)
    (T (+ (fib (- n 1)) (fib (- n 2)))) ) )

(prinl (fib 1)) # prints 1
(prinl (fib 5)) # prints 5
(bye)
A1rPun
  • 16,287
  • 7
  • 57
  • 90