I am pretty new with scheme and edwin and I have two questions (maybe observations?) 1 - When there is a block of code in the lecture with procedures referencing other procedures - does it matter which one is written first? Because it seems that it is always written that procedure A comes before procedure B in the code, even though procedure A is referencing procedure B. 2 - My next question is semi-related to the first: When you are defining a bunch of procedures that are all referencing eachother for some bigger "black box"-type procedure, IE the square root approximation procedure "s
It would seem I was cut-off: the last procedure defined gets evaluated and the rest dont - then I retype and evaluate the other procedures inidivdually and then it all works. Any ideas why?
1 - The order of definitions doesn't matter in Scheme. It matters in Clojure, sadly. The usual thinking process in Scheme goes like this: you define a function at a high level of abstraction. It uses a few lower level functions that need not even exist yet. You just practice "wishful thinking", pretending the lower level pieces are already defined. Next you define the lower level functions, similarly imagining that you already have all the more primitive functions, etc. 2 - Do you mean a list of local definitions inside another definition? In that case they don't exist in the global environment. You can call them from inside the outer procedure or from the local procedures. Your code listing would be helpful.
For example, I type in these lines of code - separated byb Ctrl-J to move to the next line, (define plus (lambda (a b) (+ a b))) (define minus (lambda (a b) (- a b))) (define times (lambda (a b) (* a b))) Then I type: Ctrl-X Ctrl-E and I get: ;Value: times and when I try to use one of teh procedures IE: (plus 2 2) I get ;Unbound variable: plus but if I use Ctrl-X Ctrl-E between the above definitions they all work out. is that expected is all Im askin
Yes, that is expected. You need Ctrl-X Ctrl-E after each definition. This key combination means "evaluate last s-expression". To evaluate all of them in one go, select the definitions, and press Ctrl-C Ctrl-R (means "evaluate region").
yes that is the key: evaluate last s-expression".
Join our real-time social learning platform and learn together with your friends!