<commit_before>;;;; Example VL programs

;;; Adding 5 to 3

(let ((addn (lambda (n)
	      (lambda (x) (+ n x)))))
  (let ((add5 (addn (real 5))))
    (add5 (real 3))))

;;; Variations on IF

(if (< (real 3) (real 6))
    (real 4)
    (real 3))

(if (< 3 6)
    (real 4)
    (real 3))

;;; Doubling and squaring do not commute under composition

(let ((double (lambda (x) (+ x x)))
      (square (lambda (x) (* x x)))
      (compose (lambda (f g)
		 (lambda (x) (f (g x))))))
  (cons ((compose double square) (real 2))
	((compose square double) (real 2))))

;;; Cubing 3 if it's less than 20

(let ((cube (lambda (x) (* x (* x x)))))
  (let ((enlarge-upto (lambda (bound)
			(lambda (x)
			  (if (< x bound)
			      (cube x)
			      x)))))
    ((enlarge-upto (real 20)) (real 3))))

;;; Variations on destructuring

(let ((my-add (lambda (x y) (+ x y))))
  (my-add (real 3) (real 6)))

(let ((my-add (lambda (x y) (+ (real x) (real y)))))
  (my-add 3 6))

(let ((my-add (lambda (foo) (+ foo))))
  (my-add (cons (real 3) (real 6))))

(let ((my-add (lambda (foo) (+ foo))))
  (my-add (cons 3 (real 6))))

(let ((my-add (lambda (foo) (real (+ foo)))))
  (my-add 3 6))

(let ((delay-add (lambda (x y) (lambda () (+ x y)))))
  ((delay-add (real 3) (real 6))))

(let ((frobnicate (lambda (x) (real x))))
  (frobnicate 3))


;;; Factorial

(letrec ((fact (lambda (n)
		 (if (= n 1)
		     1
		     (* n (fact (- n 1)))))))
  (fact (real 5)))

;;; Factorial, with letrec manually macro expanded

(let ((Z (lambda (f)
	   ((lambda (x)
	      (f (lambda (y) ((x x) y))))
	    (lambda (x)
	      (f (lambda (y) ((x x) y))))))))
  (let ((fact (Z (lambda (fact)
		   (lambda (n)
		     (if (= n 1)
			 1
			 (* n (fact (- n 1)))))))))
    (fact (real 5))))

;;; Parity testing

(letrec ((even? (lambda (n)
		  (if (= n 0)
		      #t
		      (odd? (- n 1)))))
	 (odd? (lambda (n)
		 (if (= n 0)
		     #f
		     (even? (- n 1))))))
  (even? (real 5)))

;;; Counting to 10

(let loop ((count (real 0)))
  (if (< count 10)
      (loop (+ count 1))
      count))

(let loop ((count (real 10)))
  (if (< count 0)
      (+ (loop (- count 1)) 1)
      count))
<commit_msg>Right.  I should actually get my examples right.<commit_after>;;;; Example VL programs

;;; Adding 5 to 3

(let ((addn (lambda (n)
	      (lambda (x) (+ n x)))))
  (let ((add5 (addn (real 5))))
    (add5 (real 3))))

;;; Variations on IF

(if (< (real 3) (real 6))
    (real 4)
    (real 3))

(if (< 3 6)
    (real 4)
    (real 3))

;;; Doubling and squaring do not commute under composition

(let ((double (lambda (x) (+ x x)))
      (square (lambda (x) (* x x)))
      (compose (lambda (f g)
		 (lambda (x) (f (g x))))))
  (cons ((compose double square) (real 2))
	((compose square double) (real 2))))

;;; Cubing 3 if it's less than 20

(let ((cube (lambda (x) (* x (* x x)))))
  (let ((enlarge-upto (lambda (bound)
			(lambda (x)
			  (if (< x bound)
			      (cube x)
			      x)))))
    ((enlarge-upto (real 20)) (real 3))))

;;; Variations on destructuring

(let ((my-add (lambda (x y) (+ x y))))
  (my-add (real 3) (real 6)))

(let ((my-add (lambda (x y) (+ (real x) (real y)))))
  (my-add 3 6))

(let ((my-add (lambda (foo) (+ foo))))
  (my-add (cons (real 3) (real 6))))

(let ((my-add (lambda (foo) (+ foo))))
  (my-add (cons 3 (real 6))))

(let ((my-add (lambda (foo) (real (+ foo)))))
  (my-add 3 6))

(let ((delay-add (lambda (x y) (lambda () (+ x y)))))
  ((delay-add (real 3) (real 6))))

(let ((frobnicate (lambda (x) (real x))))
  (frobnicate 3))


;;; Factorial

(letrec ((fact (lambda (n)
		 (if (= n 1)
		     1
		     (* n (fact (- n 1)))))))
  (fact (real 5)))

;;; Factorial, with letrec manually macro expanded

(let ((Z (lambda (f)
	   ((lambda (x)
	      (f (lambda (y) ((x x) y))))
	    (lambda (x)
	      (f (lambda (y) ((x x) y))))))))
  (let ((fact (Z (lambda (fact)
		   (lambda (n)
		     (if (= n 1)
			 1
			 (* n (fact (- n 1)))))))))
    (fact (real 5))))

;;; Parity testing

(letrec ((even? (lambda (n)
		  (if (= n 0)
		      #t
		      (odd? (- n 1)))))
	 (odd? (lambda (n)
		 (if (= n 0)
		     #f
		     (even? (- n 1))))))
  (even? (real 5)))

;;; Counting to 10

(let loop ((count (real 0)))
  (if (< count 10)
      (loop (+ count 1))
      count))

(let loop ((count (real 10)))
  (if (> count 0)
      (+ (loop (- count 1)) 1)
      count))

{'fraction_non_alphanumeric': 0.23900529587842506, 'fraction_numerical': 0.02717015887635275, 'mean_word_length': 2.47242206235012, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1496569', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1701, 'n_words': 617}