I will use a simple example to illustrate my question. In Java, C, or any other OOP language, I could create a class piein the same way:
class Apple{
public String flavor;
public int pieces;
private int tastiness;
public goodness(){
return tastiness*pieces;
}
}
What is the best way to do this with Scheme? I suppose I could do something like this:
(define make-pie
(lambda (flavor pieces tastiness)
(list flavor pieces tastiness)))
(define pie-goodness
(lambda (pie)
(* (list-ref pie 1) (list-ref pie 2))))
(pie-goodness (make-pie 'cherry 2 5))
;output: 10
... where cherries are aromas, 2 are slices, and 5 is good. However, then there is no security or type visibility, and everything is simply stuffed into the unlabeled list. How can I improve this?
Sidenote: make-pie 3 . , (, , Java C), ( - , ) ?
:
/, . , .
, , , , , pie , , .