Author Topic: Well tested common functions library - should we have it?  (Read 16496 times)

0 Members and 1 Guest are viewing this topic.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Well tested common functions library - should we have it?
« Reply #15 on: December 07, 2013, 05:28:15 AM »
2. Consistent naming scheme? You now have predicate functions with names that do not end in '-p'.
Which?
consp
some
every

divtiply

  • Guest
Re: Well tested common functions library - should we have it?
« Reply #16 on: December 07, 2013, 06:53:30 AM »
They are standard CL names. As null, for example.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Well tested common functions library - should we have it?
« Reply #17 on: December 07, 2013, 07:41:11 AM »
Have seen so many try-outs -- ALL have failed.

Pretty much this -- a six member committee with 12 legs -- will try to walk in as many directions -- good luck.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Well tested common functions library - should we have it?
« Reply #18 on: December 07, 2013, 08:04:17 AM »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Well tested common functions library - should we have it?
« Reply #19 on: December 07, 2013, 08:09:27 AM »
BTW: My (roy_some_2) has a problem:
Code: [Select]
(defun MyFunc (a) (if (numberp a) (1+ a)))
(roy_some_2 'MyFunc '("a" "b" "c" "d" 0)) => 1
(roy_some_2 'MyFunc '("a" "b" "c" 0)) => T

New version:
Code - Auto/Visual Lisp: [Select]
  1. (defun roy_some_2_Revised (pred lst / res)
  2.   (setq pred (eval pred))
  3.   (while
  4.     (and
  5.       (cadddr lst)
  6.       (not
  7.         (setq res
  8.           (cond
  9.             ((pred (car lst)))
  10.             ((pred (cadr lst)))
  11.             ((pred (caddr lst)))
  12.             ((pred (cadddr lst)))
  13.           )
  14.         )
  15.       )
  16.     )
  17.     (setq lst (cddddr lst))
  18.   )
  19.   (if (not res)
  20.     (while
  21.       (and
  22.         (car lst)
  23.         (not (setq res (pred (car lst))))
  24.       )
  25.       (setq lst (cdr lst))
  26.     )
  27.   )
  28.   res
  29. )

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Well tested common functions library - should we have it?
« Reply #20 on: December 07, 2013, 09:16:09 AM »
Roy,

Why "cad....r" and not "nth #"  much easier to read a number then how many "d's" to use. 

Bruce

divtiply

  • Guest
Re: Well tested common functions library - should we have it?
« Reply #21 on: December 07, 2013, 11:34:18 AM »
Why "cad....r" and not "nth #"

"cad...r" functions are faster than "nth n" equivalents.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Well tested common functions library - should we have it?
« Reply #22 on: December 07, 2013, 11:42:10 AM »
Roy,

Why "cad....r" and not "nth #"  much easier to read a number then how many "d's" to use. 

Bruce

Apart from the issue of speed there also this:
On line 5 of (roy_some_2_revised) I have:
Code: [Select]
(cadddr lst)Because lst can be or become nil (nth) cannot be used here:
Code: [Select]
(nth 3 nil) => Error
(cadddr nil) => nil

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Well tested common functions library - should we have it?
« Reply #23 on: December 07, 2013, 02:13:09 PM »
Roy,

Thanks for the explanation, I did not know about the nil/error difference.

Bruce

Jeremy

  • Guest
Re: Well tested common functions library - should we have it?
« Reply #24 on: December 07, 2013, 07:06:24 PM »
I share some of DIVTIPLY's concerns. There are a great many functions on this board that have been optimized and benchmarked but can be impossible to find unless you know they exist. It would be nice if there could be a place to drop the most optimized version of various functions in one spot where you can see them all categorized. This would of course need updating as new people submit better algorithms. We could suggest that people use these functions in submitted code so that one is not constantly bothered with making sure every subfunction to a given function is included. A lot of repetitious space is being used over and over again.

Setting some rules for function naming is important because Autolisp is kind of a mess in that regard. Predicate functions are indeed not consistent and I have ended all of mine with a question mark rather than -p. I think "number?" is more quickly recognized as an inquiry than "numberp" is. Perhaps I am excessive but I also wrote replacements for the operators and booleans that have no "p" at all. So I have "less?" as well as "<" and "wcmatch?" instead of "wcmatch". Rather than "First","Second","Third" I would gravitate towards "1st","2nd" and "3rd" as they are shorter and I believe the digits are more rapidly comprehended than the words.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Well tested common functions library - should we have it?
« Reply #25 on: December 09, 2013, 03:56:22 AM »
FWIW: Another look at the (some) function.

Code: [Select]
(vl-some 'atom nil)              => nil
(divtiply_some 'atom nil)        => T
(roy_some_1 'atom nil)           => T
(roy_some_2_Revised 'atom nil)   => nil
(roy_some_1_Revised_2 'atom nil) => nil
(roy_some_2_Revised_2 'atom nil) => nil

(vl-some 'atom '(nil))              => T
(divtiply_some 'atom '(nil))        => T
(roy_some_1 'atom '(nil))           => T
(roy_some_2_Revised 'atom '(nil))   => nil
(roy_some_1_Revised_2 'atom '(nil)) => T
(roy_some_2_Revised_2 'atom '(nil)) => T

(vl-some 'numberp '(nil nil 0 . 0))              => T
(divtiply_some 'numberp '(nil nil 0 . 0))        => T
(roy_some_1 'numberp '(nil nil 0 . 0))           => T
(roy_some_2_Revised 'numberp '(nil nil 0 . 0))   => Error
(roy_some_1_Revised_2 'numberp '(nil nil 0 . 0)) => T
(roy_some_2_Revised_2 'numberp '(nil nil 0 . 0)) => T

(vl-some 'numberp '(nil nil . 0))              => nil
(divtiply_some 'numberp '(nil nil . 0))        => Error
(roy_some_1 'numberp '(nil nil . 0))           => Error
(roy_some_2_Revised 'numberp '(nil nil . 0))   => Error
(roy_some_1_Revised_2 'numberp '(nil nil . 0)) => nil
(roy_some_2_Revised_2 'numberp '(nil nil . 0)) => nil

Code - Auto/Visual Lisp: [Select]
  1. (defun roy_some_1_Revised_2 (pred lst / res)
  2.   (setq pred (eval pred))
  3.   (while
  4.     (and
  5.       (vl-consp lst)
  6.       (not (setq res (pred (car lst))))
  7.     )
  8.     (setq lst (cdr lst))
  9.   )
  10.   res
  11. )
  12.  
  13. (defun roy_some_2_Revised_2 (pred lst / res)
  14.   (setq pred (eval pred))
  15.   (while
  16.     (and
  17.       (vl-consp lst)
  18.       (vl-consp (cdr lst))
  19.       (vl-consp (cddr lst))
  20.       (vl-consp (cdddr lst))
  21.       (not
  22.         (setq res
  23.           (cond
  24.             ((pred (car lst)))
  25.             ((pred (cadr lst)))
  26.             ((pred (caddr lst)))
  27.             ((pred (cadddr lst)))
  28.           )
  29.         )
  30.       )
  31.     )
  32.     (setq lst (cddddr lst))
  33.   )
  34.   (if (not res)
  35.     (while
  36.       (and
  37.         (vl-consp lst)
  38.         (not (setq res (pred (car lst))))
  39.       )
  40.       (setq lst (cdr lst))
  41.     )
  42.   )
  43.   res
  44. )

ymg

  • Guest
Re: Well tested common functions library - should we have it?
« Reply #26 on: December 09, 2013, 05:20:31 AM »
Here some revised ceil and floor function.

These you may attribute to me although probably was done before.

Code - Auto/Visual Lisp: [Select]
  1. (defun floor (x) (if (minusp (rem x 1)) (- (fix x) 1) (fix x)))
  2. (defun ceil  (x) (if (> (rem x 1) 0) (+ (fix x) 1) (fix x)))
  3.  

@divtiply
As an aside, it would certainly have been appreciated if you had let me know
in the Poisson Disk Sampling thread about the problem.

ymg
« Last Edit: December 09, 2013, 05:28:51 AM by ymg »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Well tested common functions library - should we have it?
« Reply #27 on: December 09, 2013, 06:34:58 AM »
Since the OP is a BricsCAD user this may be of interest:

BricsCAD uses OpenLisp as the basis for its Lisp-engine:
http://www.eligis.com/
OpenLisp is an ISLISP implementation:
http://islisp.info/

To be compatible with AutoLisp some functionality from the underlying Lisp-engine is blocked in BricsCAD. Which can be a frustrating idea if you goal is to extend the Lisp-library.

Note: there is also a different OpenLISP:
http://www.openlisp.org/

Edit: Typo.
« Last Edit: December 09, 2013, 10:09:33 AM by roy_043 »

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Well tested common functions library - should we have it?
« Reply #28 on: December 09, 2013, 07:39:32 AM »
Roy,

A little off subject, but do you know if OpenLisp from your last post supports DCL use.

Bruce

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Well tested common functions library - should we have it?
« Reply #29 on: December 09, 2013, 10:29:28 AM »
do you know if OpenLisp from your last post supports DCL use.
DCL is unique to AutoCAD and some other .dwg software. So the answer is: No.