chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Chicken for Python Programmers


From: John Cowan
Subject: Re: [Chicken-users] Chicken for Python Programmers
Date: Mon, 5 Jan 2009 19:06:17 -0500
User-agent: Mutt/1.5.13 (2006-08-11)

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"       address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]