Author Topic: How to set function-help as CommonLisp?  (Read 955 times)

0 Members and 1 Guest are viewing this topic.

d2010

  • Bull Frog
  • Posts: 326
How to set function-help as CommonLisp?
« on: June 22, 2022, 01:10:41 PM »
Inside CommonLisp the comment ,imediatly after (defun  is God-revelation
Can I use this comment inside Vlisp inside Acad?
How to use?
The  "Usage:Text is not too long?
Code: [Select]
(defun regex (expression string)
  "Usage: (regex <expression> <string)
   This function will call regex-compile on the expression and then apply
   the string to the returned lambda list."
  (let ((findit (cond ((stringp expression)

(defun unique-dir-name ()
  "Return a name that can be used as a directory name that is
unique to a Lisp implementation, Lisp implementation version,
operating system, and hardware architecture."


(defun file-newer-p (new-file old-file)
  "Returns true if NEW-FILE is newer than OLD-FILE."
  (> (file-write-date new-file) (file-write-date old-file)))

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: How to set function-help as CommonLisp?
« Reply #1 on: June 22, 2022, 02:04:47 PM »
AutoLisp is not really set up to work that way because it is an interpreted language and prints all runtime errors to STDOUT (the command line of AutoCAD) by a simple error handler. A compiled program can toss errors to an error handler or ERRNO system or even toss exceptions to an exception handler established by the kernel (or some other means).

As an AutoLisp demonstration: You could use something like the following but your call to this function would always need to have an argument to have `myFunction` execute and evaluate the argument; otherwise the built in error handler takes over and displays a "too few arguments" error for the function call.

Code - Auto/Visual Lisp: [Select]
  1. (defun myFunction (expression)
  2.   (cond
  3.     ((not expression)
  4.      (princ "\nUsage: This function takes one argument \"<expression>\"") (princ))
  5.      (expression)
  6.      )
  7.   )

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: How to set function-help as CommonLisp?
« Reply #2 on: June 23, 2022, 07:48:58 PM »
Not sure what your after is this meant to be a help string for some one looking at code ?

Code: [Select]
(defun regex ( / )
;  Usage: (regex <expression> <string)
       This function will call regex-compile on the expression and then apply
       the string to the returned lambda list.;
 
(let ((findit (cond ((stringp expression)
)
A man who never made a mistake never made anything

baitang36

  • Bull Frog
  • Posts: 213
Re: How to set function-help as CommonLisp?
« Reply #3 on: June 24, 2022, 12:05:49 AM »
AutoLISP can write strings outside the parentheses, but it does nothing, which is equivalent to comments.

d2010

  • Bull Frog
  • Posts: 326
Re: How to set function-help as CommonLisp?
« Reply #4 on: June 27, 2022, 10:35:05 AM »
AutoLisp is not really set up to work that way because it is an interpreted language and prints
Thank you,
Gracis,,
That is solution. always I check the function the variabiles types.
Code - Auto/Visual Lisp: [Select]
  1. (setq winhelp (list ""))
  2. (Defun dfn_enamk_arc3d(p1 p2  p3 / $rr)
  3.  (command "_ucs" "_w")
  4.   (if (= p1 "--help")
  5.     (progn (setq winhelp (cons "\ndfn_enamk_arc3d create Arc3D:" winhelp))
  6.               (prompt (car winhelp))
  7.               (setq p1 (getpoint "Coordonate #1: "))
  8.     )
  9.   )
  10.  
  11.  (setq p2 (getpoint "Coordonate #2: "))
  12.  (setq p3 (getpoint "Coordonate #3: "))
  13.  (command "_ucs" "_3p" p1 p2 p3)
  14.  (command "_arc" (trans p1 0 1)(trans p2 0 1)(trans p3 0 1))
  15.  (command "_ucs" "_p")
  16.  (setq $rr (entlast))
  17. $rr)
  18.  
  19. (defun dfn_view_pnts(ljfour / $rr a b c d e f x)
  20.  (setq;|a000|;
  21.          b (getvar "VIEWSIZE")
  22.          $rr (getvar "SCREENSIZE")
  23.          c (car $rr)
  24.          d (cadr $rr)
  25.          a (/ (* b c) d)
  26.          x (getvar "VIEWCTR")
  27.          x (trans x 1 2)) (setq;|a67118225|;
  28.          c (list (- (car x) (/ a 2.0)) (- (cadr x) (/ b 2.0)) 0.0)
  29.          d (list (+ (car x) (/ a 2.0)) (+ (cadr x) (/ b 2.0)) 0.0)
  30.          c (trans c 2 1)
  31.          d (trans d 2 1)
  32.   )
  33.   (if (= ljfour "--help"))
  34.      (setq winhelp (cons "\ndfn_view_pnts='calculate Coordinate Ucs of Screen;" winhelp)
  35.             ljfour nil)
  36.   )
  37.   $rr (if ljfour (list c (list (car c) (cadr d) 0.0) (list (cadr c) (car d) 0.0) d) (if (=  ljfour 4) (list c (list (car c) (cadr d) 0.0) (list (cadr c) (car d) 0.0) d) (list c d))))
  38. $rr)
  39. ;Lib:free
  40.  
After-I call two function/s , then I display
(princ winhelp)
« Last Edit: June 27, 2022, 10:41:57 AM by d2010 »

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: How to set function-help as CommonLisp?
« Reply #5 on: June 27, 2022, 11:16:23 AM »
In other prgraming languages there is typically a "getopt" type of function where you can do something along the lines of:
(if (= argument "--help")... but you often find yourself building a series of checks for the same type but as different configurations. Example:
Code: [Select]
(if (= argument "--help")...
(if (= argument "-help")...
(if (= argument "--H")...
(if (= argument "-H")...
(if (= argument "help")...
(if (= argument "HELP")...
(if (= argument "?")...

this quickly become so cumbersome (for the programmer) you find yourself only dealing with "standard" type of argument syntaxes like "--help, --h, etc." but this is also not very useful (for the end-user). The example I gave above (is very, very crude) is how I would deal with the "help check" to create a sort of "assert" type function check. I choose to use COND because of what it returns and how it evaluates vs the IF statement.

To make things a bit more generic you can build a set of simple check procedures which will deal with more situations.
Code - Auto/Visual Lisp: [Select]
  1. ;; -Support routines.
  2. (set '#test
  3.         (lambda ( result expected )
  4.            (equal result expected)))
  5. (set '#assert
  6.          (lambda ( process expected consequent)
  7.            (cond ((#test (eval process) expected))
  8.                  ((eval consequent)))) )
  9. ;; -Example usage.
  10. ;;  (#assert "a" "1" '((princ "\nWrong argument") (princ)))

Now we can structure our code like this:

Code - Auto/Visual Lisp: [Select]
  1. (if (#assert "a" 1 '((princ "\nI have been given the wrong argument type.") (princ)))
  2.   (princ "\n \"a\" does equal 1 so I can run this portion of code now...")
  3.   )

We can also do more complicated checks like this:

Code - Auto/Visual Lisp: [Select]
  1. ;; -Support function which will always return 1.
  2. (defun myfunction (argument) 1)
  3.  
  4. ;; -Run a check to make sure the return of `myfunction` is equal to 1...
  5. (if (#assert
  6.      '(myfunction "b")
  7.      1
  8.      '((princ "\nI have been given the wrong argument type.") (princ)))
  9.   ;; -if test passes, run the following prompt.
  10.   (princ "\n \"myfunction\" does equal 1 so I can run this portion of code now...")
  11.   )

Not perfect, but this is the basis of an "assertion check".
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org