<commit_before>;; Copyright (c) 2013 <NAME> <<EMAIL>>
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;;     http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.

;; File    : church.lfe
;; Author  : <NAME>
;; Purpose : Demonstrating church numerals from the lambda calculus

;; The code below was used to create the section of the user guide here:
;;    http://lfe.github.io/user-guide/recursion/5.html
;;
;; Here is some example usage:
;;
;; > (slurp '"church.lfe")
;; #(ok church)
;; > (zero)
;; #Fun<lfe_eval.10.53503600>
;; > (church->int1 (zero))
;; 0
;; > (church->int1 (three))
;; 3
;; > (church->int1 (five))
;; 5
;; > (church->int2 #'five/0)
;; 5
;; > (church->int2 (lambda () (get-church 25)))
;; 25

(defmodule church
  (export all))

(defun zero ()
  (lambda (s)
    (lambda (x) x)))

(defun one ()
  (lambda (s)
    (lambda (x)
      (funcall s x))))

(defun two ()
  (lambda (s)
    (lambda (x)
      (funcall s
        (funcall s x)))))

(defun three ()
  (lambda (s)
    (lambda (x)
      (funcall s
        (funcall s
          (funcall s x))))))

(defun four ()
  (lambda (s)
    (lambda (x)
      (funcall s
        (funcall s
          (funcall s
            (funcall s x)))))))

(defun five ()
  (get-church 5))

(defun int-successor (n)
  (+ n 1))

; converts a called church numeral to an integer, e.g.:
;   > (church->int1 (five))
(defun church->int1 (church-numeral)
  (funcall (funcall church-numeral #'int-successor/1) 0))

; converts a non-called church numeral to an integer, e.g.:
;   > (church->int2 #'five/0)
(defun church->int2 (church-numeral)
  (funcall (funcall (funcall church-numeral) #'int-successor/1) 0))

(defun church-successor (church-numeral)<commit_msg>Changed comments to docstrings.<commit_after>;; Copyright (c) 2013 <NAME> <<EMAIL>>
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;;     http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.

;; File    : church.lfe
;; Author  : <NAME>
;; Purpose : Demonstrating church numerals from the lambda calculus

;; The code below was used to create the section of the user guide here:
;;    http://lfe.github.io/user-guide/recursion/5.html
;;
;; Here is some example usage:
;;
;; > (slurp '"church.lfe")
;; #(ok church)
;; > (zero)
;; #Fun<lfe_eval.10.53503600>
;; > (church->int1 (zero))
;; 0
;; > (church->int1 (three))
;; 3
;; > (church->int1 (five))
;; 5
;; > (church->int2 #'five/0)
;; 5
;; > (church->int2 (lambda () (get-church 25)))
;; 25

(defmodule church
  (export all))

(defun zero ()
  (lambda (s)
    (lambda (x) x)))

(defun one ()
  (lambda (s)
    (lambda (x)
      (funcall s x))))

(defun two ()
  (lambda (s)
    (lambda (x)
      (funcall s
        (funcall s x)))))

(defun three ()
  (lambda (s)
    (lambda (x)
      (funcall s
        (funcall s
          (funcall s x))))))

(defun four ()
  (lambda (s)
    (lambda (x)
      (funcall s
        (funcall s
          (funcall s
            (funcall s x)))))))

(defun five ()
  (get-church 5))

(defun int-successor (n)
  (+ n 1))

(defun church->int1 (church-numeral)
  "Converts a called church numeral to an integer, e.g.:
     > (church->int1 (five))
  "
  (funcall (funcall church-numeral #'int-successor/1) 0))

(defun church->int2 (church-numeral)
  "Converts a non-called church numeral to an integer, e.g.:
     > (church->int2 #'five/0)
  "
  (funcall (funcall (funcall church-numeral) #'int-successor/1) 0))

(defun church-successor (church-numeral)
{'fraction_non_alphanumeric': 0.16096997690531178, 'fraction_numerical': 0.020323325635103928, 'mean_word_length': 3.1926427879961277, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5282307', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1485, 'n_words': 500}