;---------------------------------------------------------------
; Last few days I played with definition of IF as function.
; It is typically not possible in Lisp family, but Newlisp
; can do that. I present here two definitions of IF that are
; specific not only because of that, but also because the
; definitions do not use any equivalent built in (like if, cond,
; case) and also, definitions do not use any variables.
;---------------------------------------------------------------
(set 'IF (lambda()
(eval
((args)
(- 5 (length
(string
(true?
(eval (first (args)))))))))))
(let ((x 2)(y 3))
(IF '(< x y)
'(println x " is less than " y)
'(println x " is not less than " y))
(IF '(> x y)
'(println x " is greater than " y)
'(println x " is not greater than " y)))
;---------------------------------------------------------------
(set 'IF (lambda()
(eval
((args)
(find (true? (eval (first (args))))
'(* true nil))))))
(let ((x 2)(y 3))
(IF '(< x y)
'(println x " is less than " y)
'(println x " is not less than " y))
(IF '(> x y)
'(println x " is greater than " y)
'(println x " is not greater than " y)))
(exit)
Two Definitions of IF Function.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment