4 ms·
For those saying that the code is too verbose, here is another version in Common Lisp: (defun jim (arg &optional path) (etypecase arg (string
by junke 10y ago
For those saying that the code is too verbose, here is another version in Common Lisp:
(defun jim (arg &optional path)
(etypecase arg
(string
(format t "import ~{~(~A~).~}~A;~%" (reverse path) arg))
(list
(push (pop arg) path)
(dolist (a arg)
(jim a path)))))
Test:
(jim
'(java
(util "HashMap" "HashSet" "Map" "Random" "Set" "UUID"
(concurrent "ExecutorService" "Executors" "Callable" "Future"))
(awt "Color")))
Gives:
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.awt.Color;
- ruste 10y agoIf you'd prefer common lisp you should check out the project that inspired mine: https://github.com/zc1036/lips https://github.com/zc1036/lips
- junke 10y agoYou did a great job and I am sorry that the discussion is mostly about the example. I saw the Scheme version and found it quite verbose, like some other people on this thread. That's what made me want to implement a CL one. Maybe if you had a less controversial example where you produce e.g. Markdown text, it would not distract people from the tool.
- ruste 10y agoIt was verbose. I actually left a comment in the example about how it could have been written better. Someone else further down in the comments suggested a nicer way of writing it. I think most people got the idea though! Thanks for the feedback. :)