Commit 75ff4b4e authored by Gautham Velchuru's avatar Gautham Velchuru
Browse files

racket lambdas

parent 7efffd97
......@@ -155,7 +155,19 @@ We can navigate these with car for first element, cdr for tail, cadr for head of
Structs in Racket, like objects in OOP, are pass-by-pointer -- so, (if they are mutable), we can set their fields
but when we reassign the original struct is unchanged.
Lambdas are good not only for delaying evaluation and implementing lexical closures, but
also because you can use them to do multiple things in a row. \\
Question: Write a function map-pairs that takes in a function and a list of kvpairs and mutates
the pairs such that the new value for each pair is the function applied to their original
(define (map-pairs f ls)
(if (null? ls)
((lambda () (set-kvpair-value! (car ls) (f (kvpair-value (car ls)))) (map-pairs f (cdr ls))))))
\subsection{Rules, facts, and goals}
A fact is a predicate, and a rule is an extension of a fact with added clauses:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment