Author Topic: (project?) standard library?  (Read 2645 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10634
(project?) standard library?
« on: May 27, 2004, 10:27:50 AM »
I was gonna just share the following procedures as just stuff i had laying arround but would anybody be intrested in sharing their or helping collect general procedures like these?

***

A while ago i spent some time and started working on "standard" procedures i could use in a ".dll" of sorts. I noticd i had this file in my lisp dir and i wanted to share these with all of you.

Most are pretty general (well actualy, they came from a file called "general.l" so... :D) and some are pretty dumb, but i like to share cause you never know if someone can use these.

Enjoy...

Code: [Select]
;;; variable-p
;;; Test to see if item is a variable or not.
;;; Returns - bool
(defun variable-p (a) (not (null a)))

;;; same-variable
;;; Test to see if two variables are equal.
;;; Returns - bool
(defun same-variable (a b) (and (variable-p a) (variable-p b) (eq a b)))

;;; number-p
;;; Tests to see if the given is a number.
;;; returns - bool
(defun number-p (a) (eq (type a) 'INT))

;;; make-product
;;; Takes two numbers and forms a multiplication process
;;; Returns - process
(defun make-product (a b) (list '* a b))

;;; pair?
;;; Test to see if an object is infact a pair or entities.
;;; Ex:
;;; (pair? '(1 2))
;;; > T
(defun pair? (x) (and (car x) (cadr x)))

;;; sum-p
;;; test to see if given process is summation
;;; returns - bool
(defun sum-p (x) (and (pair? x) (eq (car x) '+)))

;;; product-p
;;; test to see if given process is multplication
;;; returns - bool
(defun product-p (x) (and (pair? x) (eq (car x) '*)))

;;; block-p
;;; test to see of given is a block
;;; Returns - bool
(defun block-p (x)
  (and (caddr (nentselp (cadr x)))))

;;; ### The following is a process demonstration ###
;;; will take a list (1 2 3 4 5 6 7 8 9) and tell you if each item
;;; in the list is greater then the number you want.
;;; -e.g. (High-Low '(1 2 3 4) 2)
;;;    -> (L H H H)
(defun High-Low (lst num)
  (setq newlist (cons (if (>= (car lst) num) 'H 'L) newlist))
  (if (> (length (cdr lst)) 0)
    ;; itterate thru again if the remanter of the list is greater then 0
    (High-Low (cdr lst) num))
  (reverse newlist)
  )

;;; var-store
;;; Store a variable in a dotted list format. Name and value
(defun var-store (var value)
  (cond ((and value) (cons var value))
        ((cons var (getvar var)))))

;;;===================================================================;
;;; List Position                                                     ;
;;;-------------------------------------------------------------------;
;;; This procedure will search a list for a given item and retrun the ;
;;; first position in the list where the item occures.                ;
;;;                                                                   ;
;;; Author: John Kaul (Se7en)                                         ;
;;;===================================================================;
(defun listpos (lst item)
  (if (member item lst) (- (length lst) (length (member item lst)))))

;;; ### The following are a few examples attempting to take a
;;;     step towards "safer" general process' ###
(defun getpoin7 (/ x)
  (while (not (setq x (getpoint)))
         (princ "\nYou missed, try again.")) x)

(defun entse7 (/ x)
  (while (not (setq x (car (entsel))))
    (princ "\nYou missed, try again.")) x)

(defun StartPT (ent) (cdr (assoc 10 (entget ent))))

(defun EndPT (ent) (cdr (assoc 11 (entget ent))))

(defun GetLyr (ent)
  (cdr (assoc 8 (entget ent))))

(defun GetRotDeg (ent)
    (* 180.0 (/ (cdr (assoc 50 (entget ent))) pi)))

(defun GetRotRad (ent)
    (cdr (assoc 50 (entget ent))))

(defun GetTxt (ent) (cdr (assoc 1 (entget ent))))

(defun GetEntColor (ent)
  (cond (ent (cdr (assoc 62 (entget (car ent)))))))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
(project?) standard library?
« Reply #1 on: May 27, 2004, 10:34:06 AM »
(number-p 12.6)  ;; =>> would be nil ?????
 
(numberp 12.6)  ;; =>> T is a built in function
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JohnK

  • Administrator
  • Seagull
  • Posts: 10634
(project?) standard library?
« Reply #2 on: May 27, 2004, 10:39:02 AM »
yes 12.6 would be nil.

Oh yeah i forgot about him.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org