Wrote my first macro in newLISP. Actually, this was only my third macro to date. I wrote one in Scheme and one in Common Lisp. How's that for symmetry?
When I mentioned in the Gotcha post that I'd translated all of my old code into newLISP, I of course was lying for dramatic effect :-) With still mountains of code yet to newLISPify, I began rewriting one of the classes I'd written in Ruby. It's called FullName and one of its methods, prefix?, uses Ruby's %w to make a list of strings from unquoted words. This is then matched against the argument to see if it is a prefix:
Code: Select all
def prefix?(s)
%w(Dr. Fraülein Frau Herr Madame Mademoiselle Miss Mlle. Mme. Monsieur Mr. Mrs. Ms. Prof. Professor Senor Senora Senorita Sr. Sra. Srta.).member?(s)
end
# N.B. absent most prefixes
The first attempt:
Code: Select all
(define-macro (words)
(map
(fn (ea)
(eval (string ea)))
(args)))
I remembered reading about name in the manual, and this seemed like the right place to use it. After some fumbling and bumbling and realizing that the eval wasn't necessary, I ended up with these 5 lines:
Code: Select all
(define-macro (words)
(map
(fn (ea)
(string (name ea)))
(args)))
("this" "is" "the" "way" "we" "wash" "our" "clothes") in or out of a context.
That was a fun ten minutes. I wonder why I thought Ruby's %w was so cool? Oh yeah! It must be the %w. No, wait.
Code: Select all
(constant '%w words)
:-)
m i c h a e l