1
votes

I am trying to implement a decision tree in Racket manually to see how it works. I have this structure:

(define-struct node
  (list : childs
        class attribute type ))

and my function:

(define tree-1 
  (node '((node null 'round 'yes null) (node null 'square 'yes null)) 'shape null null))

Basically I want a tree with 3 nodes as follow:

;;    shape
;;     / \
;; round square
   (yes)  (no)

"Yes" and "no" are representing the classes for each atribute.

I get the following error: node: expects 6 arguments, given 4: '((node null 'round 'yes null) (node null 'square 'yes null)) 'shape '() '() but my node should take 4 arguments so i do not see where the problem is.

1

1 Answers

0
votes

Your definition of node seems kind of odd:

(define-struct node
  (list : childs
        class attribute type ))

That defines a struct with 6 members: list, :, childs, class, attribute, and type.

That defines a node constructor that expects those 6 arguments, but you call the constructor with only 4 arguments:

(node '((node null 'round 'yes null) (node null 'square 'yes null))
      'shape null null))

I'm guessing you meant those to be the childs, class, attribute, and type.

When you take "list :" out of the struct definition, the next problem you'll run into is that you probably meant to be passing a list of two nodes as that first argument. Instead you're passing a list of two lists, each list containing the symbols node, and null, followed by a list (quote round) or (quote square), etc. All because of your use of the quote (') operator instead of quasiquote. Try this:

(node `(,(node null 'round 'yes null) ,(node null 'square 'yes null))
      'shape null null))