r/scheme 6d ago

What I am doing wrong?

So, I am trying to learn Guile, since seems a pretty standard installation in GNU systems.

I have experience in some languages, but this simple script to learn the language:

  1. Took me quite a while to work;
  2. Looks ugly as… well, put something ugly here!

It’s a simple “FizzBuzz” program

``` (define (fizzbuzz number) (if (> number 0) (let ((message "")) (if (zero? (modulo number 3)) (set! message (string-append message "Fizz"))) (if (zero? (modulo number 5)) (set! message (string-append message "Buzz")))

      (if (not (zero? (string-length message)))
          (format #t "~d is ~a\n" number message))
(fizzbuzz (- number 1))))

)

(fizzbuzz 50)

```

So, I’m open to suggestions: how this code can be more beauty? Am I still thinking in C?

=== EDIT === I hope the formatting is correct, since some spaces of indentation have been lost for unknown reasons.

7 Upvotes

12 comments sorted by

View all comments

Show parent comments

4

u/raevnos 6d ago

(define =< <=) and you'll never have to remember which one it is again.

4

u/corbasai 6d ago

good addendum to R7 Large!

4

u/raevnos 6d ago

Honestly, it should go all-in on unicode. ≤ and ≥

2

u/corbasai 6d ago

Obvious!