Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Jeremy Dunn

#91
Anything else we might add? /
October 17, 2004, 03:14:37 PM
Quote from: "Lutz"The nice thing about LISP and Scheme is, that the syntax rules are very simple : the first list member is the functor/operator and the rest are the parameters/arguments. The only difference between LISP and Scheme/newLISP is that Scheme and newLISP evaluate the first list member first before applying it to the parameters:



;; newLISP and Scheme evaluate the operator part first (other LISPs don't):

((if (> A B) + *) A B)

;; in this example A and B are added if A > B else multiplied


Most of Jeremy's suggestions could be implemented by defining functions or macros for it, i.e:



(define (<=> x y A B C)
   (if
    (< x y) A
    (= x y) B
    (> x y) C))

(<=> 3 4 10 20 30) => 10
(<=> 4 4 10 20 30) => 20
(<=> 5 4 10 20 30) => 30


In newLISP you also have the possibility to redefine the built-in functions using 'constant'. Doing this and using functions and macros, you can completely tailor a language to your own taste, which is the reason people use these kind of languages in the first place, because they let you define your own language appropiate to the problem area you are developing in.



Lutz


Please forgive my poor AutoLISP addled brain, I am having to learn a new way to think here. Your example has a statement that in purest form is

(if a b c d e f). I thought an if statement can have only 3 arguments. I take it it keeps grabbing them and interprets it as (if a b (if c d (if e f)))? But I thought all the other functions left associate as in

(fn (fn (fn a b) c) d) is if an exception or am I just lost?
#92
newLISP newS /
October 17, 2004, 02:57:10 PM
I find the complaint about the factorial function a little ridiculous. For most normal situations it is probably more efficient to have the function look up a precalculated value from a table rather than brute force it every time. How high do we need to go, factorial 200? Use Sterling's formula for an approximate value or code your problem in Mathematica if you are trying to some weird number theory thing. Yes it would be fun to have bignums integrated but give Lutz some time, Perl didn't start out perfect either.
#93
Anything else we might add? / Syntax Suggestions
October 16, 2004, 10:15:54 AM
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.
#94
newLISP newS /
October 14, 2004, 06:52:45 AM
The main reason I'm interested in alternatives is I find myself cut off at the knees as it were on many occasions. I find the lack of optional arguments in AutoLISP extremely irritating. I think if I have another person tell me to just pass them as a list I'm going to scream. Yes, AutoLISP is very handy but it needs to be improved.
#95
newLISP newS / newLISP and AutoCAD
October 13, 2004, 01:18:16 PM
Hi, I'm a newbie to newLISP and am looking forward to playing with it. About time someone came up with something like this!



I typically program in AutoLISP in AutoCAD. Autodesk is trying to get everyone into the VB/VBA universe, but we lispers are not giving up without a fight! Is it possible to interact with AutoCAD using newLISP? Can you get and set properties/methods? If so, I can almost gaurantee a lot of interest from the CAD programmers since most of us prefer LISP but are continually frustrated by Autodesk programmers not taking us seriously and giving us a better LISP to work with.



As long as I'm here can I suggest some further defaults for some of your arithmetic operators?



Let



(* x) = (* 2 x)

(/ x) = (/ 1 x)

(div x) = (/ x 2)

(pow x) = (pow x 2)



These are very simple and handy to have.