Re: a golden oldie challenge: Eliza
  Home FAQ Contact Sign in
comp.lang.functional only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: a golden oldie challenge: Eliza         

Group: comp.lang.functional · Group Profile
Author: Stevan Apter
Date: Feb 25, 2008 13:58

"Brian Adkins" gmail.com> wrote in message news:ba2f0ce4-9bcc-4de3-b3c1-d781417a4384@p73g2000hsd.googlegroups.com...
>> He, Ruby is so verbose, both K an Q beat it to death when it comes to
>> brevity. Witness the power, a sudoku solver in K:
>>
>> f:{$[&/x;,x;,/f'@[x;i;:;]'&27=x[,/p i:x?0]?!10]}
>>
>> Not that I understand what this eyesore means, but according to this
>> blog it is supposed to be a sudoku solver:
>
> Boy, I have mixed emotions when reading that. On the one hand, I see
> what at first glance appears to be a collection of random characters.
> On the other hand, I recognize I have zero knowledge of K, so I'm
> slightly curious about a language that seems to take conciseness to an
> obscene level.
>
> Here's a question. Would it be easier to add some verbosity and
> formatting to make the above K program more readable to those who
> don't know K, or to take a readable program in another language and
> make it that short? :)

in k symbols like + are ambivalent: x+y is addition, +x is transposition.
q is k with keywords for the unary case: x+y is addition, flip x is
transposition.

in f we have one instance of a primitive with four arguments: @[x;y;:;w].
so we can define:

amend:{@[x;y;:;z]}

x?y finds y in x. let's cover that as well, and give it infix syntax:

.q.find:?

$[x;y;z;...] is the conditional.

now rewrite f in q like this:

f:{$[all x;enlist x;raze f each amend[x;i]each where 27=x[raze p i:x find 0]find til 10]}
no comments
diggit! del.icio.us! reddit!