I have a scheme project with which I want to make a dictionary without using 'dict' function. IO example:
(define d (make-dictionary)) ;; creates an empty dictionary
(define d1 (d (cons "a" 1))) ;;d1 is d+("a" 1), d not changing
(d1 "a") ;; = 1
(define d2 (d1 (cons "b" 15))) ;;d2 is d1+("b" 15), d1 not changing
(d2 "b") ;; = 15
(d2 "a") ;; = 1
I simply do not understand how I can get make-dictionary with parenthesis as an argument, it always returns a procedure rather than types the answer.
(define (make-dictionary)
'())
(define ( ( (make-dictionary) pairs) ) ;;trying to get it with parenthesis
append make-dictionary (cons pairs '()))
I know I've asking a lot of questions the past couple of days, but I am new to scheme and I am doing my best to learn it, but I'm running out of time.. HELP?
I guess you're trying to implement an association list. Sadly, what you're proposing to do with parentheses doesn't make sense, at all. A more sensible approach would be to have separate procedures for adding and retrieving key/value pairs:
Now, we'd use it like this: