Changeset 8734 in project
- Timestamp:
- 02/24/08 03:41:36 (12 years ago)
- Location:
- wiki
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
wiki/chicken-for-ruby-programmers
r8731 r8734 316 316 because when the {{(+ (add-up-to (sub1 x)) x)}} expression is 317 317 evaluated, the recursive call to {{add-up-to}} creates a new stack 318 frame so that when it returns the x can be added to the result. 318 frame so that when it returns the x can be added to the result. 319 320 [Note that this code will 'break' in Chicken too, but only for much 321 larger numbers. Although Chicken doesn't have an arbitrary stack 322 depth, if you try (add-up-to) on a large enough number, you'll use up 323 all your system memory before getting an answer. Read on for a better 324 way to write it.] 325 319 326 All Schemes know that when there is nothing that needs to be done 320 327 after a procedure returns, there is no point in returning to the 321 procedure that called it at all ,instead it can just return directly322 to the procedure that called the current procedure , so the call can323 be optimized to become a ''goto'', replacing the current stack frame :328 procedure that called it at all: instead it can just return directly 329 to the procedure that called the current procedure. So the call can 330 be optimized to become a ''goto'', replacing the current stack frame. 324 331 325 332 Ruby still can't handle it: … … 354 361 As you'll notice, this version is a lot faster in Chicken too because 355 362 it does not have to travel back through all those empty "stack 356 frames". You can also notice the difference when you remove the stop 357 condition and you look at your OS's process list. Then Chicken's 358 memory usage just keeps going up until it breaks because it can't 359 allocate any more. In the second example it will stay constant and 360 simply loop forever. 363 frames". In the first example, Chicken's memory usage increases upon 364 every recursion: for large numbers, it will break because it can't 365 allocate any more. But in the second example, memory usage will stay 366 constant and simply loop forever. 361 367 362 368 === Blocks -
wiki/orders
r753 r8734 4 4 5 5 There's no documentation about it right now. Sorry. :-( 6 7 == Dependencies 8 9 {{srfi-13}} 10 11 == Procedures 12 13 [procedure] (cmp-key cmp key) 14 15 Generates an ordering procedure that applies the 'key' proc to both 16 sort candidates, and compares the resulting keys using the 'cmp' 17 procedure. 18 19 E.g. to sort a list of integers based on their value modulo-10: 20 (sort my-numbers (cmp < (cut modulo <> 10))) 21 22 [procedure] (key-string< key) 23 24 Generates an ordering procedure that sorts strings using string< 25 (defined in SRFI-13). 26
Note: See TracChangeset
for help on using the changeset viewer.