Primes by Trial Division - XLISP
20 May 2018
XLISP began with only a superficial resemblance to LISP, over time steadily becoming more and more LISP-like. It doesn't seem like source compatibility between versions was ever a priority.
XLISP v1.1
(defun div? (n list / rc) (setq rc nil) (while (&& (! (null list)) (!= rc t)) (if (% n (car list)) () ((setq rc t))) (setq list (cdr list))) rc) (defun primes (n / primes) (setq count 3) (setq primes (list 2)) (while (> n (length primes)) (if (div? count primes) () ((setq primes (append primes (list count))))) (setq count (+ 1 count))) primes)
XLISP v1.4
Same as v1.6, with the following addition:
(setq T t)
XLISP v1.6
(defun divp (n list) (prog () (mapc #'(lambda (p) (cond ((zerop (rem n p)) (return T)))) list) (return nil))) (defun primes (n) (prog (count primes) (setq count 3) (setq primes (list 2)) NEXT (cond ((< (length primes) n) (cond ((divp count primes) nil) (T (nconc primes (list count))))) (T (return primes))) (setq count (+ 1 count)) (go NEXT)))
XLISP v2.0
(defun divp (n list) (mapc #'(lambda (p) (cond ((zerop (rem n p)) (return-from divp T)))) list) (return-from divp nil)) (defun primes (n) (setq count 3) (setq primes (list 2)) (tagbody NEXT (cond ((< (length primes) n) (cond ((divp count primes) nil) (T (nconc primes (list count))))) (T (return-from primes primes))) (setq count (+ 1 count)) (go NEXT)))