Problem
I'm given a list of lists of symbols and asked to manipulate it in a certain way, which I've already done (found in the definitions section), I want to convert this code from helper functions to local.
Definitions
The lists that I'm dealing with have their first element as an identifier and the rest of the list be descriptions of the item. For example, (list 'candy 'sweet 'light 'packaged). Note that every element is a symbol and that each list can have an infinite number of descriptions.
Given a list of these lists, I was asked to make a list that has all the descriptions of all the items, without duplicates. Order does not matter.
Examples
Here's a list that I created:
(list
(list 'chips 'fresh 'crisp)
(list 'oranges 'fresh 'sweet 'cold 'heavy)
(list 'person 'tall)
(list 'computer 'new 'heavy))
It is supposed to output (list 'fresh 'crisp 'sweet 'cold 'heavy 'tall 'new). Note that 'fresh does not appear twice, neither does heavy.
Code
; Main function
(define (get-desc lst) (remove-desc (add-list lst)))
; Function to process each individual list
(define (add-list lst)
(cond [(empty? lst) empty]
[else (append (add-row (rest (first lst))) (add-list (rest lst)))]))
; Process a single list, not nested
(define (add-row lst)
(cond [(empty? lst) empty]
[else (cons (first lst) (add-row (rest lst)))]))
; Removes duplicates in a list
(define (remove-desc lst)
(cond [(empty? lst) empty]
[else (cons (first lst) (remove-desc (filter (lambda (x) (not (symbol=? (first lst) x))) lst)))]))
So the code does what it is supposed to do. But how would I convert the helper functions into local? It is my first time trying to use local and I'm not very familiar with it. Is it even possible to fit all this into one function?