Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Many alligators will be slain, but the swamp will remain.


devel / comp.lang.lisp / .Re: lisp code problem, post your solution!

SubjectAuthor
o .Re: lisp code problem, post your solution!Robert L.

1
.Re: lisp code problem, post your solution!

<suuht9$1bn7$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16910&group=comp.lang.lisp#16910

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!cnMFwgAl3AZSZhKJg9s53w.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: lisp code problem, post your solution!
Date: Sun, 20 Feb 2022 23:12:42 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <suuht9$1bn7$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="44775"; posting-host="cnMFwgAl3AZSZhKJg9s53w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Sun, 20 Feb 2022 23:12 UTC

Pascal J. Bourguignon wrote:

> >> count from 1 to 100
> >> if the number is divizible by three print fizz
> >> if by 5 print bazz
> >> if by both 3 and 5, print fizzbazz
> >> if none of those, print the number
> >>
> >>
> >>
> >> post your lisp solution!
>
>
> Just put parentheses around your own solution!
>
> (defun divisiblep (n d) (zerop (mod n d)))
>
> (loop for number from 1 to 100
> if (divisiblep number 3) do (princ "fizz")
> if (divisiblep number 5) do (princ "bazz")
> if (not (or (divisiblep number 3) (divisiblep number 5))) do (princ number)
> do (terpri))

Gauche Scheme and Racket:

(use srfi-42) ;; do-ec for Gauche
or
(require srfi/42) ;; do-ec for Racket
(require srfi/1) ;; any for Racket

(define (maybe-print n d text)
(and (zero? (modulo n d)) (display text)))

(define (fizz)
(define stuff '((3 fizz) (5 buzz) (7 hum)))
(do-ec (:range i 1 36)
(begin
(or (any values (map (lambda (xs) (apply maybe-print i xs)) stuff))
(display i))
(newline))))

(fizz)
===>
1 2
fizz
4 buzz
fizz
hum
8 fizz
buzz
11
fizz
13
hum
fizzbuzz
16
17
fizz
19
buzz
fizzhum
22
23
fizz
buzz
26
fizz
hum
29
fizzbuzz
31
32
fizz
34
buzzhum


devel / comp.lang.lisp / .Re: lisp code problem, post your solution!

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor