[plt-scheme] Re: Getting started with Scheme: How can I improve my code for generating prime numbers?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Aug 7 11:04:17 EDT 2009

You may have misinterpreted my email a bit.

If you learn to program well in PLT Scheme, you will learn MORE THAN  
if you just learn to program functionally in ANY OLD Scheme. Once  
again, PLT Scheme is to Scheme what Scheme is to LISP and Algol 60,  
its two acknowledged predecessor. Point blank:

  PLT Scheme is vastly more than Scheme.

Just in case this isn't clear, your primes example demonstrates this  
point more than anything else. For sheer elegance, you should build  
your solution as a two-module program:

  sieve.ss
  #lang lazy ;; the truly functional solution
  (provide take-n-primes)
  ... see old mail

  main.ss
  #lang scheme
  (require "sieve.ss")
  ... now use the lazy stream in regular strict FP ...

NO OTHER LANGUAGE (Scheme or other FP or scripting or whatever) can  
provide this kind of mixed service. BEST OF ALL, the entire thing is  
still shorter than your Python program.

-- Matthias




On Aug 6, 2009, at 4:52 PM, SiWi wrote:

> Thank you for your hints and tips first of all. As I've been on
> holiday the last days, I had no internet access and couln't reply to
> your posts therefore.
>> Question is what is your goal?
>>   -- functional programming per se (as a philosopher, I would have to
>> question if it exists)
>>   -- Scheme programming in a functional way?
>>   -- Scheme programming in the 'best' possible way?
>>         -- best could mean 'fastest' (as you saw Eli's program is  
>> faster
>> than yours)
>>         -- best could mean 'suitable for proving theorems  
>> automatically'
>>         -- and many more things
>
> My goal is functional programming in genreral and Scheme programming
> in the 'best' way. I'd also be interested in where exactly the
> differences between 'best' Scheme programming( where 'best' would
> rever to a mixture between speed and idiomatic Scheme programming) and
> 'best' functional programming style can be found.
> On a sidenote, I want to use the primes code to try out a few project
> euler problems with Scheme to get started with the language.
> Therefore speed matters a bit, but of course it should not be the
> world's most efficient prime numbers generator. :)
>> So the last question is:
>>   -- perhaps you really want to learn to program in PLT Scheme so
>> that you can see what
>>        elegant lazy functional programmers do,
>>        strict lazy programmers,
>>        OO programmers,
>>        logic programmers,
>>        and imperative programmers
>> without ever leaving the language.
>
> My main goal is to learn something new, not only PLT-Schme, but also
> about programming styles in general.
> Therefore I want to learn coding in Scheme in general, but I'm also
> interested in strict lazy and logic programming.
> I've done enough OO and imperative programming in other languages so
> I'm not really interested in that at the moment, although I would like
> to learn about this in Scheme as well.
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.