Jack Trades scripsit: > After noticing "Chicken for blub programmers" on the wiki some months ago, I > decided a good way to learn Scheme would be to produce a similar document.
Great work! Just a few notes: Altering a character in a *literal* string is never a good idea in any language; if you must demonstrate string-set!, use one constructed with the make-string or string procedures. Some Schemes disallow string-set! if they know the string is literal. "In Scheme all functions are lambdas": but they don't have the restrictions of Python lambdas. Nested functions: note that Scheme can do internal defines. Unfortunately, hash tables in Chicken aren't very efficient yet: in small examples, a-lists are better. SRFI-1 provides append!, but note that you must capture the return values of destructive (!) list functions; you can't just rely on the side effects. There is no guarantee that append! will actually side-effect its arguments; you are just permitting it to do so. One way to do a LIST-SET! operation is: (define (list-set! list index new) (set-car! (drop list index) new)) This works because the result of drop is guaranteed to share storage with the original list. Similarly, list-insert! is: (define (list-insert! list index new) (append (take list index) (list new) (drop list index))) To reverse in place when possible, use reverse!, but note that you must capture the result: (set! r (reverse! r)) Ditto with sort!. List-copy makes a shallow copy of a list. Here's a tree-copy function: (define (tree-copy x) (if (pair? x) (cons (tree-copy (car x)) (tree-copy (cdr x))) x)) -- Deshil Holles eamus. Deshil Holles eamus. Deshil Holles eamus. Send us, bright one, light one, Horhorn, quickening, and wombfruit. (3x) Hoopsa, boyaboy, hoopsa! Hoopsa, boyaboy, hoopsa! Hoopsa, boyaboy, hoopsa! --Joyce, Ulysses, "Oxen of the Sun" [email protected] _______________________________________________ Chicken-users mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/chicken-users
