LISP SICP Video Lecture 2a Average Damp Question

The average-damp procedure takes a procedure as its argument and returns a procedure as its value. When given a procedure that takes one argument, average-damp returns another procedure that computes the average of the values before and after applying the original function f to its argument. It’s inside the fixed-point procedure where that returned function … Read more

Count occurrence of element in a list in Scheme?

In Racket, you could do But more seriously, doing this with lists in Scheme is much easier that what you mention. A list is either empty, or a pair holding the first item and the rest. Follow that definition in code and you’ll get it to “write itself out”. Here’s a hint for a start, … Read more

Scheme IDE for Windows

DrScheme is the best Scheme IDE I have found. It has a JIT compiler, can build stand-alone executables or run in the traditional Scheme REPL, has smart syntax editing , as well as other traditional IDE features like Menu bars to change features. Running/stopping your program is as easy as clicking ‘Run’/’Stop’. It also includes a macro-expander … Read more

Scheme console printing

Printing in Scheme works by calling display (and possibly, newline). Since you want to call it sequentially before/after something else (which, in a functional (or in the case of Scheme, functional-ish) language only makes sense for the called functions side-effects), you would normally need to use begin, which evaluates its arguments in turn and then returns the value of … Read more

Help explaining how `cons` in Scheme work?

cons build pairs, not lists. Lisp interpreters uses a ‘dot’ to visually separate the elements in the pair. So (cons 1 2) will print (1 . 2). car and cdr respectively return the first and second elements of a pair. Lists are built on top of pairs. If the cdr of a pair points to another pair, that sequence is treated as a list. The cdr of … Read more

What is the difference between map and apply in scheme?

They are not the same! Their names can actually help remember which does what. map will take as argument one procedure and one or more lists. The procedure will be called once for each position of the lists, using as arguments the list of elements at that position: map called (- 2), (- 3), (- … Read more

In Scheme, what’s the point of “set!”?

Though both define and set! will redefine a value when in the same scope, they do two different things when the scope is different. Here’s an example: As you can see, when we create a new lexical scope (such as when we define a function), any names defined within that scope mask the names that … Read more

if else construction

There are several errors in your code. And you should use a cond when dealing with multiple conditions (think of it as a series of IF/ELSE IF/…/ELSE statements). Be aware that the expression (and (> x 1) (= x 1)) will never be true, as x is either greater than or equal to 1, both … Read more

tech