Talk:Scheme (programming language): Difference between revisions

Content deleted Content added
Yobot (talk | contribs)
m Banner clean up using AWB (8434)
Sokleidas (talk | contribs)
Line 109:
 
Theres a statement in the wording that SCHEME is the easiest language of comparable power to implement. Is this REALLY true? I've seen some DAMN slim versions of Forth, and although it was never as fashionable for its stack-y ways, it was always a pretty expressive language and surprisingly capable for the kind of metaprogramming the lisps where known for. [[Special:Contributions/121.45.251.215|121.45.251.215]] ([[User talk:121.45.251.215|talk]]) 12:07, 9 October 2011 (UTC)
 
== The Hofstaedter example ==
 
IMHO the Hofstaedter example looks a bit ugly and seems not to be very scheme-like (besides <code>letrec</code> of course). It evaluates to #f and depends mostly on the side effects of <code>display</code>. Wouldn’t it be more appropiate if it evaluated e. g. to a list of pairs <code>(female male)</code> like this:
 
<syntaxhighlight lang="Scheme">
(define (hofstaedter-male-female n)
(letrec ((female (lambda (n)
(if (= n 0)
1
(- n (male (female (- n 1)))))))
(male (lambda (n)
(if (= n 0)
0
(- n (female (male (- n 1))))))))
(let loop ((i 0))
(if (> i n)
'()
(cons (cons (female i)
(male i))
(loop (+ i 1)))))))
 
(hofstaedter-male-female 8)
==> ((1 0) (1 0) (2 1) (2 2) (3 2) (3 3) (4 4) (5 4) (5 5))
</syntaxhighlight>
[[User:Sokleidas|Sokleidas]] ([[User talk:Sokleidas|talk]]) 21:53, 7 November 2012 (UTC)