Search the Community
Showing results for tags 'clojure'.
-
Hello, After a sidestep to Clojure, of course back to AutoLisp. I have quite some exeperience with AutoLisp and on and off I worked with it for almost 20 years now. (Auto)Lisp is known amongst AutoCAD users but further on, the whole lisp-thing doesn't ring a bell with most programmers that I meet. They work with SQL, HTML, XHTML, Java, C# or maybe (V)BA. I stayed interested in Lisp, although limited to AutoLisp. Recently. I discovered that there is a new Lisp called Clojure that is becoming big in the programming world. Possibly due to the fact that it translates to Java or javascript before anything is executed. But this aside. I learned that Clojure is first class because it is capable of accepting a function as a parameter and clojure functions can produce functions. There's a whole lot more to be discoverd about this great language but I leave that to the reader. The subject 'Clojure' is easily found on the web. By taking this interest in Clojure I learned a lot about AutoLisp too. On this page at the subject of 'Closures' halfway the page, there is an example showing how a function is produced in Clojure. Realy, it took me quite some time to grasp it. After that I wanted to know if this could be done with AutoLisp as well. After trials with defun-q-list-set/ref (which also work) I came up with the following. Hart of the solution is (eval (append '(lambda . . Is it the best way to do this? I don't know. Is it useful? I doubt it but see below. Is it interesting? Highly (for me!) (defun messenger-builder (greeting) (setq greeting (strcat "\n" greeting " ")) (eval (append '(lambda (who)) (list (list 'princ (list 'strcat greeting 'who)) '(princ))))) (setq hello-er (messenger-builder "Hello") goodbye-er (messenger-builder "Goodbye")) (defun c:greet_the_world () (hello-er "World!")) (defun c:say_goodbye () (goodbye-er "Everyone!!")) AutoLisp does a great job in AutoCAD. Perfect, but as a Lisp it is less thoroughly designed than Clojure. This shows off in the example above. Clojure handles the subject of producing functions easier. Maybe my example is ill-constructed. I could not find a better solution. Question also is, can we think of any usufull application of this in AutoCAD. Although I took another route in the example, the designated functions for this are (I think) defun-q-list-set/ref. I suppose they are there for a reaon. Or is it all limited to the s::startup example?