Skip to content

Commit 5807d1c

Browse files
committed
Add support for the Emacs Lisp programming language
1 parent 3025a53 commit 5807d1c

10 files changed

Lines changed: 754 additions & 0 deletions

‎dataset_builder/humaneval_to_el.py‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
This script translates problems from the OpenAI HumanEval dataset into Emacs Lisp.
3+
4+
- Home: https://www.gnu.org/software/emacs/
5+
- Reference manual: https://www.gnu.org/software/emacs/manual/elisp.html
6+
- Test library: https://www.gnu.org/software/emacs/manual/ert.html
7+
"""
8+
9+
import ast
10+
from typing import List
11+
12+
13+
class Translator:
14+
15+
USub = "-"
16+
17+
stop = ["\n(defun", "\n;", "\n("]
18+
19+
def file_ext(self):
20+
return "el"
21+
22+
def translate_prompt(
23+
self, name: str, args: List[ast.arg], _returns, description: str
24+
) -> str:
25+
self.entry_point = name
26+
el_preamble = ";;; -*- lexical-binding: t; -*-"
27+
el_args = " ".join(arg.arg for arg in args)
28+
el_description = description.replace('"', '\\"')
29+
return f'{el_preamble}\n(defun {name} ({el_args})\n "{el_description}"\n '
30+
31+
def test_suite_prefix_lines(self, entry_point) -> List[str]:
32+
return [
33+
f"(defalias #'candidate #'{entry_point})",
34+
"(ert-deftest test-human-eval ()",
35+
]
36+
37+
def test_suite_suffix_lines(self) -> List[str]:
38+
return [")"]
39+
40+
def deep_equality(self, left: str, right: str) -> str:
41+
return f" (should (equal {left} {right}))"
42+
43+
def gen_literal(self, c: bool | str | int | float):
44+
if type(c) is bool:
45+
return "t" if c else "nil"
46+
elif type(c) is str:
47+
return f'"{c}"'
48+
elif c is None:
49+
return "nil"
50+
return repr(c)
51+
52+
def gen_var(self, variable: str) -> str:
53+
return variable
54+
55+
def gen_list(self, list: List[str]) -> str:
56+
return "(list " + " ".join(list) + ")"
57+
58+
def gen_tuple(self, tuple: List[str]) -> str:
59+
return "(list " + " ".join(tuple) + ")"
60+
61+
def gen_dict(self, keys: List[str], values: List[str]) -> str:
62+
pairs = " ".join(f"(cons {k} {v})" for k, v in zip(keys, values))
63+
return "(list " + pairs + ")"
64+
65+
def gen_call(self, func: str, args: List[str]) -> str:
66+
return "(" + func + " " + " ".join(args) + ")"

‎dataset_builder/libexperiments.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def path(self) -> Path:
4242
"elixir",
4343
"clj",
4444
"ada",
45+
"el",
4546
]
4647
MODELS = ["davinci", "incoder", "codegen"]
4748

‎dataset_builder/terms.csv‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ Matlab,m,array,array,array,dictionary,<missing>,true,false
2626
Haskell,hs,list,list,tuple,association list,Nothing,True,False
2727
Clojure,clj,vector,list,vector,map,nil,true,false
2828
Dart,dart,list,list,record,map,null,true,false
29+
Emacs Lisp,el,list,list,list,alist,nil,t,nil

‎evaluation/Dockerfile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ RUN apt-get update -yqq && apt-get install -yqq dart
106106
# Lean
107107
# RUN wget https://github.com/leanprover/lean4/releases/download/v4.6.0-rc1/lean-4.6.0-rc1-linux.zip -O /tmp/lean.zip && unzip /tmp/lean.zip -d /root/lean/ && ln -s /root/lean/bin/lean /bin/lean
108108

109+
# Emacs Lisp (no-X/GUI version)
110+
RUN apt install -y emacs-nox
111+
109112
# install numpy for humanevalplus
110113
RUN python3 -m pip install numpy
111114

‎evaluation/src/containerized_eval.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import eval_v
3030
import eval_lean
3131
import eval_dart
32+
import eval_el
3233
import tempfile
3334

3435

@@ -65,6 +66,7 @@
6566
"coq": (eval_v.eval_script, ".v"),
6667
"lean": (eval_lean.eval_script, ".lean"),
6768
"dart": (eval_dart.eval_script, ".dart"),
69+
"el": (eval_el.eval_script, ".el"),
6870
}
6971

7072
def eval_string_script(language, program):

‎evaluation/src/eval_el.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Evaluates a generated Emacs Lisp program (.el).
3+
"""
4+
from pathlib import Path
5+
from safe_subprocess import run
6+
7+
def eval_script(path: Path):
8+
9+
result = run([
10+
"emacs", "-batch",
11+
"-l", "ert",
12+
"-l", str(path),
13+
"-f", "ert-run-tests-batch-and-exit"
14+
])
15+
16+
if result.timeout:
17+
status = "Timeout"
18+
elif result.exit_code != 0:
19+
status = "Exception"
20+
elif "\nRan 1 tests, 1 results as expected, 0 unexpected" in result.stderr:
21+
status = "OK"
22+
else: # test failure
23+
status = "Exception"
24+
25+
return {
26+
"status": status,
27+
"exit_code": result.exit_code,
28+
"stdout": result.stdout,
29+
"stderr": result.stderr,
30+
}
31+
32+
if __name__ == "__main__":
33+
main()
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
problem,pass,total
2+
HumanEval_0_has_close_elements,3,200
3+
HumanEval_1_separate_paren_groups,0,200
4+
HumanEval_10_make_palindrome,0,200
5+
HumanEval_100_make_a_pile,4,200
6+
HumanEval_101_words_string,0,200
7+
HumanEval_102_choose_num,0,200
8+
HumanEval_103_rounded_avg,0,200
9+
HumanEval_104_unique_digits,0,200
10+
HumanEval_105_by_length,14,200
11+
HumanEval_106_f,0,200
12+
HumanEval_107_even_odd_palindrome,0,200
13+
HumanEval_108_count_nums,0,200
14+
HumanEval_109_move_one_ball,0,200
15+
HumanEval_11_string_xor,179,200
16+
HumanEval_110_exchange,0,200
17+
HumanEval_111_histogram,0,200
18+
HumanEval_112_reverse_delete,0,200
19+
HumanEval_113_odd_count,0,200
20+
HumanEval_114_minSubArraySum,25,200
21+
HumanEval_115_max_fill,1,200
22+
HumanEval_116_sort_array,0,200
23+
HumanEval_117_select_words,5,200
24+
HumanEval_118_get_closest_vowel,0,200
25+
HumanEval_119_match_parens,0,200
26+
HumanEval_12_longest,188,200
27+
HumanEval_120_maximum,2,200
28+
HumanEval_121_solution,0,200
29+
HumanEval_122_add_elements,61,200
30+
HumanEval_123_get_odd_collatz,0,200
31+
HumanEval_124_valid_date,19,200
32+
HumanEval_125_split_words,0,200
33+
HumanEval_126_is_sorted,0,200
34+
HumanEval_127_intersection,0,200
35+
HumanEval_128_prod_signs,145,200
36+
HumanEval_129_minPath,0,200
37+
HumanEval_13_greatest_common_divisor,200,200
38+
HumanEval_130_tri,0,200
39+
HumanEval_131_digits,0,200
40+
HumanEval_132_is_nested,0,200
41+
HumanEval_133_sum_squares,99,200
42+
HumanEval_134_check_if_last_char_is_a_letter,0,200
43+
HumanEval_135_can_arrange,11,200
44+
HumanEval_136_largest_smallest_integers,74,200
45+
HumanEval_137_compare_one,1,200
46+
HumanEval_138_is_equal_to_sum_even,0,200
47+
HumanEval_139_special_factorial,0,200
48+
HumanEval_14_all_prefixes,8,200
49+
HumanEval_140_fix_spaces,0,200
50+
HumanEval_141_file_name_check,0,200
51+
HumanEval_142_sum_squares,0,200
52+
HumanEval_143_words_in_sentence,0,200
53+
HumanEval_144_simplify,44,200
54+
HumanEval_145_order_by_points,0,200
55+
HumanEval_146_specialFilter,0,200
56+
HumanEval_147_get_max_triples,17,200
57+
HumanEval_148_bf,0,200
58+
HumanEval_149_sorted_list_sum,0,200
59+
HumanEval_15_string_sequence,200,200
60+
HumanEval_150_x_or_y,0,200
61+
HumanEval_151_double_the_difference,0,200
62+
HumanEval_152_compare,61,200
63+
HumanEval_153_Strongest_Extension,0,200
64+
HumanEval_154_cycpattern_check,0,200
65+
HumanEval_155_even_odd_count,0,200
66+
HumanEval_156_int_to_mini_roman,71,200
67+
HumanEval_157_right_angle_triangle,187,200
68+
HumanEval_158_find_max,20,200
69+
HumanEval_159_eat,175,200
70+
HumanEval_16_count_distinct_characters,13,200
71+
HumanEval_160_do_algebra,0,200
72+
HumanEval_161_solve,0,200
73+
HumanEval_162_string_to_md5,86,200
74+
HumanEval_163_generate_integers,0,200
75+
HumanEval_17_parse_music,0,200
76+
HumanEval_18_how_many_times,0,200
77+
HumanEval_19_sort_numbers,2,200
78+
HumanEval_2_truncate_number,190,200
79+
HumanEval_20_find_closest_elements,5,200
80+
HumanEval_21_rescale_to_unit,200,200
81+
HumanEval_22_filter_integers,179,200
82+
HumanEval_23_strlen,200,200
83+
HumanEval_24_largest_divisor,35,200
84+
HumanEval_25_factorize,38,200
85+
HumanEval_26_remove_duplicates,3,200
86+
HumanEval_27_flip_case,0,200
87+
HumanEval_28_concatenate,200,200
88+
HumanEval_29_filter_by_prefix,200,200
89+
HumanEval_3_below_zero,0,200
90+
HumanEval_30_get_positive,137,200
91+
HumanEval_31_is_prime,103,200
92+
HumanEval_33_sort_third,0,200
93+
HumanEval_34_unique,157,200
94+
HumanEval_35_max_element,182,200
95+
HumanEval_36_fizz_buzz,105,200
96+
HumanEval_37_sort_even,0,200
97+
HumanEval_39_prime_fib,0,200
98+
HumanEval_4_mean_absolute_deviation,85,200
99+
HumanEval_40_triples_sum_to_zero,0,200
100+
HumanEval_41_car_race_collision,0,200
101+
HumanEval_42_incr_list,200,200
102+
HumanEval_43_pairs_sum_to_zero,21,200
103+
HumanEval_44_change_base,199,200
104+
HumanEval_45_triangle_area,142,200
105+
HumanEval_46_fib4,12,200
106+
HumanEval_47_median,0,200
107+
HumanEval_48_is_palindrome,106,200
108+
HumanEval_49_modp,12,200
109+
HumanEval_5_intersperse,143,200
110+
HumanEval_51_remove_vowels,65,200
111+
HumanEval_52_below_threshold,0,200
112+
HumanEval_53_add,200,200
113+
HumanEval_54_same_chars,0,200
114+
HumanEval_55_fib,180,200
115+
HumanEval_56_correct_bracketing,0,200
116+
HumanEval_57_monotonic,6,200
117+
HumanEval_58_common,73,200
118+
HumanEval_59_largest_prime_factor,19,200
119+
HumanEval_6_parse_nested_parens,14,200
120+
HumanEval_60_sum_to_n,200,200
121+
HumanEval_61_correct_bracketing,0,200
122+
HumanEval_62_derivative,98,200
123+
HumanEval_63_fibfib,136,200
124+
HumanEval_64_vowels_count,0,200
125+
HumanEval_65_circular_shift,48,200
126+
HumanEval_66_digitSum,0,200
127+
HumanEval_67_fruit_distribution,6,200
128+
HumanEval_68_pluck,0,200
129+
HumanEval_69_search,187,200
130+
HumanEval_7_filter_by_substring,135,200
131+
HumanEval_70_strange_sort_list,15,200
132+
HumanEval_71_triangle_area,0,200
133+
HumanEval_72_will_it_fly,160,200
134+
HumanEval_73_smallest_change,190,200
135+
HumanEval_74_total_match,20,200
136+
HumanEval_75_is_multiply_prime,9,200
137+
HumanEval_76_is_simple_power,111,200
138+
HumanEval_77_iscube,1,200
139+
HumanEval_78_hex_key,22,200
140+
HumanEval_79_decimal_to_binary,0,200
141+
HumanEval_8_sum_product,200,200
142+
HumanEval_80_is_happy,4,200
143+
HumanEval_81_numerical_letter_grade,102,200
144+
HumanEval_82_prime_length,0,200
145+
HumanEval_83_starts_one_ends,0,200
146+
HumanEval_84_solve,0,200
147+
HumanEval_85_add,0,200
148+
HumanEval_86_anti_shuffle,47,200
149+
HumanEval_87_get_row,84,200
150+
HumanEval_88_sort_array,0,200
151+
HumanEval_89_encrypt,0,200
152+
HumanEval_9_rolling_max,71,200
153+
HumanEval_90_next_smallest,2,200
154+
HumanEval_91_is_bored,0,200
155+
HumanEval_92_any_int,195,200
156+
HumanEval_93_encode,0,200
157+
HumanEval_94_skjkasdkd,0,200
158+
HumanEval_95_check_dict_case,0,200
159+
HumanEval_96_count_up_to,0,200
160+
HumanEval_97_multiply,200,200
161+
HumanEval_98_count_upper,3,200
162+
HumanEval_99_closest_integer,1,200

0 commit comments

Comments
 (0)