scheme - What will I input in the interaction window with this program i search? sorry beginner -
i don't know how edit here in stack sorry this.. want larn should input in interaction window of scheme .. ty
#lang scheme (define sort #f) (define merge #f) (let () (define dosort (lambda (pred? ls n) (if (= n 1) (list (car ls)) (let ((i (quotient n 2))) (domerge pred? (dosort pred? ls i) (dosort pred? (list-tail ls i) (- n i))))))) (define domerge (lambda (pred? l1 l2) (cond ((null? l1) l2) ((null? l2) l1) ((pred? (car l2) (car l1)) (cons (car l2) (domerge pred? l1 (cdr l2)))) (else (cons (car l1) (domerge pred? (cdr l1) l2)))))) (set! sort (lambda (pred? l) (if (null? l) l (dosort pred? l (length l))))) (set! merge (lambda (pred? l1 l2) (domerge pred? l1 l2))))
what have here sorting procedure. unusual way of definition. in interactions area, come in
(sort < '(6 5 2 1)) '(1 2 4 6)
for example. need provide function compares 2 items of list. example:
(sort string>? '("c" "b" "a" "d")) ("d" "c" "b" "a")
scheme
No comments:
Post a Comment