Re: S-expressions
Lieven Marchand <mal-x0HW/[email protected]> 07 Aug 2003 19:54:52 +0200
| Newsgroups | gmane.comp.programming.pragmatic |
|---|---|
| Message-ID | <[email protected]> |
Aaron Optimizer Digulla <[email protected]> writes: > > May I give you a few examples of existing Lisp macrology? I'll be happy to give you some explanation of the stuff below - in fact, I'll enthuse about Lisp long after you'll be sick of me going on about it - but you're missing my main point. All the features below can be added to Lisp in a completely portable way as macros. It's not about the features, the point is that they do not have to be built into the core language to appear as first class language concepts. > > * generalized assignment (the setf macro) > > So I can (setf a b)? What's wrong with a=b? The generalized part. a[i][j][k] is written in Lisp as (aref a i j k) and to set that element you do (setf (aref a i j k) b). Hash table lookup is done as (get-hash key hash-table) and setting one is done as (setf (get-hash key hash-table) b). Now suppose I have a function (circumference triangle). I can define (defun (setf circumference) (new-circumference triangle) ; scale sides so circumference is new-circumference ) and then I can do (setf (circumference triangle) 1) > > * the LOOP macro > > > > this was an experiment in coding a more algol like iteration statement. > > > > It allows you to write stuff like > > Ok, this is a very good example because I didn't understand it :-) Once again, the point was that a macro (in the original MIT implementation a macro of some 10000 lines of code) can change a parenthesis rich language like Lisp into something algol like. > > (loop for i from 0 below 10 > > That is probably for i = 0 to 10. from 0 to 9 inclusive. otherwise it would be from 0 to 10 > > > for j across string > > uhm... iterate over every character of the string? yes > > for key being each hash-key of hash-table > > python would say here > > for key in hashTable.keys(): > > Which is easier to understand? Assuming this isn't rhetorical, I'd say both are about as easy. What does python do for the following: for key being each hash-key of hash-table using (hash-value value) where it will iterate with key bound to the key and value bound to the value > > sum i into account > > ?? account += i or what? yes > > collect j into stack > keep each j into a list > > > when (eql key :foo) > > do > > (push (get-hash key hash-table) stack) > > finally (return (values account stack))) > > argl... > > Ok, this seems to be a while look (while key == :foo). What does the ":" mean? > > Then we seem to have the body of the loop (do(...)). Nope. It's a conditional in the loop when <condition> do <body> > What happened to the "Professionals read the code by indentation" > when the code is not indented??? :-) > > Ok, next statement is a push (something) on stack. I guess that the loop > pushes all elements where the key is larger than ":foo" into stack. equal > As a result, the values of "account" and "stack" are returned. > > But the code confuses me completely: > > - Why is there a "(" before push but none before "for", "sum", > "collect", "when" and "finally"?? because for the body one drops again into native lisp. > - Where does a statement begin and where does it end? Is the second > for part of the body of the first for? there is one iteration. All variables are iterated parallel. > > Further, if you have your own data structure, say a graph, you can > > tell loop about it with add-loop-path and then you can use 'for edge > > being each edge of graph' as a loop clause. > > Python, C++ and Java have iterators, too. Obviously any language can implement an iterator data structure, even C. Since loop is a macro, it isn't called at runtime but at compile time. add-loop-path generates pieces of code that the compiler will place at the right point in the loop body. Think C++ templates rather than iterators. > My whole point is: > > - The infix syntax is hard to read if the language doesn't > enforce indentation because you have to manually count > the parens to know what belongs where. Stuff you're not used to is hard to read. Film at 11. > - 90% of all software developers are not used to it 100% of all software developers won't be used to our new language. Maybe we should redesign Visual Basic? > - Recursive structures in the code confuse people. Many people > don't understand how quicksort works and that's one of > the most simple sorting algorithms. Make a tool designed for an idiot and only an idiot will want to use it. -- Jane - Daria? Come on, the neighbors are starting to talk. Daria - Um... good. Soon they'll progress to cave drawings and civilization will be on its way. ------------------------ Yahoo! Groups Sponsor ---------------------~--> Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511 http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/W4wwlB/TM ---------------------------------------------------------------------~-> To unsubscribe from this group, send an email to: pragmatic_lang-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/