Hi all,
@ Mike , it is common to use the operator first as in apply , map , for-each etc.. in recursive based mechanisms , but the NewLisp iterative constructions do it your proposed way (for (i from to &opt::step) body) and (dotimes (i end &opt::break) body )
so I changed it.
It is still "camouflaged" mapping -- there are no real iterative steps involved -- it just maps a function over a list in one flow - this operation can not be split in parts that give back intermediate results -- there is no way to declare the arguments of the lambda function non-local -- there is no way to define a global variable inside a function (NewLisp can do this) -- there is no single iterative mechanism to start with that can be expanded ... but, maybe ... I have to sleep on it , yes , maybe ...
the operator has to be quoted -- otherwise it will be evaluated before its result is passed as an argument -- if the pseudo-index doesn't need manipulation, it is directly assigned without the need for setting up a local variable for it (see attached).
.. I also defined (nth i L) , which gives the nth element of a List (beware indexbase 0)
best I'll read the documentation once again ...
0](iterate+ 1 6 1 '(lambda (x) (println (+ x x)))))
2
4
6
8
10
12
T
0](iterate+ 1 6 1 'println)
1
2
3
4
5
6
T
0](nth 2 (range 6))
2
0](nth 4 (make-indexx 1 10 0.2 '() ))
1.800000
0](make-indexx 1 10 0.2 '() )
(1 1.200000 1.400000 1.600000 1.800000 2.000000 2.200000 2.400000 2.600000 2.800000 3.000000 3.200000 3.400000 3.600000 3.800000 4.000000 4.200000 4.400000 4.600000 4.800000 5.000000 5.200000 5.400000 5.600000 5.800000 6.000000 6.200000 6.400000 6.600000 6.800000 7.000000 7.200000 7.400000 7.600000 7.800000 8.000000 8.200000 8.400000 8.600000 8.800000 9 9.200000 9.400000 9.600000 9.800000 10.000000)
0]
best Rob
(maybe something can be done with pre-declared global variables -- but it looks ugly to define some things for functions/procedures that are pre-coded -- and I'm even not sure they are correctly assinged in nested lambda-function
(I mean (lambda (x)
(lambda (y) .... )) do x and Y know each other ?? i'll try , but doubt it ...
@ John , the real story of MacRob - b
The Story of Mac: A Just-So Story
------------------------------------------
Once upon a time, long ago, there was a company of Lisp programmers. It was so long ago, in fact, that Lisp had no macros. Anything that couldn't be defined with a function or done with a special operator had to be written in full every time, which was rather a drag. Unfortunately, the programmers in this company--though brilliant--were also quite lazy. Often in the middle of their programs--when the tedium of writing a bunch of code got to be too much--they would instead write a note describing the code they needed to write at that place in the program. Even more unfortunately, because they were lazy, the programmers also hated to go back and actually write the code described by the notes. Soon the company had a big stack of programs that nobody could run because they were full of notes about code that still needed to be written.
In desperation, the big bosses hired a junior programmer, Mac, whose job was to find the notes, write the required code, and insert it into the program in place of the notes. Mac never ran the programs--they weren't done yet, of course, so he couldn't. But even if they had been completed, Mac wouldn't have known what inputs to feed them. So he just wrote his code based on the contents of the notes and sent it back to the original programmer.
With Mac's help, all the programs were soon completed, and the company made a ton of money selling them--so much money that the company could double the size of its programming staff. But for some reason no one thought to hire anyone to help Mac; soon he was single- handedly assisting several dozen programmers. To avoid spending all his time searching for notes in source code, Mac made a small modification to the compiler the programmers used. Thereafter, whenever the compiler hit a note, it would e-mail him the note and wait for him to e-mail back the replacement code. Unfortunately, even with this change, Mac had a hard time keeping up with the programmers. He worked as carefully as he could, but sometimes-- especially when the notes weren't clear--he would make mistakes.
The programmers noticed, however, that the more precisely they wrote their notes, the more likely it was that Mac would send back correct code. One day, one of the programmers, having a hard time describing in words the code he wanted, included in one of his notes a Lisp program that would generate the code he wanted. That was fine by Mac; he just ran the program and sent the result to the compiler.
The next innovation came when a programmer put a note at the top of one of his programs containing a function definition and a comment that said, "Mac, don't write any code here, but keep this function for later; I'm going to use it in some of my other notes." Other notes in the same program said things such as, "Mac, replace this note with the result of running that other function with the symbols x and y as arguments."
This technique caught on so quickly that within a few days, most programs contained dozens of notes defining functions that were only used by code in other notes. To make it easy for Mac to pick out the notes containing only definitions that didn't require any immediate response, the programmers tagged them with the standard preface: "Definition for Mac, Read Only." This--as the programmers were still quite lazy--was quickly shortened to "DEF. MAC. R/O" and then "DEFMACRO."
Pretty soon, there was no actual English left in the notes for Mac. All he did all day was read and respond to e-mails from the compiler containing DEFMACRO notes and calls to the functions defined in the DEFMACROs. Since the Lisp programs in the notes did all the real work, keeping up with the e-mails was no problem. Mac suddenly had a lot of time on his hands and would sit in his office daydreaming about white-sand beaches, clear blue ocean water, and drinks with little paper umbrellas in them.
Several months later the programmers realized nobody had seen Mac for quite some time. When they went to his office, they found a thin layer of dust over everything, a desk littered with travel brochures for various tropical locations, and the computer off. But the compiler still worked--how could it be? It turned out Mac had made one last change to the compiler: instead of e-mailing notes to Mac, the compiler now saved the functions defined by DEFMACRO notes and ran them when called for by the other notes. The programmers decided there was no reason to tell the big bosses Mac wasn't coming to the office anymore. So to this day, Mac draws a salary and from time to time sends the programmers a postcard from one tropical locale or another.
best Rob