[quiz] Quiz #2 - Argh! The parenthesis! They burn my eyes!
Marco Baringer
mb at bese.it
Sun May 7 17:12:46 UTC 2006
Argh! The parenthesis! They burn my eyes!
-----------------------------------------
Overview
========
One of the more common complaints people have against the lisp
language family is the abbundance of parenthesis is source code. "To
hell with 'em!" I hear you say, and you're right, but it still makes
for an interesting quiz.
Goal
====
You're going to prove that common lisp really is the "Programmable
Programming Language"[1] by changing the syntax to use less
parenthesis.
Write a function quiz2::read-off-side which allows python-style
whitspace-sensitive source code (this is sometimes called the "off
side" rule[2]). This function will be bound to the #! dispatching
macro character and so must have this api (the test suite assumes
this):
(quiz2::read-off-side stream subchar parameter) => form
The easiest way to explain how the syntax works is to show it.
Example 1:
#!
when
t
(do-stuff)
!#
=> (progn (when t (do-stuff)))
Example 2:
1:#!
2:cond
3: (zerop a)
4: (write-line "A is zero.")
5: (plusp a)
6: (write-line "A is positive.")
7: t
8: (write-line "A is negative.")
9:(write-line "Done.")
b:!#
=>
(progn
(cond
((zerop a)
(write-line "A is zero."))
((plusp a)
(write-line "A is positive."))
(t
(write-line "A is negative.")))
(write-line "Done."))
If you doubts on how a form should be parsed see the print-off-sides
function in the test suite.
Test Suite
==========
A test suite is available at:
http://common-lisp.net/project/quiz/quizzes/quiz2/test.lisp
You'll need to load your code before that file, it assumes the quiz2
package, and read-off-side function, already exist. After you've
loaded the file execute (5am:run! :quiz2) to run the test suite, it
uses my FiveAM[3] test suite. If you want to rewrite the test suite
using another framework go ahead, I'll add a link to your rewrite
here.
[1] - John Foderaro, CACM, September 1991
[2] - http://en.wikipedia.org/wiki/Off-side_rule
[3] - http://common-lisp.net/project/bese/FiveAM.html
--
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
-Leonard Cohen
More information about the Quiz
mailing list