William James
5/8/2015 6:54:00 AM
Rainer Joswig wrote:
> ; Let's generate a pair of a random string and a number.
> ; The number is the sum of the character ascii values in the string.
>
> (defun make-pair ()
> (loop with length = (random 100)
> with string = (make-string length)
> for i below length
> for char = (code-char (+ 32 (random 90)))
> summing (char-code char) into sum
> do (setf (aref string i) char)
> finally (return (cons sum string))))
Gauche Scheme:
(use srfi-27 :only (random-integer))
(use srfi-13 :only (string-tabulate))
(define (make-pair)
(define sum 0)
(define string
(string-tabulate
(lambda _
(let1 random (+ 32 (random-integer 90))
(inc! sum random)
(integer->char random)))
(random-integer 100)))
(cons sum string))
(make-pair)
===>
(2634 . "n]'?Cm7$h[Fcq+0x7(-9,hn&TXQ -]lPWG?1")
--
Use this [sword] for me, if I rule well; if not, against me.
--- Trajan
The strongest reason for the people to retain the right to bear arms is, as a
last resort, to protect themselves against tyranny in government.
--- Thomas Jefferson