| | > When possible, I prefer obfuscation through FORMAT. | | | | You mean like | | (format t "one ~a~%~:*two ~a~%~:*three ~a~%" x) | +--------------- | | *ROTFLMAO!!* I immediately thought of Lily Tomlin's character Ernestine: | | (let* ((x (format nil "r~a-~:*d~a..." "ingy"))) | (format t "one ~a~%~:*two ~a~%~:*three ~a~%" x)) |
I missed the cultural reference, so I do not understand what you are trying to demonstrate here, but _whatever_ it is, it can be done way more elegantly Using Recursion; and by Adding a Level of Indirection (which also has advantage of avoiding a style warning for LET*!)
(let* ((y (format nil "r~a-~:*d~a..." "ingy")) (x (format nil "~~#[three ~a~%~:*~~;two ~a~%~:*~~@?~~;one ~a~%~~@?~~:;~~@?~~]" y))) (format nil x x x))
+--------------- | * Rob Warnock wrote: | | Thomas A. Russ <t...@sevak.isi.edu> wrote: | | +--------------- | | | You mean like | | | (format t "one ~a~%~:*two ~a~%~:*three ~a~%" x) | | +--------------- | | | | *ROTFLMAO!!* I immediately thought of Lily Tomlin's character Ernestine: | | | | (let* ((x (format nil "r~a-~:*d~a..." "ingy"))) | | (format t "one ~a~%~:*two ~a~%~:*three ~a~%" x)) | | I missed the cultural reference, so I do not understand what you are | trying to demonstrate here... +---------------
See:
http://en.wikipedia.org/wiki/Lily_Tomlin ... Career In 1969, Tomlin joined the sketch comedy show Laugh-In. Some characters from the show have been associated with her throughout her career, including the wisecracking, snorting telephone operator, Ernestine; ...
Ernestine was known for placing telephone calls to victims\\\\\ customers and, while waiting for the call to be answeredr, saying the output from the above FORMAT out loud, to wit:
one ringy-dingy... two ringy-dingy... three ringy-dingy...
+--------------- | (which also has advantage of avoiding a style warning for LET*!) +---------------
Sorry 'bout that. An earlier version looked like this:
(let* ((s "ingy") (x (format nil "r~a-d~a..." s s))) (format t "one ~a~%~:*two ~a~%~:*three ~a~%" x))
but I realized I could use the backup trick to avoid duplicating the string arg and so got rid of the temporary variable S, but then didn't change the LET* to a LET. Happens a lot in exploratory code.
[Note that none of CMUCL, CLISP, nor SBCL (at least, not the versions to which I have access) give the annoying, overprotective "style warning" for a LET* with only one binding that your implementation apparently does.]
-Rob
----- Rob Warnock <r...@rpw3.org> 627 26th Avenue <URL:http://rpw3.org/> San Mateo, CA 94403 (650)572-2607
* (Rob Warnock) <e6WdnbQQ5sPutXHXnZ2dnUVZ_qKdn...@speakeasy.net> : Wrote on Sat, 31 Oct 2009 07:07:15 -0500:
| [Note that none of CMUCL, CLISP, nor SBCL (at least, not the versions to | which I have access) give the annoying, overprotective "style warning" for | a LET* with only one binding that your implementation apparently does.]
No I don't think I've used an implementation that spat this warning either, but I'd bet SBCL did it at some point.
[Note I _had_ to avoid a smiley at all costs. I was afraid this sentence might have given it away.]
On Fri, 30 Oct 2009 21:34:29 -0500, r...@rpw3.org (Rob Warnock) said:
> Thomas A. Russ <t...@sevak.isi.edu> wrote: > +--------------- > | x...@unnamed.xach.com writes: > | > When possible, I prefer obfuscation through FORMAT. > | > | You mean like > | (format t "one ~a~%~:*two ~a~%~:*three ~a~%" x) > +--------------- > *ROTFLMAO!!* I immediately thought of Lily Tomlin's character Ernestine: > (let* ((x (format nil "r~a-~:*d~a..." "ingy"))) > (format t "one ~a~%~:*two ~a~%~:*three ~a~%" x))
To paraphrase a friend of mine, if we shall obfuscate, then let us obfuscate:
* (format t "~3@{~'R/++/ ~@?~%~@*~}" '#:ernestine "r~A-~:*d~A..." "ingy") one ringy-dingy... two ringy-dingy... three ringy-dingy... NIL
(defun $ (stream argument colonp atsignp &rest parameters) ;; do we want to signal an error if we are supplied too many parameters? (destructuring-bind (&optional directive) parameters (let ((format-string (format nil "~~~A~A~A" (if colonp ":" "") (if atsignp "@" "") (or directive #\S)))) (format stream format-string (funcall argument)))))
(defmacro by-name (form) `#'(lambda () ,form))
---Vassil.
-- "Even when the muse is posting on Usenet, Alexander Sergeevich?"
> I am still not sure that the OP is a troll. He could be coming from > another language, and be under the impression that people start > learning CL from the Hyperspec.
That was a _huge_ stumbiling block back in 2000 or 2001 when I first gave Lisp a try. Back then there were basically no free tutorials and the HyperSpec was about all that was available.
I think I got to reading about PROGN, PROGV and friends before running away screaming.
Then Practical Common Lisp came out and life was good. Thanks Peter!
-- That's what I say when people ask me 'aren't you scared of the traffic?' 'Why? The cars are all stopped.' And they look sheepish and agree that commuting on a bicycle in peak hour isn't that much of a problem. --Zebee Johnstone
Format is a nice tool, it can even do the counting for us:
(format t "~1{~#@{~:[~#*~:*~;~:*~#/cl:format/ ~:*~0:/cl:format/...~%~2:*~]~}~}" `(nil ,@(loop repeat 3 collect "~:[~1*~R~;~2@{~:[r~;d~]ingy~^-~}~]")))
If you want more or less ringy-dingies just change the number 3 between repeat and collect.
Note that this code does not use format to build the format string. This way subtle bugs are avoided and the code becomes simple and easy to understand.
On Thu, 05 Nov 2009 00:50:26 +0100, Thomas Bakketun <tho...@bakketun.net> said:
> ... > Format is a nice tool, it can even do the counting for us: > (format > t "~1{~#@{~:[~#*~:*~;~:*~#/cl:format/ ~:*~0:/cl:format/...~%~2:*~]~}~}" > `(nil ,@(loop repeat 3 collect "~:[~1*~R~;~2@{~:[r~;d~]ingy~^-~}~]")))
That's the spirit!
> ... > Note that this code does not use format to build the format > string. This way subtle bugs are avoided and the code becomes simple > and easy to understand.
:- )
---Vassil.
-- "Even when the muse is posting on Usenet, Alexander Sergeevich?"
> If you want more or less ringy-dingies just change the number 3 between > repeat and collect.
> Note that this code does not use format to build the format string. This > way subtle bugs are avoided and the code becomes simple and easy to > understand.
I'd like to give a example from another language that if famous for it's clarity of exposition.
Here is the winner of "The Perl Journal's Obfuscated Perl Contest in 2000":
The problem is with the `~2:*' in the main format string. 22.3.7.1 says ``When within a ~{ construct (see below), the ignoring (in either direction) is relative to the list of arguments being processed by the iteration.''
When the ~2:* is encountered, we are processing a list in the inner iteration and are at the second element of _this_ list being processed. An implementation is free to throw an error since it cannot skip more than 2 elements backwards in a list of length 1.
I think LW's implementation follows this interpretation of the spec.
The problem is with the `~2:*' in the main format string. 22.3.7.1 says ``When within a ~{ construct (see below), the ignoring (in either direction) is relative to the list of arguments being processed by the iteration.''
When the ~2:* is encountered, we are processing a list in the inner iteration and are at the second element of _this_ list being processed. An implementation is free to throw an error since it cannot skip more than 2 elements backwards in a list at position 1.
I think LW's implementation follows this interpretation of the spec.