From: Thomas Bakketun on
Vassil Nikolov skreiv:
> Oh, and another way to obfuscate ^W do the ringy-dingy count is:
>
> (let ((counter 0))
> (format t "~3@{~'R/$/ r~A-~:*d~A...~%~@*~}" (by-name (incf counter)) "ingy"))

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.
From: Vassil Nikolov on

On Thu, 05 Nov 2009 00:50:26 +0100, Thomas Bakketun <thomas(a)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?"
From: John Thingstad on
Den Thu, 05 Nov 2009 00:50:26 +0100, skrev Thomas Bakketun:

> Vassil Nikolov skreiv:
>> Oh, and another way to obfuscate ^W do the ringy-dingy count is:
>>
>> (let ((counter 0))
>> (format t "~3@{~'R/$/ r~A-~:*d~A...~%~@*~}" (by-name (incf
>> counter)) "ingy"))
>
> 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.

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":

#:: ::-| ::-| .-. :||-:: 0-| .-| ::||-| .:|-. :||
open(Q,$0);while(<Q>){if(/^#(.*)$/){for(split('-',$1)){$q=0;for(split){s\|
/:.:/xg;s/:/../g;$Q=$_?length:$_;$q+=$q?$Q:$Q*20;}print chr($q);print"\n";
#.: ::||-| .||-| :|||-| ::||-| ||-:: :|||-| .:|

prints "The Perl Journal"

http://mysite.verizon.net/les.peters/id2.html
From: Madhu on
* Thomas Bakketun <7leia3F3di316U1(a)mid.individual.net> :
Wrote on Thu, 05 Nov 2009 00:50:26 +0100:

| Format is a nice tool, it can even do the counting for us:

Excellent!

I'm not sure about one construct being portable CL though:

| (format
| t "~1{~#@{~:[~#*~:*~;~:*~#/cl:format/ ~:*~0:/cl:format/...~%~2:*~]~}~}"
------------------------------------------------------------^^^^^^
| `(nil ,@(loop repeat 3 collect "~:[~1*~R~;~2@{~:[r~;d~]ingy~^-~}~]")))
|

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.

--
Madhu