Answering the question of how to pass parameters in Racket - just declare them after the function's name, and be careful with the parentheses (there are several erroneous parentheses in your code). I believe you were aiming for something like this:
(define (throw-value dice-rolls)
(list (list-sum dice-rolls) (car dice-rolls) (car dice-rolls)))
The above will return a list in the format (sum num1 num2)
, be aware that num1
and num2
will be the same number, because in both cases you're taking the first element of the list. Now, for the rest of the question - in Racket, a direct translation of the C code in the question will look like this:
(define (function vec)
(printf "~a total has been rolled from rolls ~a and ~a.~n"
(vector-ref vec 0)
(vector-ref vec 1)
(vector-ref vec 2)))
(define vec (vector 1 2 3)) ; `vec` is a vector
(function vec)
=> 1 total has been rolled from rolls 2 and 3.
Although the linked list is the standard data structure in Lisp-based programming languages, whenever you need to efficiently access data given an index it's better to use a vector as shown above. If for some reason you really have to use a list you can do so, albeit less efficiently (linked lists are not optimized for index-based access):
(define (function lst)
(printf "~a total has been rolled from rolls ~a and ~a.~n"
(list-ref lst 0)
(list-ref lst 1)
(list-ref lst 2)))
(define lst (list 1 2 3)) ; `lst` is a singly-linked list
(function lst)
=> 1 total has been rolled from rolls 2 and 3.