unicode as valid naming symbols
Marko Rauhamaa
marko at pacujo.net
Tue Apr 1 08:02:29 EDT 2014
Ian Kelly <ian.g.kelly at gmail.com>:
> Setting aside the fact that C doesn't have anonymous functions, I'll
> approximate it as best I can:
>
> [...]
>
> C: 10
> Scheme: 20
It is true that scheme needs parentheses for operators and assignments
so the ratio is probably in the order of 2:1. Whether that is excess or
not is a matter of taste.
For example:
========================================================================
#include<stdio.h>
int main()
{
int n, i = 3, count, c;
printf("Enter the number of prime numbers required\n");
scanf("%d",&n);
if ( n >= 1 )
{
printf("First %d prime numbers are :\n",n);
printf("2\n");
}
for ( count = 2 ; count <= n ; )
{
for ( c = 2 ; c <= i - 1 ; c++ )
{
if ( i%c == 0 )
break;
}
if ( c == i )
{
printf("%d\n",i);
count++;
}
i++;
}
return 0;
}
========================================================================
(<URL: http://www.programmingsimplified.com/c/source-code/
c-program-for-prime-number>)
is rendered in scheme as follows:
========================================================================
(define (main)
(format #t "Enter the number of prime numbers required\n")
(let ((n (read)))
(if (>= n 1)
(begin
(format #t "First ~S prime numbers are :\n" n)
(format #t "2\n")))
(let display-primes ((count 2) (i 3))
(if (<= count n)
(let find-divisor ((c 2))
(cond
((= c i)
(format #t "~S\n" i)
(display-primes (1+ count) (1+ i)))
((= (remainder i c) 0)
(display-primes count (1+ i)))
(else
(find-divisor (1+ c)))))))))
(main)
========================================================================
The scheme translation has 37 parenthesis pairs, while the C version has
16. Which one is easier on the eye?
Marko
More information about the Python-list
mailing list