0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

多言語FizzBuzzAdvent Calendar 2022

Day 18

多言語FizzBuzzチャレンジ18日目:LISP

Last updated at Posted at 2022-12-17

これまでのまとめ

本日のお品書き

ついに来ましたLISP(Common LISP)…! 括弧がたっぷりということだけは知っていますが、自分で書いたことはない…!楽しみですね。

FizzBuzz

(defun fizzbuzz(i)
  ;; Lispではelse ifが無いので複数条件を書くときはcondが楽そう
  ;; princでは""は無視して表示される。改行のためにterpriを追加。
  (cond ((= (mod i 15) 0) (princ "FizzBuzz")(terpri))
        ((= (mod i 3) 0) (princ "Fizz")(terpri))
        ((= (mod i 5) 0) (princ "Buzz")(terpri))
        ;; t = trueのこと
        (t (princ i)(terpri))))

(dotimes (x 100) (fizzbuzz (+ x 1)))

おまけ:実行環境

Common LISPのHPを見るとsbclの利用が案内されていたのでLinux環境に導入しました。

sudo apt-get sbcl
# edit fizzbuzz.lisp
sbcl --script fizzbuzz.lisp
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?