Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lisp: advanced string comparison

I recently encountered this line in some common LISP library code:

(string-equal #1="http://" url :end2 (min (length url) #2=#.(length #1#)))

Here, url was passed in as a string variable. I understand the purpose of this comparison is to determine if the url string starts with http:// and it's a case-insensitive compare. I also understand about string-equal keys, such as :start and :end. But the pound sign (#) items threw me. I can figure most of it out by context, but I haven't found documentation on how it works, and I'm still befuddled a bit by what #2=#.(length #1#) really means. It looks a little mystical to me.

Could someone please explain how the pound sign mechanism works in this specific context and if it's universally usable in other constructs in the same way? Or point me to a document/website that describes it.

Thank you!

like image 806
lurker Avatar asked Jan 02 '14 04:01

lurker


1 Answers

The pound (or sharp) sign's function is described in the Hyperspec here.

The #1= notation labels the following form (here the string "http://") with a numeric index for later backreference by the #1# notation. #. causes the following form to be evaluated at read time.

The overall effect is to make it as if the code had been written as:

(string-equal "http://" url :end2 (min (length url) 7))
like image 175
Sean Avatar answered Sep 26 '22 03:09

Sean