newLISP and AutoCAD

Notices and updates
Locked
Jeremy Dunn
Posts: 95
Joined: Wed Oct 13, 2004 8:02 pm
Location: Bellingham WA

newLISP and AutoCAD

Post by Jeremy Dunn »

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.

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Hello Jeremy,

wellcome to the board.

I come from a similar background and also do a lot of Autolisp-programming.
When you perform a search here on the forum for 'Autolisp' then you get some threads over a long time.

There are thread's about getting more Autolisp compatible commands like 'setq' and other's.

>Is it possible to interact with AutoCAD using newLISP?

Not in the easy way like visual lisp/autolisp. But why search a replacment for them.
They do a fine job in Autocad. In the newer releases of
ACAD, which are more based on the .NET-framework, you maybe able to
embed newLISP.dll in .NET to mix a .NET-GUI with lisp-code.

My intention for using newLISP is for jobs where I want to port Autolisp
logic to programms to outside of ACAD, where I need a embedable
lisp-interpreter. We have now a lot of programming enviroments where
you can use newlisp.

What I like on newLISP is the incredible small size and the speed for an
interpreted lisp, multiplatform and the great flexibility.
Hans-Peter

Jeremy Dunn
Posts: 95
Joined: Wed Oct 13, 2004 8:02 pm
Location: Bellingham WA

Post by Jeremy Dunn »

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.

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

>AutoLISP is very handy but it needs to be improved

Of cource you are right! But for some political reasons they
seems to think in other directions at autodesk.

There is only the inventor and VB hype.

They do not improve lisp and they does not fix serious DCL bugs.
What would be possible for small business and single acad user
to develop own utilitys when they would get a DCL based on latest
GUI-developments in the MS-world.

But that another story and off-topic.

So in the moment the only way to get into autocad is COM or .NET
to use the 'modern' interfaces they provide.
Hans-Peter

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

Jeremy, I have just tried to redefine the arithmetic operator *:

Code: Select all

(define-macro (redef old-fn new-fn pre post)
  (if (not (lambda? (eval old-fn)))
    (begin
      (constant (global (sym (append (or pre "old-") (string old-fn) (or post "")))) (eval old-fn))
      (constant old-fn (eval new-fn)))))

(define (new*)
  (if (= (length (args)) 1)
    (old-* 2 ((args) 0))
    (apply old-* (args))))
Now, type:
> (* 3)
3
> (redef * new*)
(lambda ... )
> (* 3)
6

Where is the problem?
> (time (dotimes (x 500000) (old-* 5 3)))
63
> (time (dotimes (x 500000) (* 5 3)))
485

See also the post:
http://www.alh.net/newlisp/phpbb/viewtopic.php?t=764

Fanda

Jeremy Dunn
Posts: 95
Joined: Wed Oct 13, 2004 8:02 pm
Location: Bellingham WA

Post by Jeremy Dunn »

Thanks for the suggestion. I ultimately decided to write a doubling and halving function.

Code: Select all

;;Divide a number in half. Uses bit shifting if x is an integer
(define (hlf x)
  (if (integer? x)(>> x 1)(mul x 0.5)))

;; Double a number or take the product of several numbers and then double it.
;; If given a single integer bit shifting is used for greater speed
;; (dbl 3 2 1) -> 12
;; (dbl 4) -> 8
(define-macro (dbl)
 (if (= 1 (length (args)))
  (begin
    (setq x (first (args)))
    (if (integer? x)(<< x 1)(add x x)))
  (mul 2 (apply mul (args)))))

Locked