Sponsored links: Algebra eBooks
 

Related

unless

Run Example
(%i1):lisp (defun lottery (&optional (p ()))  (let ((non-randoms '(49 49 49 49 49 49)) (random-tuple))    (dolist        (x non-randoms           (if (not p)               random-tuple               (values-list random-tuple)))      (push (1+ (random x)) random-tuple))));

LOTTERY
(%i1) :lisp (lottery);

(22 10 8 28 13 10)
(%i1) :lisp (lottery t);

16
17
32
3
24
12
(%i1) :lisp (defun make-number-gen (m &optional n)  #'(lambda (cmd)      (ecase cmd        (:test (and (numberp n) (>
 m n)))        (:get m)        (:next (prog1 m                    (unless (and (numberp n) (>
 m n))                      (incf m)))))));

MAKE-NUMBER-GEN
(%i1) :lisp (make-number-gen 3 10);

(LAMBDA-CLOSURE ((N 10) (M 3)) ()
    ((MAKE-NUMBER-GEN BLOCK #<@0000000002BA3090>)) (CMD)
  (ECASE CMD (TEST (AND (NUMBERP N) (> M N))) (GET M)
         (NEXT (PROG1 M (UNLESS (AND (NUMBERP N) (> M N)) (INCF M))))))
(%i1) :lisp (let ((l)) (cons (funcall (make-number-gen 3 10) :get) l) l);

NIL
(%i1) 
Run Example
:lisp (defun lottery (&optional (p ()))  (let ((non-randoms '(49 49 49 49 49 49)) (random-tuple))    (dolist        (x non-randoms           (if (not p)               random-tuple               (values-list random-tuple)))      (push (1+ (random x)) random-tuple))));

LOTTERY
(%i1) :lisp (lottery);

(22 10 8 28 13 10)
(%i1) :lisp (lottery t);

16
17
32
3
24
12
(%i1) :lisp (defun make-number-gen (m &optional n)  #'(lambda (cmd)      (ecase cmd        (:test (and (numberp n) (>
 m n)))        (:get m)        (:next (prog1 m                    (unless (and (numberp n) (>
 m n))                      (incf m)))))));

MAKE-NUMBER-GEN
(%i1) :lisp (make-number-gen 3 10);

(LAMBDA-CLOSURE ((N 10) (M 3)) ()
    ((MAKE-NUMBER-GEN BLOCK #<@0000000002BA30A0>)) (CMD)
  (ECASE CMD (TEST (AND (NUMBERP N) (> M N))) (GET M)
         (NEXT (PROG1 M (UNLESS (AND (NUMBERP N) (> M N)) (INCF M))))))
(%i1) :lisp (funcall (make-number-gen 10 3) :get);

10
(%i1) :lisp (let ((result)) (push (funcall (make-number-gen 3) :test) result) result);

(NIL)
(%i1) 
Run Example
:lisp (defun lottery (&optional (p ()))  (let ((non-randoms '(49 49 49 49 49 49)) (random-tuple))    (dolist        (x non-randoms           (if (not p)               random-tuple               (values-list random-tuple)))      (push (1+ (random x)) random-tuple))));

LOTTERY
(%i1) :lisp (lottery);

(22 10 8 28 13 10)
(%i1) :lisp (lottery t);

16
17
32
3
24
12
(%i1) :lisp (defun make-number-gen (m &optional n)  #'(lambda (cmd)      (ecase cmd        (:test (and (numberp n) (>
 m n)))        (:get m)        (:next (prog1 m                    (unless (and (numberp n) (>
 m n))                      (incf m)))))));

MAKE-NUMBER-GEN
(%i1) :lisp (defun advance-gen (gen)  (funcall gen :next));

ADVANCE-GEN
(%i1) :lisp (defun empty-gen-p (gen)  (funcall gen :test));

EMPTY-GEN-P
(%i1) :lisp (defun extrude (n gen)  (do ((l nil (cons (advance-gen gen) l))       (i 0 (1+ i)))      ((or (empty-gen-p gen) (>
= i n))       (nreverse l))));

EXTRUDE
(%i1) :lisp (extrude 10 (make-number-gen 1 7));

(1 2 3 4 5 6 7)
(%i1) 

Related Help

Help for Unless