{"id":4376,"date":"2026-10-12T09:29:18","date_gmt":"2026-10-12T03:59:18","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=4376"},"modified":"2026-10-12T09:29:18","modified_gmt":"2026-10-12T03:59:18","slug":"run-length-encoding-in-common-lisp","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2026\/10\/12\/run-length-encoding-in-common-lisp\/","title":{"rendered":"Run Length Encoding in Common Lisp"},"content":{"rendered":"<p>I was curious to generate <em><strong>Common Lisp<\/strong><\/em> code using <em><strong>ChatGPT<\/strong><\/em> and <em><strong>Claude<\/strong><\/em> for a simple problem and then compare the code. After thinking for while, I decided to use the <em><strong>\u201cRun Length Encoding\u201d<\/strong><\/em> problem for this experiment.<\/p>\n<p>Here is the prompt I used:<\/p>\n<p><em><strong>\u201cYou are an experienced Common Lisp developer. Please write bug-free and elegant Lisp code for run-length encoding\/decoding.\u201d<span class=\"Apple-converted-space\">\u00a0<\/span><\/strong><\/em><\/p>\n<p>Nothing fancy. To the point.<\/p>\n<p>Here is the code generated by <em><strong>ChatGPT<\/strong><\/em> (model: GPT 5.6 Medium mode):<\/p>\n<figure id=\"attachment_4377\" aria-describedby=\"caption-attachment-4377\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/ChatGPT.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"4377\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/10\/12\/run-length-encoding-in-common-lisp\/chatgpt\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/ChatGPT.jpg\" data-orig-size=\"984,662\" data-comments-opened=\"1\" data-image-meta=\"{&quot;credit&quot;:&quot;Admin&quot;,&quot;created_timestamp&quot;:&quot;1791658205&quot;}\" data-image-title=\"ChatGPT Code\" data-image-description=\"&lt;p&gt;ChatGPT Code&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;ChatGPT Code&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/ChatGPT.jpg\" class=\"wp-image-4377\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/ChatGPT.jpg?resize=550%2C370&#038;ssl=1\" alt=\"ChatGPT Code\" width=\"550\" height=\"370\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/ChatGPT.jpg?resize=300%2C202&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/ChatGPT.jpg?w=984&amp;ssl=1 984w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-4377\" class=\"wp-caption-text\"><strong>ChatGPT Code<\/strong><\/figcaption><\/figure>\n<p>The following was generated by <em><strong>Claude<\/strong><\/em> (model: Opus 5.5 Medium mode):<\/p>\n<figure id=\"attachment_4378\" aria-describedby=\"caption-attachment-4378\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/Claude.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4378\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/10\/12\/run-length-encoding-in-common-lisp\/claude\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/Claude.jpg\" data-orig-size=\"952,554\" data-comments-opened=\"1\" data-image-meta=\"{&quot;credit&quot;:&quot;Admin&quot;,&quot;created_timestamp&quot;:&quot;1791658233&quot;}\" data-image-title=\"Claude Code\" data-image-description=\"&lt;p&gt;Claude Code&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Claude Code&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/Claude.jpg\" class=\"wp-image-4378\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/Claude.jpg?resize=550%2C320&#038;ssl=1\" alt=\"Claude Code\" width=\"550\" height=\"320\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/Claude.jpg?resize=300%2C175&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/Claude.jpg?w=952&amp;ssl=1 952w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-4378\" class=\"wp-caption-text\"><strong>Claude Code<\/strong><\/figcaption><\/figure>\n<p>You can see that <em><strong>ChapGPT\u2019s<\/strong><\/em> code for encoding is slightly more <span style=\"text-decoration: underline;\">verbose<\/span> than <em><strong>Claude\u2019s<\/strong><\/em>, but the decoding implementation is more compact. Such differences are expected even among human programmers, so no big deal. But what made me happy is the fact that both implementations worked the first time, without bugs! I think simplicity of the problem is the main reason for this.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Here is the output for different inputs:<\/p>\n<figure id=\"attachment_4379\" aria-describedby=\"caption-attachment-4379\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/output.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4379\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/10\/12\/run-length-encoding-in-common-lisp\/output-16\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/output.jpg\" data-orig-size=\"821,755\" data-comments-opened=\"1\" data-image-meta=\"{&quot;credit&quot;:&quot;Admin&quot;,&quot;created_timestamp&quot;:&quot;1791658086&quot;}\" data-image-title=\"Program Output\" data-image-description=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/output.jpg\" class=\"wp-image-4379\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/output.jpg?resize=500%2C460&#038;ssl=1\" alt=\"Program Output\" width=\"500\" height=\"460\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/output.jpg?resize=300%2C276&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/10\/output.jpg?w=821&amp;ssl=1 821w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-4379\" class=\"wp-caption-text\"><strong>Program Output<\/strong><\/figcaption><\/figure>\n<p>I tested the programs in <em><strong>LispWorks Lisp ver 8.0<\/strong><\/em>. You can download the source <a href=\"https:\/\/www.rangakrish.com\/downloads\/Run-length-encoding.lisp\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\">here<\/span><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was curious to generate Common Lisp code using ChatGPT and Claude for a simple problem and then compare the code. After thinking for while, I decided to use the \u201cRun Length Encoding\u201d problem for this experiment. Here is the prompt I used: \u201cYou are an experienced Common Lisp developer. Please write bug-free and elegant [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_seo_schema_type":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[18,17],"tags":[348,454,465],"class_list":["post-4376","post","type-post","status-publish","format-standard","hentry","category-lisp","category-programming","tag-chatgpt","tag-claude","tag-run-length-encoding"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-18A","jetpack-related-posts":[{"id":2927,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/10\/20\/why-learn-lisp\/","url_meta":{"origin":4376,"position":0},"title":"Why Learn Lisp?","author":"admin","date":"October 20, 2022","format":false,"excerpt":"In the last article, I had shared my views on why programmers should learn Prolog, preferably as the first language. What language should one learn next? I strongly pitch for Lisp, to be precise, \u201cCommon Lisp\u201d. Lisp happens to be the second oldest (1958) programming language, only after Fortran (1957)!\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3589,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/01\/04\/word-transformation-puzzle-part-2-implementation-in-common-lisp\/","url_meta":{"origin":4376,"position":1},"title":"Word Transformation Puzzle &#8211; Part 2: Implementation in Common Lisp","author":"admin","date":"January 4, 2025","format":false,"excerpt":"In the last article\u00a0I discussed an interesting word puzzle and showed how to solve it using Prolog. Here is the problem statement: \u201cYou are given two words of the same length. You have to transform the first word into the second word, by changing only one letter at a time.\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Getting Word Neighbors","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/01\/code1-300x127.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/01\/code1-300x127.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/01\/code1-300x127.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2765,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/04\/17\/calling-lisp-functions-from-xojo\/","url_meta":{"origin":4376,"position":2},"title":"Calling Lisp Functions from Xojo","author":"admin","date":"April 17, 2022","format":false,"excerpt":"A few days ago, I purchased Xojo Pro commercial license. In case you haven't heard about the product, Xojo\u00a0is a popular cross-platform development tool targeting Desktop, Web and iOS (Android is expected in the near future). It supports an Object-Oriented Basic language. It has been around for over 25 years\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"The Lisp Code","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/04\/LispCode-300x168.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/04\/LispCode-300x168.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/04\/LispCode-300x168.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3525,"url":"https:\/\/www.rangakrish.com\/index.php\/2024\/10\/13\/using-chatgpt-for-algorithmic-music-composition\/","url_meta":{"origin":4376,"position":3},"title":"Using ChatGPT for Algorithmic Music Composition","author":"admin","date":"October 13, 2024","format":false,"excerpt":"Algorithmic music composition is one of my favourite areas. And in terms of tools, as several of my past articles\u00a0show, OpusModus software is the main choice.\u00a0 Recently I have been spending some time checking if ChatGPT could be cajoled into writing some good OpusModus code. But the experience has not\u2026","rel":"","context":"In &quot;Music&quot;","block_context":{"text":"Music","link":"https:\/\/www.rangakrish.com\/index.php\/category\/music\/"},"img":{"alt_text":"SonicPi Code for Twinkle Twinkle Lite Star","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/twinkle-300x280.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/twinkle-300x280.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/10\/twinkle-300x280.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3555,"url":"https:\/\/www.rangakrish.com\/index.php\/2024\/11\/22\/multiobjective-optimization-moo-in-lisp-and-prolog\/","url_meta":{"origin":4376,"position":4},"title":"Multiobjective Optimization (MOO) in Lisp and Prolog","author":"admin","date":"November 22, 2024","format":false,"excerpt":"Recently I came across a nice article\u00a0by Jose Crespo, where the author stresses that the future of programming revolves around the application of math concepts such as Functor, Monads, Folds, etc. In addition, he argues that familiarity with C\/C++ is essential in this modern AI age. The author goes through\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Lisp Code for Pareto Front","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/11\/lisp-code-249x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":558,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/07\/07\/clpython-python-in-common-lisp\/","url_meta":{"origin":4376,"position":5},"title":"CLPython &#8211; Python in Common Lisp","author":"admin","date":"July 7, 2017","format":false,"excerpt":"My work in the area of NLP requires\u00a0me to work with several frameworks across multiple languages such as Java, Python and Lisp. Sometime ago I got a chance to experiment with CLPython, an open-source implementation of Python in Common Lisp. Although CLPython is not under active development now, I found\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=4376"}],"version-history":[{"count":2,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4376\/revisions"}],"predecessor-version":[{"id":4381,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4376\/revisions\/4381"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=4376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=4376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=4376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}