TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why I Like PLT Scheme (2004)

36 点作者 rw大约 16 年前

2 条评论

d0mine大约 16 年前
The map definition that OP uses doesn't look like a pure tail-recursive one:<p><pre><code> ; map-kuro5hin : (X -&#62; Y) * (listof X) -&#62; (listof Y) ; http://www.kuro5hin.org/story/2004/3/17/93442/8657 (define (map-kuro5hin func a-list) (cond [(null? a-list) null] [else (cons (func (car a-list)) (map-kuro5hin func (cdr a-list)))])) </code></pre> In a simple substitution model it unwraps to:<p><pre><code> (define sq (lambda (x) (* x x))) (map-kuro5hin sq '(1 2 3)) (cons (sq 1) (map-kuro5hin sq '(2 3))) (cons (sq 1) (cons (sq 2) (map-kuro5hin sq '(3)))) (cons (sq 1) (cons (sq 2) (cons (sq 3) (map-kuro5hin sq '())))) (cons (sq 1) (cons (sq 2) (cons (sq 3) '()))) (cons (sq 1) (cons (sq 2) '(9))) (cons (sq 1) '(4 9)) '(1 4 9) </code></pre> In this model it uses stack to store the result list. Of cause an actual Scheme implementation might perform the calculation without using stack.<p>Here's a pure tail-recursive variant:<p><pre><code> ; make external definition to allow unwrapping demonstration (define (map-iter func lst result) (if (null? lst) result (map-iter func (cdr lst) (cons (func (car lst)) result)))) (define (map-tr func a-list) (map-iter func (reverse a-list) '())) </code></pre> That translates to:<p><pre><code> (map-tr sq '(1 2 3)) (map-iter sq (reverse '(1 2 3)) '()) (map-iter sq '(3 2 1) '()) (map-iter sq '(2 1) (cons (sq 3) '())) (map-iter sq '(1) (cons (sq 2) '(9))) (map-iter sq '() (cons (sq 1) '(4 9))) '(1 4 9)</code></pre>
gord大约 16 年前
I now think lisp variants like scheme, CL and arc allow you to write code that reflects how you think about the problem at hand, with much less boilerplate than C, C++ or Java. Performance is good enough, and the repl is a very effective RAD tool.<p>Ive heard the same about Python, ruby, ocaml, F#, Haskell etc. After years of C and C++, I just cant bring myself to use the 'end' keyword, which rules some of these out.<p>Im very impressed with plts mzscheme command shell. The docs are excellent and clever blog articles abound for scheme. It seems a good way to learn a lisp while getting real work done.<p>I do wish there was a #lang arc 'personality' to provide the Arc language from within plt itself - that would be my dream machine.
评论 #517912 未加载
评论 #517894 未加载