Little fun things to do in CL

Discussion of Common Lisp

Little fun things to do in CL

Postby voosey » Wed Apr 13, 2016 5:33 pm

Hi guys

I'm looking for little things that I can do with CL. I've been trying to learn the language for quite some time. I am finding it hard to get a grip on the language. So I would like a list(pun) of fun things to do in the language. Like changing the text color and mini text based games. I have a copy of Land of Lisp with no luck of understanding the language to well. Maybe I shouldn't have started out with C++ a few years back. I want CL for the power nothing more.
voosey
 
Posts: 2
Joined: Wed Apr 13, 2016 5:19 pm

Re: Little fun things to do in CL

Postby edgar-rft » Mon Apr 18, 2016 5:31 pm

Hi voosey,

I see that nobody has answered your question so far, so here some chatter from the ##lisp IRC channel on Freenode.net with funny Lisp code.

Everything started with the question "if woah is a misspelling of whoa, what is the meaning of woah?" Then I looked at urbandictionary.com and there was written "Woah, you have nothing better to do with your time than to look up the spelling of woah." Some other guy said: "Woah, that's a recursive definition of woah!" and that's why I wrote this recursive definition of woah:

Code: Select all
(defun woah ()
  "Print some nonsense recursively a random number of times."
  (princ "WOAH! ")
  (if (zerop (random 10))
      (finish-output)
      (woah)))

(princ "WOAH! ") prints WOAH! and a space character without any line-break, then the function calls itself until (random 10) returns a zero. (finish-output) flushes the output buffer.

Here's what happens at the REPL:

Code: Select all
CL-USER> (woah)
WOAH! WOAH! WOAH! WOAH! WOAH! WOAH! WOAH! WOAH!

Then we saw that WOAH! looks like batman fight noise what lead to the following code:

Code: Select all
(defparameter *noise* '(awk bam bang biff blop boff bonk clank clash clunk
  crash crunch kapow klonk klunk krunch pam plop pow slosh splat swap swish
  swooch thunk twack ugh urk vronk whack wham whap zam zap zlonk zlop zlot
  zok zow zwap)
  "Weird batman fight noise.")

(defun batman (words)
  "Make some batman fight noise of random words and length."
  (let ((word (nth (random (length words)) words)))
    (cond ((zerop (random 10))
           (format t "~S!~%" word)
           (finish-output))
          (t
           (format t "~S!, " word)
           (batman (remove word words))))))

(nth (random (length words)) words) picks a random word from the list of words. (format t <format-string> <arguments>) prints the arguments as a string to the *standard-output* stream. (remove word words) removes the printed word from the list of words before the function is recursively called to avoid duplicate words on the screen.

Here you can watch batman fight at the REPL:

Code: Select all
CL-USER> (batman *noise*)
SWOOCH!, URK!, CRUNCH!, ZOK!, ZAP!, PLOP!, UGH!, PAM!

In the CLiki (Common Lisp Wiki) under Getting Started there are lots of links to free books and other stuff.

- edgar
edgar-rft
 
Posts: 224
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: Little fun things to do in CL

Postby voosey » Mon Apr 18, 2016 6:22 pm

Wow, that is pretty cool. I remember learning other languages and having fun during the process sure helps. I wounder what else can be done, for new comers like myself?
voosey
 
Posts: 2
Joined: Wed Apr 13, 2016 5:19 pm

Re: Little fun things to do in CL

Postby pjstirling » Thu Apr 21, 2016 9:09 am

It's hard to know what to suggest here, CL can do almost anything you can think of, so it really needs to be something that YOU are interested in.

To give you some examples of itches that I've scratched with CL:

  • A tool for creating project skeletons and managing them with source control for easy use across my computers (including symlinking .asd files in my system directory, blast from the past!)
  • A solver for Picross/nonograms
  • A script that stitches together webpages into a single document
  • A small webapp that serves files from a .zip file (saving my laptop's SSD from the java documentation's MASSIVE number of tiny files, when I'm away from wi-fi)
  • A code-sharing web-app that allows interactive macroexpansion (source) (demo)
  • A proxy for an amateur fiction site that let's me easily track spelling and grammar mistakes to submit to the author once I'm finished
  • And my music streaming web-app that I've been growing features on, whenever something starts to bug me too much

I tend to use web-apps as my UI because it's mostly a stable platform (new stuff gets added but deprecated stuff almost never disappears) this compares to using FFI to access QT or Gnome where at major version changes you need to make more pervasive changes.

That doesn't mean interesting things can't been done with native apps, sketch (not mine) looks quite cool.
pjstirling
 
Posts: 130
Joined: Sun Nov 28, 2010 4:21 pm

Re: Little fun things to do in CL

Postby Goheeca » Wed May 18, 2016 2:31 pm

voosey wrote:Like changing the text color and mini text based games.


I once wrote this code when I was introducing myself to multithreading in Common Lisp. It prints colored text into the console, it uses ANSI escape sequences (on Windows I recommend start using ansicon; don't miss the release page), the other possibility is to use one of the bindings to the ncurses/PDCurses library.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
User avatar
Goheeca
 
Posts: 271
Joined: Thu May 10, 2012 12:54 pm

Re: Little fun things to do in CL

Postby simonlucas » Mon Jul 11, 2016 2:55 pm

I've been going through the Winston/Horn book to re-acquaint myself with lisp.

I think for many (me included), it's nice to get visual responses to things when learning languages. Plotting lines or drawing with ascii for example.

If you can draw lines with your installation of Common Lisp, on page 76 of Winston/Horn there's a recursive function that draws 'c curves'.

Code: Select all
(defun c-curve (length angle min-length)
(cond ((< length min-length) (plot-line length angle))
      (t (c-curve (/ length (sqrt 2.0))
                  (+ angle (/ pi 4.0))
                  min-length)
         (c-curve (/ length (sqrt 2.0))
                  (- angle (/ pi 4.0))
                  min-length))))


You also need

Code: Select all
(defun plot-line (length angle)
  (connect-line (+ x-old (* length (cos angle)))
                (+ y-old (* length (sin angle)))))

(defun connect-line (x-new y-new)
  (draw-line x-old y-old x-new y-new)
  (setq x-old x-new y-old y-new))


You would need to define your own 'draw-line' that draws into a target window. x-old and y-old are global.

I can post the 'dragon-curve', once I have worked it out.
Lisp novice.
simonlucas
 
Posts: 1
Joined: Mon Jul 11, 2016 2:45 pm


Return to Common Lisp

Who is online

Users browsing this forum: Exabot [Bot] and 3 guests