Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #374: It's the InterNIC's fault.


comp / comp.lang.lisp / Re: A style question

SubjectAuthor
* Re: A style questionB. Pym
`- Re: A style questionB. Pym

1
Subject: Re: A style question
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Fri, 9 Aug 2024 07:40 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: A style question
Date: Fri, 9 Aug 2024 07:40:20 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <v94h50$komi$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 09 Aug 2024 09:40:20 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b56adfd1b06b773bd0a515961a3e0f95";
logging-data="680658"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EyN6Po55doa95xOsRL9aE"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:pz9pJhyBAbn0uv8IQCUiCs53j0g=
View all headers

Brian wrote:

> > (defun fizz-buzz (n)
> > (do ((i 1 (+ i 1)))
> > ((> i n))
> > (let
> > ((fizz (= 0 (mod i 3)))
> > (buzz (= 0 (mod i 5))))
> > (if fizz (format t "Fizz"))
> > (if buzz (format t "Buzz"))
> > (format t "~A~%"
> > (if (or fizz buzz) "" i)))))
> >
> > (fizz-buzz 100)
>
> Another friend of mine commenting on the same FizzBuzz thread supplied
> the following Python code. It certainly is concise:
>
> for i in xrange(1,101):
> print(str(i), "Fizz", "Buzz", "FizzBuzz")[(i%3==0)|(i%5==0)<<1]

newLISP

(define (fizz)
(define (any _test) (exists _test $args))
(define (divis n) (= 0 (mod i n)))
(for (i 1 21)
(if (divis 3) (print 'fizz))
(if (divis 5) (print 'buzz))
(if (divis 7) (print 'zoom))
(unless (any divis 3 5 7) (print i))
(println)))

(fizz)

1
2 fizz
4 buzz
fizz
zoom
8 fizz
buzz
11
fizz
13
zoom
fizzbuzz
16
17
fizz
19
buzz
fizzzoom

Subject: Re: A style question
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Fri, 9 Aug 2024 08:53 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: A style question
Date: Fri, 9 Aug 2024 08:53:24 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 80
Message-ID: <v94le0$lg03$1@dont-email.me>
References: <v94h50$komi$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 09 Aug 2024 10:53:24 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b56adfd1b06b773bd0a515961a3e0f95";
logging-data="704515"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/H91a0lIygR2WEi1xBflKF"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:pHWilOHNdARDSXLHIwFl9VXUxHc=
View all headers

B. Pym wrote:

> Brian wrote:
>
> > > (defun fizz-buzz (n)
> > > (do ((i 1 (+ i 1)))
> > > ((> i n))
> > > (let
> > > ((fizz (= 0 (mod i 3)))
> > > (buzz (= 0 (mod i 5))))
> > > (if fizz (format t "Fizz"))
> > > (if buzz (format t "Buzz"))
> > > (format t "~A~%"
> > > (if (or fizz buzz) "" i)))))
> > >
> > > (fizz-buzz 100)
> >
> > Another friend of mine commenting on the same FizzBuzz thread supplied
> > the following Python code. It certainly is concise:
> >
> > for i in xrange(1,101):
> > print(str(i), "Fizz", "Buzz", "FizzBuzz")[(i%3==0)|(i%5==0)<<1]
>
> newLISP
>
> (define (fizz)
> (define (any _test) (exists _test $args))
> (define (divis n) (= 0 (mod i n)))
> (for (i 1 21)
> (if (divis 3) (print 'fizz))
> (if (divis 5) (print 'buzz))
> (if (divis 7) (print 'zoom))
> (unless (any divis 3 5 7) (print i))
> (println)))
>
> (fizz)
>
> 1
> 2
> fizz
> 4
> buzz
> fizz
> zoom
> 8
> fizz
> buzz
> 11
> fizz
> 13
> zoom
> fizzbuzz
> 16
> 17
> fizz
> 19
> buzz
> fizzzoom

Another way:

(define-macro (try-all) ;; Arguments are in $args or (args).
(let (_successes nil)
(dolist (_expr $args)
(when (eval _expr) (++ _successes)))
_successes))

(define (fizz)
(define (divis n) (= 0 (mod i n)))
(for (i 1 21)
(unless
(try-all
(if (divis 3) (print 'fizz))
(if (divis 5) (print 'buzz))
(if (divis 7) (print 'zoom)))
(print i))
(println)))

1

rocksolid light 0.9.8
clearnet tor