Re: A style question



On 2007-02-28 17:38:48 +0000, Richard M Kreuter <kreuter@xxxxxxxxx> said:

I think you mean "~&~[Fizz~:;~]~[Buzz~:;~D~]~%" right?

Probably, yes.


(dotimes (i 100)
(format t "~[~[~3@*~A~A~:;~3@*~A~]~:;~[~4@*~A~:;~D~]~]~%"
(mod i 3) (mod i 5) i "Fizz" "Buzz"))


Really good, yes. Almost impossible to work out what it does. The perfectionist in me would insist on

"~&~[~[~3@*~A~A~:;~3@*~A~]~:;~[~4@*~A~:;~D~]~]~%"

- you do actually want that so you know it always starts a line properly, apart from being an extra bit of squigglines. But that's trivial compared to the main drag of it.

I'm unhappy about the explicit looping however. I can see two solutions to this:

* something really gratuitous involving GO
* something equally gratuitous involving a lot of LAMBDAs.

I think I may be too rusty to write this, but something like:

(defun fb (n)
((lambda (c p)
(funcall c c p 1)
(lambda (c p i)
(or (> i n)
(funcall p c p i)))
(lambda (c p i)
(format t "~[~[~3@*~A~A~:;~3@*~A~]~:;~[~4@*~A~:;~D~]~]~%"
(mod i 3) (mod i 5) i "Fizz" "Buzz")
(funcall c c p (1+ i))))))

(I should point out that I don't have a CL on the system I'm writing this.)

--tim

.



Relevant Pages

  • Re: A style question
    ... variable thickness with rounded corners of variable radius: ... (defun transparentp (color) ... (lambda (x y) ... (c2 (funcall fun2 x y))) ...
    (comp.lang.lisp)
  • Re: A style question
    ... (yes, this still uses LOOP, but it is somewhat buried). ... (lambda (c p i) ... (funcall p c p i))) ... (defun fizzbuzz (n) ...
    (comp.lang.lisp)
  • Re: Paul Grahams Arc is released today... what is the long term impact?
    ... If you write all of your code in the first form, you can go home a full hour and a half hour sooner because you've shaved off all that unnecessary time reading that cumbersome lambda form. ... But that's because I already know that WHEN does not FUNCALL it's second argument. ... If you happen to be writing something with the semantics of a WHEN, i.e. introducing syntax for a new control structure, perhaps a macro is the best way to write it because of purely semantic reasons. ... And if every Lisp operator was defined to take an anonymous function which would be FUNCALLed, I would probably find it annoying to have to use LAMBDA everywhere, too. ...
    (comp.lang.lisp)
  • Re: why funcall is needed in things like ((foo) 10)
    ... a lisp symbol or expression can have different ... funcall version is clearer anyhow. ... function name or lambda expression. ...
    (comp.lang.lisp)
  • Re: Scoping of functions.
    ... By compile-time I mean the time that the lambda expression ... (defun make_foo() ... (funcall temp_foo y))) ... (setf x 3) ...
    (comp.lang.lisp)