Logo

Programming-Idioms

History of Idiom 28 > diff from v70 to v71

Edit summary for version 71 by srcreigh:
[Scheme] The name formatting doesn't work for punctuation names like <

Version 70

2021-08-15, 23:32:58

Version 71

2021-08-15, 23:33:38

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Variables
items,x,p
Variables
items,x,p
Code
(define-struct item (p x y) #:transparent)
(define items (list (item 1 2 3) (item 0 0 0) (item 5 2 1)))
(sort items < #:key item-p)
Code
(define-struct item (p x y) #:transparent)
(define items (list (item 1 2 3) (item 0 0 0) (item 5 2 1)))
(sort items < #:key item-p)
Comments bubble
_< is the integer comparison function. There is also string<?.
Comments bubble
< is the integer comparison function. There is also string<?.
Doc URL
https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._sort%29%29
Doc URL
https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._sort%29%29