Skip to content

Commit 9e19574

Browse files
rudolf-adamkovicclaude
authored andcommitted
Add support for the Tcl programming language
Based on PR #187. Creates a language-specific Tcl.dockerfile instead of modifying the main Dockerfile. Tested with claude-haiku-4-5 on HumanEval (1 completion, temperature 0.2): pass@1 = 84.5%. Co-Authored-By: Rudolf Adamkovic <rudolf@adamkovic.org> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 42c1f11 commit 9e19574

6 files changed

Lines changed: 99 additions & 1 deletion

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# This script translates problems from the OpenAI HumanEval dataset into Tcl.
2+
import re
3+
import ast
4+
from typing import List
5+
6+
7+
class Translator:
8+
9+
stop = ["\nproc ", "\n#", "\n\n"]
10+
11+
def file_ext(self):
12+
return "tcl"
13+
14+
def translate_prompt(self, name: str, args: List[ast.arg], _returns, description: str):
15+
tcl_description = (
16+
"# " + re.sub(r"\n(\s*)", "\n# ", description.strip()) + "\n" if description else ""
17+
)
18+
arg_names = [arg.arg for arg in args]
19+
arg_list = " ".join(arg_names)
20+
return f"{tcl_description}proc {name} {{{arg_list}}} {{\n"
21+
22+
def test_suite_prefix_lines(self, entry_point: str) -> List[str]:
23+
return [
24+
"",
25+
"proc assert_equal {actual expected} {",
26+
" if {$actual ne $expected} {",
27+
" error \"Expected: $expected | Actual: $actual\"",
28+
" }",
29+
"}",
30+
"",
31+
f"interp alias {{}} candidate {{}} {entry_point}",
32+
"",
33+
]
34+
35+
def test_suite_suffix_lines(self) -> List[str]:
36+
return []
37+
38+
def deep_equality(self, left: str, right: str) -> str:
39+
return f"assert_equal {left} {right}"
40+
41+
def gen_literal(self, c: bool | str | int | float | None):
42+
if type(c) == bool:
43+
return str(c).lower()
44+
elif type(c) == str:
45+
escaped = c.replace("\\", "\\\\").replace('"', '\\"').replace("$", "\\$").replace("[", "\\[").replace("\n", "\\n")
46+
return f'"{escaped}"'
47+
elif c is None:
48+
return '""'
49+
return repr(c)
50+
51+
def gen_var(self, v: str):
52+
return v
53+
54+
def gen_list(self, l: List[str]):
55+
return "[list " + " ".join(l) + "]"
56+
57+
def gen_tuple(self, t: List[str]):
58+
return "[list " + " ".join(t) + "]"
59+
60+
def gen_dict(self, keys: List[str], values: List[str]):
61+
pairs = " ".join(f"{k} {v}" for k, v in zip(keys, values))
62+
return "[dict create " + pairs + "]"
63+
64+
def gen_call(self, func: str, args: List[str]):
65+
return "[" + func + " " + " ".join(args) + "]"
66+
67+
def no_completion_prompt_stub(self):
68+
return " return 0\n}\n"

dataset_builder/terms.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ Clojure,clj,vector,list,vector,map,nil,true,false
2828
Dart,dart,list,list,record,map,null,true,false
2929
Hy,hy,list,list,tuple,dictionary,None,True,False
3030
Zig,zig,slice,slice,tuple,hash map,null,true,false
31+
Tcl,tcl,list,list,list,dictionary,empty string,true,false

evaluation/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
DOCKER_EXEC=podman
22

3-
build: Dockerfile Adb.dockerfile Hy.dockerfile Zig.dockerfile
3+
build: Dockerfile Adb.dockerfile Hy.dockerfile Zig.dockerfile Tcl.dockerfile
44
${DOCKER_EXEC} build -t multipl-e-evaluation .
55
${DOCKER_EXEC} build -t ghcr.io/nuprl/multipl-e:adb -f Adb.dockerfile .
66
${DOCKER_EXEC} build -t ghcr.io/nuprl/multipl-e:hy -f Hy.dockerfile .
77
${DOCKER_EXEC} build -t ghcr.io/nuprl/multipl-e:zig -f Zig.dockerfile .
8+
${DOCKER_EXEC} build -t ghcr.io/nuprl/multipl-e:tcl -f Tcl.dockerfile .
89

910
test: build
1011
${DOCKER_EXEC} run --rm \

evaluation/Tcl.dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM ubuntu:22.04
2+
ARG DEBIAN_FRONTEND=noninteractive
3+
ENV TZ=Etc/UTC
4+
5+
RUN apt-get update -yqq && apt-get install -yqq python3-tqdm tcl
6+
7+
COPY src /code
8+
WORKDIR /code
9+
ENTRYPOINT ["python3", "main.py"]

evaluation/src/containerized_eval.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import eval_dart
3232
import eval_hy
3333
import eval_zig
34+
import eval_tcl
3435
import tempfile
3536

3637

@@ -69,6 +70,7 @@
6970
"dart": (eval_dart.eval_script, ".dart"),
7071
"hy": (eval_hy.eval_script, ".hy"),
7172
"zig": (eval_zig.eval_script, ".zig"),
73+
"tcl": (eval_tcl.eval_script, ".tcl"),
7274
}
7375

7476
def eval_string_script(language, program):

evaluation/src/eval_tcl.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from pathlib import Path
2+
from safe_subprocess import run
3+
4+
def eval_script(path: Path):
5+
r = run(["tclsh", str(path)])
6+
if r.timeout:
7+
status = "Timeout"
8+
elif r.exit_code == 0:
9+
status = "OK"
10+
else:
11+
status = "Exception"
12+
return {
13+
"status": status,
14+
"exit_code": r.exit_code,
15+
"stdout": r.stdout,
16+
"stderr": r.stderr,
17+
}

0 commit comments

Comments
 (0)