Only in Lisp

Discussion of Common Lisp
ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: Only in Lisp

Post by ramarren » Sat May 15, 2010 6:52 am

Gerenuk wrote:Can you recommend a specific other high-quality macro I could attempt? (as I don't know much Lisp it's hard for me to judge suitable macros myself)
To be clear, I don't claim my code to be especially high quality. I would suggest cl-cont, but I guess that would be cheating. Or parenscript. Also cl-unification is an interesting application of macros.

Although do note that as I have written before, macros are compiler extensions. If you do not have a compiler, then by definition you cannot have macros and are not doing what a macro is doing. This might not matter for pure expressiveness, as usually you can just write an interpreter for some data language with fairly minimal additional markers, but it does affect both time and space performance.

lithos
Posts: 14
Joined: Tue Feb 02, 2010 4:11 pm

Re: Only in Lisp

Post by lithos » Sat May 15, 2010 7:07 am

A complete unit test framework capable of accepting any type of code and testing it compared to any type of result and with well formatted output. Which isn't bad for 16 lines of code(without comments), if you printed it out a piece of paper would feel almost naked. You even get the full walk-through for how the code was developed here: http://www.gigamonkeys.com/book/practic ... ework.html, Practical Common Lisp of course.

Code: Select all

(defvar *test-name* nil)

(defmacro deftest (name parameters &body body)
  "Define a test function. Within a test function we can call
   other test functions or use 'check' to run individual test
   cases."
  `(defun ,name ,parameters
    (let ((*test-name* (append *test-name* (list ',name))))
      ,@body)))

(defmacro check (&body forms)
  "Run each expression in 'forms' as a test case."
  `(combine-results
    ,@(loop for f in forms collect `(report-result ,f ',f))))

(defmacro combine-results (&body forms)
  "Combine the results (as booleans) of evaluating 'forms' in order."
  (with-gensyms (result)
    `(let ((,result t))
      ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
      ,result)))

(defun report-result (result form)
  "Report the results of a single test case. Called by 'check'."
  (format t "~:[FAIL~;pass~] ... ~a: ~a~%" result *test-name* form)
  result)

Jasper
Posts: 209
Joined: Fri Oct 10, 2008 8:22 am
Location: Eindhoven, The Netherlands
Contact:

Re: Only in Lisp

Post by Jasper » Sat May 15, 2010 8:53 am

Special vars:

Code: Select all

(let ((*special-variable* something else))
  (any-program-using-that)) ;Feeding arguments to a program by non-destructive changing of its variables.
You can look at it as adding then as arguments everywhere. Also useful if you have a recursive function and values are passed unchanged a lot.

The more i head into functions using and returning functions, the less i need macros.(So the more suitable macroless languages seem) However macros like with-slots will remain a requisite for me, and will likely still want to make my own macros like that. Anyway, how do you access elements of a structure in python? In C++ the member functions approach is silly,(and can only do one object at a time) and object.slot all the time is cumbersome.(and the '.' notation not particularly natural, but whatever)

Does python have &keyword arguments, &rest arguments? Know a good link summarizing pythons features thoroughly? For people learning CL i usually link to PCL. (Though that is a learning book, not really a feature summary.)

Ben
Posts: 6
Joined: Thu Jul 02, 2009 2:28 am
Location: Germany

Re: Only in Lisp

Post by Ben » Mon May 17, 2010 4:19 am

Well, i think we have forgotten one thing in our goal to 'convert' Gerenuk. :)
In LISP it is very simple to debug your code. You can visit your code line by line, make changes on the values (if you want) or inspect symbols and go on. You have no overhead with debugging-tools or breakpoints and such things.

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: Only in Lisp

Post by gugamilare » Mon May 17, 2010 6:42 am

Ben wrote:Well, i think we have forgotten one thing in our goal to 'convert' Gerenuk. :)
In LISP it is very simple to debug your code. You can visit your code line by line, make changes on the values (if you want) or inspect symbols and go on. You have no overhead with debugging-tools or breakpoints and such things.
If we go down on that route, there are also many SLIME's feature that could be mentioned. Like the ability to inspect values, which is very useful to visualize the object you are dealing with. Or the ability to copy-by-reference: just point to a printed representation of a value in the REPL and you can use the value (unless already garbage collected, of course). Consistency: in Python, AFAIK, you can't copy files' contents to the REPL directly, you have to copy function by function or something. In Lisp you don't have to worry about it. Other features Python might also have, like finding the source of a function, checking documentation of a function or variable...

Suroy
Posts: 46
Joined: Sat Dec 19, 2009 11:20 am

Re: Only in Lisp

Post by Suroy » Tue May 18, 2010 7:45 am

I wonder about the feasability of creating a python to lisp compiler. Reuse all of that wonder python code. especially since all features of python are available in lisp.

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: Only in Lisp

Post by gugamilare » Tue May 18, 2010 7:58 am

Suroy wrote:I wonder about the feasability of creating a python to lisp compiler. Reuse all of that wonder python code. especially since all features of python are available in lisp.
You mean cl-python? There is also python-on-lisp, which communicates with Python rather than recompiling Python.

Suroy
Posts: 46
Joined: Sat Dec 19, 2009 11:20 am

Re: Only in Lisp

Post by Suroy » Tue May 18, 2010 10:19 am

Oh, didn't see that one. So it compiles python to lisp? Nice :D

Edit: Any catch? I would think with all those python libraries out there, compiling them to lisp and using them would be really advantageous.

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Only in Lisp

Post by nuntius » Tue May 18, 2010 10:32 am

Suroy wrote:Any catch? I would think with all those python libraries out there, compiling them to lisp and using them would be really advantageous.
I talked to the author at ILC09. The two catches were (1) he wasn't tracking the latest additions to python and (2) it didn't work with python libraries which were wrappers over a C/C++ library. Other than that, it sounded rather full featured and fast.

Jasper
Posts: 209
Joined: Fri Oct 10, 2008 8:22 am
Location: Eindhoven, The Netherlands
Contact:

Re: Only in Lisp

Post by Jasper » Tue May 18, 2010 12:23 pm

This page has some languages in lisp. Would be awesome if as asdf gets fixed, then, with an extension, we probably could add Python code and other languages just by adding the files to the defsystem, if this C/C++ library thing gets fixed.

Post Reply