In the spirit of Paul Graham's request for core language ideas here are a few that I use in NewLISP that he might find useful: 1. RTN
RTN (short for RETURN) takes a boolean expression and returns the first argument to the expression rather than returning the truth value. For instance, if we write (rtn = 2 2) then 2 is returned, this is the same as
(if (= x 2) x). I find that in boolean tests that the truth value is just a means to an end and this function bypasses the need to write a conditional statement to get the value. 2. LENGTH?
How often have you written
(if (= (length lst) n)...
I have written a function where I write this as
(length? lst n =). If no n then 1 is assumed and if no operation than = is assumed. Thus to test if a list's length is equal to 1 we can write (length? lst). Is the length less than 3 then we write (length? lst 3 <). 3. FMAP
FMAP is very handy. Suppose we have
(* (+ a b)(+ c d)(+ e f)), then we can write this in the alternate form of (fmap * + a b ^ c d ^ e f) wbere the carets act as spacers for the arguments. 4. IFLENGTH
This is a new conditional statement that takes a list, a length to test against and up to three blocks of code A,B,C. If we write (iflength lst n A B C) then this is the same as
(if (< n (length lst)) A (= n (length lst)) B C).
If we write (iflength lst n A B) this is the same as (if (= n (length lst)) A B). And finally (iflength lst n A) is just (if (= n (length lst)) A). I have found all of these very handy. |