Question

USING SCHEME:

I am working on a question in my assignment that asks the follows:

A toy data structure specifies the name of a toy, a description, the acquisition price, and the recommended sales price. Create constructors and accessors for the toy structure, ensuring that you do not use Racket’s builtin structs [1 marks]. Using only your accessors to get at the data in your structure, define a function that sorts a list of toy structures by the difference between the two prices [2 marks].

Is the question asking to create my own toy data structure with constructors that has the name of the toy,description, and acquisition price and accessors to get the variables of toy like name or description?

if so, how do i do this?

is there a keyword like struct in scheme?

Was it helpful?

Solution

Is the question asking to create my own toy data structure with constructors that has the name of the toy,description, and acquisition price and accessors to get the variables of toy like name or description? if so, how do i do this?

Yes, that's exactly what the assignment says. Hint: a simple list will do, store each field in a position and the accessors will return the element at the position. For instance, if we store the name in the first position, then the accessor will return the car of the list, and so on.

Is there a keyword like struct in scheme?

Yes, oddly enough in Racket is called struct (it's a macro, not a keyword). Also in R7RS (or in SRFI-9) we have record types. But the assignment specifically states that you must not use this!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top