[Edu-sig] Generating prime numbers

Edward Cherlin echerlin at gmail.com
Tue Apr 7 20:42:23 CEST 2009


On Sun, Apr 5, 2009 at 9:07 AM, kirby urner <kirby.urner at gmail.com> wrote:
> As my grandmother might have said:  ai yai yai
> http://answers.yahoo.com/question/index?qid=20081203103806AA4TSOq
>
> I'm guessing Kay (XY? XX? -- not that I need to know) is a LISP and/or
> Scheme head, by the looks of those lambdas.  Probably why Python
> doesn't want a big one is precisely this:  the language would fall
> under the control of the Great Lambda Kings (a small tribe to our
> north, spends all its time extending emacs).
>
> Ya gotta love 'em!

You should try UnLambda, then. ;-> _The_ most minimalist Turing-tarpit
language I knew of until just this moment, when I looked it up on
Wikipedia and found out about the languages Iota and Jot. Wonderful
for proof-of-concept studies. There is a Parrot implementation of
UnLambda. Here, for example, is an UnLambda implementation of the Y
fixed-point combinator.

```s``k``sii``s``s`ksk`k``sii

where i is an abbreviation for  ``skk.

Joy is a pure functional languages without Lambda. A square function
in Joy is quite FORTH-like.

DEFINE square == dup * .

J also does without Lambda. It has a functional subset with Currying
(&) in which one can write

square =. ^&2

I helped Iverson with a small design point in that functional subset,
and wrote a paper about a generalization of the idea for the next
year's APL conference. In the class of languages I discussed, one can
dispense with variables.

> Kirby
>
>
>
> On Sun, Apr 5, 2009 at 8:27 AM, John Posner <jjposner at snet.net> wrote:
>> kirby urner wrote:
>>>
>>> Excellente! kind sir.
>>>
>>
>> Here's a Python solution from Kay Schluehr on python-list. I've
>> pretty-printed it, sort of. If the line endings get garbled, just look for
>> the backslashes:
>>
>> g = (lambda primes = []: \
>>       (n for n in count(2) if \
>>           (lambda n, primes: \
>>               (n in primes if (primes and n<=primes[-1]) \
>>                            else (primes.append(n) or True if all(n%p for p
>> in primes if p <= sqrt(n)) \
>>                                                           else False) \
>>               ) \
>>           )(n, primes) \
>>       ) \
>>   )()
>>
>> "g" is a generator, so get the values with g.next().


-- 
Silent Thunder (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) is my name
And Children are my nation.
The Cosmos is my dwelling place, The Truth my destination.
http://earthtreasury.net/ (Edward Mokurai Cherlin)


More information about the Edu-sig mailing list