Autolisp versus Common Lisp

Autolisp versus Common Lisp

stanovb
Advocate Advocate
923 Views
7 Replies
Message 1 of 8

Autolisp versus Common Lisp

stanovb
Advocate
Advocate

I am reading a book called "Common Lisp A Gentle Introduction" by David S. Touretzky. Its a very good book for beginners in my opinion. It really does go into lisp & how computers deal with data & symbols in detail, but common lisp does have some functions that aren't included in Autolisp. Does anyone know if there is a website with a  database somewhere that would tell you what the alternative to the functions that aren't included would be? For instance Common Lisp has a function called REDUCE that reduces the elements of a list into a single result. 

 

(reduce #’+ ’(1 2 3)) => 6

What would the Autolisp equivalent be?

 

Also the function REMOVE-IF  takes a predicate as input. REMOVE-IF removes all the items from a list that satisfy the predicate, and returns a list of what’s left.

 

> (remove-if #’numberp ’(2 for 1 sale))
(FOR SALE)

 

These are just a few examples, but I was wondering if there was a site that would tell you instead of using REMOVE-IF, in Autolisp you need to use ....

0 Likes
924 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor
0 Likes
Message 3 of 8

diagodose2009
Collaborator
Collaborator

I hope , other/s have  same-options/

The programe Vlide + VC ,(optional BricsCad) -- for Vlisp  are top-proffesional/s for debugger/s-Lisp

. In my belief; Vlide+ VC+2024- is the "winner from all existing LISP/s on entire web; after 50years exists theLISP;language

---even-if Nasa from USA use commonLISP , GnuLisp or other LISP- do not beat these VLISDE+VC,.

🤔

 

 

0 Likes
Message 4 of 8

Sea-Haven
Mentor
Mentor

This is add up numbers in a list (apply '+ lst)

0 Likes
Message 5 of 8

_gile
Consultant
Consultant

@stanovb  a écrit :

For instance Common Lisp has a function called REDUCE that reduces the elements of a list into a single result. 

 

(reduce #’+ ’(1 2 3)) => 6

What would the Autolisp equivalent be?


From the List library at the bottom of this page which contains many other LISP functions to manage lists (the last ones mimic some F# List module functions).

;; gc:fold
;; Retourne l'état final d'un accumulateur dont l'état initial est modifié
;; par l'application d'une fonction à chacun des éléments d'une liste
;;
;; Arguments
;; fun : la fonction à appliquer à chaque élément
;; acc : l'accumulateur
;; lst : la liste
(defun gc:fold (fun acc lst / f)
  (setq f (eval fun))
  (foreach n lst (setq acc (f acc n)))
)

;; gc:reduce
;; Retourne l'état final d'un accumulateur résultat de l'application
;; d'une fonction à chacun des éléments d'une liste
;;
;; Arguments
;; fun : la fonction à appliquer à chaque élément
;; lst : la liste
(defun gc:reduce (fun lst)
  (gc:fold fun (car lst) (cdr lst))
)

 


@stanovb  a écrit :

Also the function REMOVE-IF  takes a predicate as input. REMOVE-IF removes all the items from a list that satisfy the predicate, and returns a list of what’s left.

 

> (remove-if #’numberp ’(2 for 1 sale))
(FOR SALE)


See vl-remove-if built-in function.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 8

stanovb
Advocate
Advocate

That's a good one. It sounds like there is no easy answer. Someone said in the other thread that common lisp is so much bigger than Autolisp that it would be easier to come up with the functions that are the same than it would be to come up with the alternatives. Ill just have to look through my copies of The Visual Lisp Developers Bible & the ABCs of Autolisp & find something close.

0 Likes
Message 7 of 8

Sea-Haven
Mentor
Mentor

Over at The Swamp is a forum called Lisp\Challenges and there are many sub functions posted there to do with manipulating Lists. If you want some thing else it may exist there or ask.

0 Likes
Message 8 of 8

martti.halminen
Collaborator
Collaborator

 

(defun reduce (func data / res)
  ;; Limited version of CL:REDUCE, no keyword parameters, lists only.
  ;; Usage: (reduce list '(1 2 3 4)) -> (((1 2) 3) 4). 
  ;; (reduce * '(1 2 3 4 5)) -> 120
  (cond ((null data) (func))
        ((null (cdr data)) (car data))
        (T (setq res (func (car data)(cadr data)))
           (foreach item (cddr data)
             (setq res (func res item)))
           res)))

Some difference to CL due to it having different namespaces for functions vs values, unlike Visual Lisp.

Here the function name without any quotation, i.e. as an evaluated value.

 

Some of the other CL functions are defined in Visual Lisp with a vl- prefix, i.e. SOME -> VL-SOME etc., though there are differences due to Visual Lisp limitations, so usually only the basic case without keyword parameters is supported.

 

0 Likes