{"action":"created","issue":{"url":"https://api.github.com/repos/kanaka/mal/issues/106","labels_url":"https://api.github.com/repos/kanaka/mal/issues/106/labels{/name}","comments_url":"https://api.github.com/repos/kanaka/mal/issues/106/comments","events_url":"https://api.github.com/repos/kanaka/mal/issues/106/events","html_url":"https://github.com/kanaka/mal/pull/106","id":116016549,"number":106,"title":"Tcl implementation","user":{"login":"dubek","id":9211,"avatar_url":"https://avatars.githubusercontent.com/u/9211?v=3","gravatar_id":"","url":"https://api.github.com/users/dubek","html_url":"https://github.com/dubek","followers_url":"https://api.github.com/users/dubek/followers","following_url":"https://api.github.com/users/dubek/following{/other_user}","gists_url":"https://api.github.com/users/dubek/gists{/gist_id}","starred_url":"https://api.github.com/users/dubek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dubek/subscriptions","organizations_url":"https://api.github.com/users/dubek/orgs","repos_url":"https://api.github.com/users/dubek/repos","events_url":"https://api.github.com/users/dubek/events{/privacy}","received_events_url":"https://api.github.com/users/dubek/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-11-10T03:14:42Z","updated_at":"2015-11-10T15:10:31Z","closed_at":"2015-11-10T04:19:18Z","pull_request":{"url":"https://api.github.com/repos/kanaka/mal/pulls/106","html_url":"https://github.com/kanaka/mal/pull/106","diff_url":"https://github.com/kanaka/mal/pull/106.diff","patch_url":"https://github.com/kanaka/mal/pull/106.patch"},"body":"Full Tcl implementation of mal - passes all tests and self-hosting tests. It requires Tcl 8.6 because I use `oo::class`. It includes readline support via tclreadline (if available) and very basic Tcl \"integration\" with the `tcl*` form (see `tcl/tests/stepA_mal.mal` for examples).\r\n\r\n\r\n### Memory leak\r\n\r\nOne issue: this implementation leaks memory - environments are not really deleted. Tcl has no garbage collection, and new objects (in our case, new Env objects) are never deleted unless explicitly destroyed. The following mal program causes the implementation to be killed by the Linux OOM killer:\r\n\r\n```\r\n(def! rec (fn* () (rec)))\r\n(rec)\r\n```\r\n\r\nI noticed this is also a proglem of the C implementation, but does not occur in the Ruby implementation (the Ruby GC kicks into work correctly).\r\n\r\nI think this can be solved for Tcl by implementing reference counting over the Env objects, and destroying when the count goes down to zero. Sounds like a headache...\r\n\r\n\r\n### Regression testing\r\n\r\nDuring the development I found it important in some steps to verify that I haven't broken something that was working OK earlier. In this case while implementing TCO in step 5 I broke `let*` by mistake, but no tests covered it. I wrote a small regression tester (for Tcl - see code below) that runs all the test cases from previous steps (except step0 and step1) against the given step implementation. A better implementation would be in the Makefile with all the info available there.\r\n\r\n```\r\n#!/bin/bash\r\n\r\nstep=$1\r\n\r\nif [ -z $step ] ; then\r\n  echo \"Usage: $0 step\"\r\n  echo \"Example: $0 step9\"\r\n  exit 1\r\nfi\r\n\r\nstep0_regs=\"step0\"\r\nstep1_regs=\"step1\"\r\nstep2_regs=\"step2\"\r\nstep3_regs=\"$step2_regs step3\"\r\nstep4_regs=\"$step3_regs step4\"\r\nstep5_regs=\"$step4_regs step5\"\r\nstep6_regs=\"$step5_regs step6\"\r\nstep7_regs=\"$step6_regs step7\"\r\nstep8_regs=\"$step7_regs step8\"\r\nstep9_regs=\"$step8_regs step9\"\r\nstepA_regs=\"$step9_regs stepA\"\r\n\r\nprojectdir=$(dirname $0)\r\ncd $projectdir/tcl\r\n\r\ntestfiles=\"\"\r\neval \"regsteps=\\$${step}_regs\"\r\nfor s in $regsteps ; do\r\n  testfile=$(echo ../tests/$s*.mal)\r\n  testfiles=\"$testfiles $testfile\"\r\ndone\r\n\r\n../runtest.py <(cat $testfiles) -- tclsh ../tcl/${step}_*\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/kanaka/mal/issues/comments/155446720","html_url":"https://github.com/kanaka/mal/pull/106#issuecomment-155446720","issue_url":"https://api.github.com/repos/kanaka/mal/issues/106","id":155446720,"user":{"login":"dubek","id":9211,"avatar_url":"https://avatars.githubusercontent.com/u/9211?v=3","gravatar_id":"","url":"https://api.github.com/users/dubek","html_url":"https://github.com/dubek","followers_url":"https://api.github.com/users/dubek/followers","following_url":"https://api.github.com/users/dubek/following{/other_user}","gists_url":"https://api.github.com/users/dubek/gists{/gist_id}","starred_url":"https://api.github.com/users/dubek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dubek/subscriptions","organizations_url":"https://api.github.com/users/dubek/orgs","repos_url":"https://api.github.com/users/dubek/repos","events_url":"https://api.github.com/users/dubek/events{/privacy}","received_events_url":"https://api.github.com/users/dubek/received_events","type":"User","site_admin":false},"created_at":"2015-11-10T15:10:31Z","updated_at":"2015-11-10T15:10:31Z","body":"Should I add tcl and vimscript to the big `tests/docker/Dockerfile` ?"}}