<commit_before>(in-package :thierry-technologies.com/2011/07/lambda)

(defgeneric render (expression &key rightmost redex))

(defmethod render ((expression abstraction) &key (rightmost t) redex)
  (let ((rendering (format nil "λ~a.~a" (render (abs-var expression)) (render (abs-body expression) :redex redex))))
    (if rightmost rendering (format nil "(~a)" rendering))))

(defmethod render ((expression hidden-abstraction) &key rightmost redex)
  (hid-name expression))

(defmethod render ((expression variable) &key rightmost redex)
  (var-name expression))

(defmethod render ((expression application) &key (rightmost t) redex)
  (format nil (if (eq redex expression) "~a‸~a" "~a ~a")
	  (render (app-fun expression) :rightmost nil)
	  (let* ((arg (app-arg expression))
		 (arg-rendering (render arg :rightmost rightmost)))
	    (if (typep arg 'application)
		(format nil "(~a)" arg-rendering)
		arg-rendering))))

(defmethod print-object ((object expression) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (princ (render object) stream)))
<commit_msg>Corrected rendering to carry redex.<commit_after>(in-package :thierry-technologies.com/2011/07/lambda)

(defgeneric render (expression &key rightmost redex))

(defmethod render ((expression abstraction) &key (rightmost t) redex)
  (let ((rendering (format nil "λ~a.~a" (render (abs-var expression)) (render (abs-body expression) :redex redex))))
    (if rightmost rendering (format nil "(~a)" rendering))))

(defmethod render ((expression hidden-abstraction) &key rightmost redex)
  (hid-name expression))

(defmethod render ((expression variable) &key rightmost redex)
  (var-name expression))

(defmethod render ((expression application) &key (rightmost t) redex)
  (format nil (if (eq redex expression) "~a‸~a" "~a ~a")
	  (render (app-fun expression) :rightmost nil :redex redex)
	  (let* ((arg (app-arg expression))
		 (arg-rendering (render arg :rightmost rightmost :redex redex)))
	    (if (typep arg 'application)
		(format nil "(~a)" arg-rendering)
		arg-rendering))))

(defmethod print-object ((object expression) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (princ (render object) stream)))

{'fraction_non_alphanumeric': 0.14485559566787004, 'fraction_numerical': 0.005415162454873646, 'mean_word_length': 5.262711864406779, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7604731', 'n_tokens_mistral': 724, 'n_tokens_neox': 688, 'n_words': 228}