sicp-ex-4.23



<< Previous exercise (4.22) | Index | Next exercise (4.24) >>


meteorgan

  
  
 In Alyssa's analyze-sequence, execute-sequence is running in runtime. But the solution in the text unrolls this procedure.  for example: for  ((lambda (x) (+ x 1)) 1), 
 Alyssa's analyze-sequence is (lambda (env) (execute-sequence (lambda ...) env)), 
 analyze-sequence in text is (lambda (env) ((lambda ...) env)). 

SophiaG

  
 This finally seems to be at least a vague reference to interpreters as iterating down a tree structure. It seems pretty clear from comparison that the version of analyze-sequence presented in the text cdrs down *two* branches of a procedure's environment for every run through its "loop" procedure, whereas Alyssa's only cdrs to the end of one possible sequence and executes. Thus its efficiency gains over the original eval grow quadratically with the complexity of the procedure it analyzes.  
  

poly

I think the Alyssa's version is less efficient than the text's when there are function calls. In the text's version, the analyze-sequence will return a lambda procedure like

 (lambda (env) 
     ((lambda (env) (proc1 env) (proc2 env)) 
      env) 
     (proc3 env)) 

It's already sequentialized. When it is applied to a env argument, it will apply all the procs to the env.

In the Alyssa's version, the result would be like

 (lambda (env (executive-sequence procs env))) 

The sequential procedure is inside of the executive-sequence, which means there will be extra work whenever there is a function call.