Syntax Suggestions
Posted: Sat Oct 16, 2004 5:15 pm
I like this language a lot but hey, everyone thinks they have a good idea and I'm no different. So I would like to suggest some ideas that could be useful for reducing expression size.
1. LISTS
Lists are written like (list a b c) or even '(a b c) but it might also be good to allow us to write ( a b c) and dispense with the extra symbols altogether. In this case if there is at least one space after the left parenthesis then it is considered to be a list.
2. BOOLEAN FUNCTIONS
I'm glad to see that newLISP ends its boolean func names with "?" instead of "p". Let us go one further and have the boolean act as its own if/then conditional if you end the function name with "??". For instance,
(if (= x 3) 4 5) could be (=?? x 3 4 5)
All the arguments are collected together and the last two arguments are the "then" and "else" part of the statement. If there is no "else" condition then we can stuff it with a + sign as in
(if (= x 3) 4) becomes (=?? x 3 4 +)
Use ~ as a prefix to represent the "not" function so that we can write
(if (not (zero? x)) a b) as (~zero?? x a b)
This technique could save us a lot of parentheses and get rid of 90% of those "if" statements. Note that this would allow writing a "cond" statement in an explicit form if one wished. For instance
(cond
((= x 3) A)
((zero? y) B)
(true C)
)
would be
(=?? x 3 A
(zero?? y B C))
3. NESTED FUNCTIONS
Suppose we have the statement (sqrt (abs (sin (tan x)))), this kind of nesting often occurs. How about allowing us to write this as
(sqrt abs sin tan | x) ?
The vertical slash separates the nested item from the function names that are nesting around it.
4. NUMBERS as FUNCTIONS
This is a bit esoteric but hear me out. I would like to see the ability to treat numbers as functions and make newLISP even more of a functional language. What do I mean? I suggest a function that generates a complex number. This would have the form
(c <real digit list><real expon><imag digit list><imag expon><base>)
If the number base is not supplied it defaults to 10.
If exponents are not supplied they default to being equal to the number of digits in the digit list before them.
If a digit list is not supplied it defaults to '(0).
Negative bases, digits and exponents are all allowed.
With these rules here are some examples of numbers:
23 -> (c '(2 3))
-4 -> (c '(-4))
12.34 -> (c '(1 2 3 4) 2)
-12.34 -> (c '(-1 -2 -3 -4) 2)
1.3e3 -> (c '(1 3) 4) one notes the exponent is 1 larger
56i -> (c nil nil '(5 6))
0.78i -> (c nil nil '(7 8) 0)
1.2+8.3i -> (c '(1 2) 1 '(8 3) 1)
3AB base 12 (c '(3 10 11) nil nil nil 12)
The point here is not to demand that everyone start writing their numbers this way but to allow them to in those cases where the person wants total control of the number down to the digits and the base. This might not seem important but I think people will find clever things to do with it. This function will of course output a list with all the parts of the complex number. The math functions will have to be rewritten to take this list as input as well as the standard format numbers. There should also be two other functions
(numeric-output-standard)
(numeric-output-complex)
These would act as toggles to decide how the math functions are going to output their results, as normal numbers or complex number lists. When the user writes (numeric-output-complex) all the functions will return complex lists until they call (numeric-output-standard) again. The default is standard of course.
We also need conversion between standard and complex numbers with
(standardtocomplex n)
(complextostandard n)
So (standardtocomplex 1.2) -> ((1 2) 1 (0) 1 10)
and (complextostandard ((1 2) 1 (0) 1 10)) -> 1.2
5. NUMERIC CONDITIONAL STATEMENTS
I would like to suggest adding two numeric condtional statements that I have found extremely handy to have. First
(<=> x y A B C)
This statement means:
If (< x y) return the evaluation of A
If (= x y) return the evaluation of B
If (> x y) return the evaluation of C
And second,
(signcond x A B C)
This is similar to the first function but means
If x is negative return the evaluation of A
If x is zero return the evaluation of B
If x is positive return the evaluation C
Well I am probably wearing out my welcome with too many suggestions but I look forward to the commentary.
1. LISTS
Lists are written like (list a b c) or even '(a b c) but it might also be good to allow us to write ( a b c) and dispense with the extra symbols altogether. In this case if there is at least one space after the left parenthesis then it is considered to be a list.
2. BOOLEAN FUNCTIONS
I'm glad to see that newLISP ends its boolean func names with "?" instead of "p". Let us go one further and have the boolean act as its own if/then conditional if you end the function name with "??". For instance,
(if (= x 3) 4 5) could be (=?? x 3 4 5)
All the arguments are collected together and the last two arguments are the "then" and "else" part of the statement. If there is no "else" condition then we can stuff it with a + sign as in
(if (= x 3) 4) becomes (=?? x 3 4 +)
Use ~ as a prefix to represent the "not" function so that we can write
(if (not (zero? x)) a b) as (~zero?? x a b)
This technique could save us a lot of parentheses and get rid of 90% of those "if" statements. Note that this would allow writing a "cond" statement in an explicit form if one wished. For instance
(cond
((= x 3) A)
((zero? y) B)
(true C)
)
would be
(=?? x 3 A
(zero?? y B C))
3. NESTED FUNCTIONS
Suppose we have the statement (sqrt (abs (sin (tan x)))), this kind of nesting often occurs. How about allowing us to write this as
(sqrt abs sin tan | x) ?
The vertical slash separates the nested item from the function names that are nesting around it.
4. NUMBERS as FUNCTIONS
This is a bit esoteric but hear me out. I would like to see the ability to treat numbers as functions and make newLISP even more of a functional language. What do I mean? I suggest a function that generates a complex number. This would have the form
(c <real digit list><real expon><imag digit list><imag expon><base>)
If the number base is not supplied it defaults to 10.
If exponents are not supplied they default to being equal to the number of digits in the digit list before them.
If a digit list is not supplied it defaults to '(0).
Negative bases, digits and exponents are all allowed.
With these rules here are some examples of numbers:
23 -> (c '(2 3))
-4 -> (c '(-4))
12.34 -> (c '(1 2 3 4) 2)
-12.34 -> (c '(-1 -2 -3 -4) 2)
1.3e3 -> (c '(1 3) 4) one notes the exponent is 1 larger
56i -> (c nil nil '(5 6))
0.78i -> (c nil nil '(7 8) 0)
1.2+8.3i -> (c '(1 2) 1 '(8 3) 1)
3AB base 12 (c '(3 10 11) nil nil nil 12)
The point here is not to demand that everyone start writing their numbers this way but to allow them to in those cases where the person wants total control of the number down to the digits and the base. This might not seem important but I think people will find clever things to do with it. This function will of course output a list with all the parts of the complex number. The math functions will have to be rewritten to take this list as input as well as the standard format numbers. There should also be two other functions
(numeric-output-standard)
(numeric-output-complex)
These would act as toggles to decide how the math functions are going to output their results, as normal numbers or complex number lists. When the user writes (numeric-output-complex) all the functions will return complex lists until they call (numeric-output-standard) again. The default is standard of course.
We also need conversion between standard and complex numbers with
(standardtocomplex n)
(complextostandard n)
So (standardtocomplex 1.2) -> ((1 2) 1 (0) 1 10)
and (complextostandard ((1 2) 1 (0) 1 10)) -> 1.2
5. NUMERIC CONDITIONAL STATEMENTS
I would like to suggest adding two numeric condtional statements that I have found extremely handy to have. First
(<=> x y A B C)
This statement means:
If (< x y) return the evaluation of A
If (= x y) return the evaluation of B
If (> x y) return the evaluation of C
And second,
(signcond x A B C)
This is similar to the first function but means
If x is negative return the evaluation of A
If x is zero return the evaluation of B
If x is positive return the evaluation C
Well I am probably wearing out my welcome with too many suggestions but I look forward to the commentary.