[e-lang] Comments on SICP in E code

Chris Rathman Chris.Rathman at tx.rr.com
Fri Dec 29 00:06:15 CST 2006


Kevin Reid wrote:
> My comments on the code at
>
>    <http://www.codepoetics.com/wiki/index.php? 
> title=Topics:SICP_in_other_languages:E:Chapter_2>
>
> . I've also made the changes that I think are appropriate and don't  
> guess are against the purpose of the code.
>   

Thanks for the feedback!  I used many of your suggestions.  Spent some 
time reformatting various things as well.

> This sort of code can also be written in more functional style:
>
> def gcd(a, b) {
>     return if (b == 0) {
>               a
>            } else {
>               gcd(b, a % b)
>            }
> }
>
> or
>
> def gcd(a, b) {
>     return if (b == 0) {
>        a
>     } else {
>        gcd(b, a % b)
>     }
> }
>
> or
>
> def gcd := fn a, b { if (b == 0) {
>                          a
>                       } else {
>                          gcd(b, a % b)
>                       }
>                     }
>
>   

I'm kind of split here.  The style here is more in line with Scheme/ML.  
But I think more programmers will identify with the Python/Ruby style 
that I started with.  I did make a note in chapter one where the if 
statement was introduced in the abs function and where lambdas were 
introduced later.

> Also, this function would be better written with patterns:
>
> def islist(xs) {
>     return switch (xs) {
>        match ==nil    { true }
>        match [_, cdr] { islist(cdr) }
>        match _        { false }
>     }
> }
>   
This implementation is the one that I think captures it best.

Thanks,
Chris Rathman


\


More information about the e-lang mailing list