Logo

Programming-Idioms

History of Idiom 5 > diff from v361 to v362

Edit summary for version 362 by Dodopod:
[Scheme] make-X is the standard name for a factory function.

Version 361

2017-06-06, 15:09:03

Version 362

2017-06-06, 15:14:10

Idiom #5 Create a 2D Point data structure

Declare a container type for two floating-point numbers x and y

Illustration

Idiom #5 Create a 2D Point data structure

Declare a container type for two floating-point numbers x and y

Illustration
Code
(define (create-point x y)
  (cons x y))
(define (point-x p)
  (car p))
(define (point-y p)
  (cdr p))
Code
(define (make-point x y)
  (cons x y))
(define (point-x p)
  (car p))
(define (point-y p)
  (cdr p))