TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ArgV on October 24, 2009, 02:56:28 AM

Title: ADDING a function to VLISP libary
Post by: ArgV on October 24, 2009, 02:56:28 AM
I think there is a way to do this, but I can't remember. I want to take some of the commands I've made and add them to VLISP standard library (even so they turn blue when typed).

I've been making several small functions that I would like to use, even if I have to import them, but want to use them in compilations.

thanks!

-ArgV
Title: Re: ADDING a function to VLISP libary
Post by: Kerry on October 24, 2009, 03:26:52 AM
Have a play with something like this ..
Code: [Select]
(vl-load-com)
(setq *temp-symbols* '(fun_1 fun_2 fun_3 fun_4 fun_5))
(eval
  (list 'pragma (list 'quote (list (cons 'unprotect-assign *temp-symbols*))))
)
;;;-----------------------------------------------------------------------------------
;;;-----------------------------------------------------------------------------------
;; add the defuns here < snip >

(defun fun_1 () (princ "fun 1") (princ))

(defun fun_2 (p1 p2) (princ "fun 2") (princ))

(defun fun_3 (a b) (princ "fun 3") (princ))

(defun fun_4 () (princ "fun 4") (princ))


;;;-----------------------------------------------------------------------------------
;;;-----------------------------------------------------------------------------------
(eval (list 'pragma (list 'quote (list (cons 'protect-assign *temp-symbols*)))))
(setq *temp-symbols* nil)
Title: Re: ADDING a function to VLISP libary
Post by: alanjt on October 24, 2009, 04:25:06 PM
Have a play with something like this ..
Code: [Select]
(vl-load-com)
(setq *temp-symbols* '(fun_1 fun_2 fun_3 fun_4 fun_5))
(eval
  (list 'pragma (list 'quote (list (cons 'unprotect-assign *temp-symbols*))))
)
;;;-----------------------------------------------------------------------------------
;;;-----------------------------------------------------------------------------------
;; add the defuns here < snip >

(defun fun_1 () (princ "fun 1") (princ))

(defun fun_2 (p1 p2) (princ "fun 2") (princ))

(defun fun_3 (a b) (princ "fun 3") (princ))

(defun fun_4 () (princ "fun 4") (princ))


;;;-----------------------------------------------------------------------------------
;;;-----------------------------------------------------------------------------------
(eval (list 'pragma (list 'quote (list (cons 'protect-assign *temp-symbols*)))))
(setq *temp-symbols* nil)

Incredible, I had no idea you could do something like this. Are there any adverse effects?
Title: Re: ADDING a function to VLISP libary
Post by: ArgV on October 24, 2009, 04:56:25 PM
Have a play with something like this ..
Code: [Select]
(vl-load-com)
(setq *temp-symbols* '(fun_1 fun_2 fun_3 fun_4 fun_5))
(eval
  (list 'pragma (list 'quote (list (cons 'unprotect-assign *temp-symbols*))))
)
;;;-----------------------------------------------------------------------------------
;;;-----------------------------------------------------------------------------------
;; add the defuns here < snip >

(defun fun_1 () (princ "fun 1") (princ))

(defun fun_2 (p1 p2) (princ "fun 2") (princ))

(defun fun_3 (a b) (princ "fun 3") (princ))

(defun fun_4 () (princ "fun 4") (princ))


;;;-----------------------------------------------------------------------------------
;;;-----------------------------------------------------------------------------------
(eval (list 'pragma (list 'quote (list (cons 'protect-assign *temp-symbols*)))))
(setq *temp-symbols* nil)

Sweet, that is a good step in the right direction. Now, of course, to take it a step further, is it possible to include my functions with the (vl-load-com) statement, or can I make my own version of the (vl-load-com) statement to use to import my functions?

Thank you very much. I learned all kinds of stuff looking up these new subrs, but most of it talks about objectARX, which I haven't started using quite yet.

-ArgV
Title: Re: ADDING a function to VLISP libary
Post by: Kerry on October 24, 2009, 05:01:31 PM
>>>
Incredible, I had no idea you could do something like this. Are there any adverse effects?

No adverse effects.

Title: Re: ADDING a function to VLISP libary
Post by: Kerry on October 24, 2009, 05:05:10 PM
>>>
Sweet, that is a good step in the right direction. Now, of course, to take it a step further, is it possible to include my functions with the (vl-load-com) statement, or can I make my own version of the (vl-load-com) statement to use to import my functions?

Thank you very much. I learned all kinds of stuff looking up these new subrs, but most of it talks about objectARX, which I haven't started using quite yet.

-ArgV

>>>  is it possible to include my functions with the (vl-load-com) statement

Sorry, don't understand your intent.


>>>  can I make my own version of the (vl-load-com) statement to use to import my functions?

Sorry, don't understand your intent.


>>> I learned all kinds of stuff looking up these new subrs, but most of it talks about objectARX

This is just basic VisualLisp, nothing to do with ObjectARX.


Title: Re: ADDING a function to VLISP libary
Post by: alanjt on October 24, 2009, 10:35:16 PM
Is this kind of what you had in mine ArgV?

Code: [Select]
(defun AT-Load-Com (/ #Dir #List)
  (cond
    ((setq #Dir (findfile "c:\\AlanThompson\\LSP\\_Subs"))
     (foreach x (vl-directory-files #Dir)
       (if (wcmatch (strcase x) "*.LSP")
         (load (strcat #Dir "\\" x) nil)
       ) ;_ if
     ) ;_ foreach
     (setq #List (mapcar 'read
                         (vl-remove-if-not
                           '(lambda (x) (wcmatch (strcase x) "AT*"))
                           (atoms-family 1)
                         ) ;_ vl-remove-if-not
                 ) ;_ mapcar
     ) ;_ setq
     (eval (list 'pragma (list 'quote (list (cons 'unprotect-assign #List)))))
     (eval (list 'pragma (list 'quote (list (cons 'protect-assign #List)))))
     T
    )
  ) ;_ cond
) ;_ defun

This is what I was thinking for myself. Load all my subroutines in my _Subs folder, then create a list, based on what matches "AT*" from (atoms-family 1) and add them accordingly.

Is there a way to check if a function is already assigned? If i run this a second time (not that I would need to) and vlide is open, I have to OK through redefining each.
Title: Re: ADDING a function to VLISP libary
Post by: Kerry on October 25, 2009, 12:04:22 AM
Alan,
The process required is to
unprotect-assign the symbol name,
define the function or variable (symbol name),
protect-assign the symbol name.

so your best methodology may be to add the pragma to the head and tail of each function definition or each file.

something like this
Code: [Select]
;;;---------------------------------------
(pragma '((unprotect-assign HelloWorld)))

(defun HelloWorld () (alert "Hello World!"))

(pragma '((protect-assign HelloWorld)))

;;;---------------------------------------

(pragma '((unprotect-assign kg:270 kg:180 kg:90 kg:45)))

(setq kg:270 (* pi 1.5))
(setq kg:180 (* pi 1.0))
(setq kg:90  (* pi 0.5))
(setq kg:45  (* pi 0.25))

(pragma '((protect-assign kg:270 kg:180 kg:90 kg:45)))

;;;---------------------------------------

(princ)

ADDED PICCY :
Title: Re: ADDING a function to VLISP libary
Post by: Lee Mac on October 25, 2009, 08:46:07 AM
Kerry,

Interesting thread, never really thought about doing something like this.  :-)

Is there any documentation available for the pragma function that you know of?

Thanks

Lee
Title: Re: ADDING a function to VLISP libary
Post by: Kerry on October 25, 2009, 04:12:00 PM

No documentation as far as I know Lee.
It's a carry over from Vital Lisp by Basis Software who sold what became Visual Lisp to AutoDesk. ( about 1995 if I recall).
I have the manuals boxed away 'somewhere' I think.
Title: Re: ADDING a function to VLISP libary
Post by: DEVITG on October 25, 2009, 09:27:21 PM
After a Search .

I got it

http://msdn.microsoft.com/en-us/library/sctyh01s%28VS.80%29.aspx

If you use the intrinsic pragma (or /Oi) to tell the compiler to generate intrinsic functions (intrinsic functions are generated as inline code, not as function calls), you can use the function pragma to explicitly force a function call. Once a function pragma is seen, it takes effect at the first function definition containing a specified intrinsic function. The effect continues to the end of the source file or to the appearance of an intrinsic pragma specifying the same intrinsic function. The function pragma can be used only outside of a function — at the global level.

For lists of the functions that have intrinsic forms, see #pragma intrinsic.
 Example
Title: Re: ADDING a function to VLISP libary
Post by: Kerry on October 25, 2009, 10:08:05 PM

No documentation as far as I know Lee.
It's a carry over from Vital Lisp by Basis Software who sold what became Visual Lisp to AutoDesk. ( about 1995 if I recall).
I have the manuals boxed away 'somewhere' I think.

ok, a revised answer.

No documentation from AutoDesk relating explicitly to VLisp as far as I know Lee.  :)
Title: Re: ADDING a function to VLISP libary
Post by: TimSpangler on October 26, 2009, 07:27:48 AM
So maybe Its because I haven't had my morning java yet, ....but.....what's the value of doing t his?
Title: Re: ADDING a function to VLISP libary
Post by: Kerry on October 26, 2009, 08:34:16 AM

I use it for library functions Tim.
Because the functions Symbol name is protected, any attempt to redefine the function will generate a warning.
... handy sometimes.
Title: Re: ADDING a function to VLISP libary
Post by: TimSpangler on October 26, 2009, 10:55:03 AM
Ah...Gotcha!

Thanks  8-)
Title: Re: ADDING a function to VLISP libary
Post by: JohnK on October 26, 2009, 01:29:02 PM
Ah...My take on the situation (1 cent worth):
I have added a custom syntax group in my language syntax file for Vim for any personal library functions i have built (more project based then generic--i dont use a global lib-.). This way im allowed to color my syntax groups separately; (if we are talking lisp) ``lispFunc'' may show up yellow while ``lispCustFunction'' can show green.

This way, i dont have just one barrel of functions.
Title: Re: ADDING a function to VLISP libary
Post by: ArgV on October 28, 2009, 11:58:31 PM
Is this kind of what you had in mine ArgV?

Code: [Select]
(defun AT-Load-Com (/ #Dir #List)
  (cond
    ((setq #Dir (findfile "c:\\AlanThompson\\LSP\\_Subs"))
     (foreach x (vl-directory-files #Dir)
       (if (wcmatch (strcase x) "*.LSP")
         (load (strcat #Dir "\\" x) nil)
       ) ;_ if
     ) ;_ foreach
     (setq #List (mapcar 'read
                         (vl-remove-if-not
                           '(lambda (x) (wcmatch (strcase x) "AT*"))
                           (atoms-family 1)
                         ) ;_ vl-remove-if-not
                 ) ;_ mapcar
     ) ;_ setq
     (eval (list 'pragma (list 'quote (list (cons 'unprotect-assign #List)))))
     (eval (list 'pragma (list 'quote (list (cons 'protect-assign #List)))))
     T
    )
  ) ;_ cond
) ;_ defun

This is what I was thinking for myself. Load all my subroutines in my _Subs folder, then create a list, based on what matches "AT*" from (atoms-family 1) and add them accordingly.

Is there a way to check if a function is already assigned? If i run this a second time (not that I would need to) and vlide is open, I have to OK through redefining each.

From only looking at it, and not running it, yes. I believe so. Just wanted my own "vl-load-com" to load because I've written alot of useful functions that I use alot. :)

thanks, if this is what I'm looking for. Won't know till tommorow. :(
Title: Re: ADDING a function to VLISP libary
Post by: ArgV on October 29, 2009, 12:03:02 AM
Ah...My take on the situation (1 cent worth):
I have added a custom syntax group in my language syntax file for Vim for any personal library functions i have built (more project based then generic--i dont use a global lib-.). This way im allowed to color my syntax groups separately; (if we are talking lisp) ``lispFunc'' may show up yellow while ``lispCustFunction'' can show green.

This way, i dont have just one barrel of functions.

Nice. :)
Title: Re: ADDING a function to VLISP libary
Post by: ArgV on October 29, 2009, 12:06:58 AM
>>>
Sweet, that is a good step in the right direction. Now, of course, to take it a step further, is it possible to include my functions with the (vl-load-com) statement, or can I make my own version of the (vl-load-com) statement to use to import my functions?

Thank you very much. I learned all kinds of stuff looking up these new subrs, but most of it talks about objectARX, which I haven't started using quite yet.

-ArgV



>>>  is it possible to include my functions with the (vl-load-com) statement

Sorry, don't understand your intent.


>>>  can I make my own version of the (vl-load-com) statement to use to import my functions?

Sorry, don't understand your intent.


>>> I learned all kinds of stuff looking up these new subrs, but most of it talks about objectARX

This is just basic VisualLisp, nothing to do with ObjectARX.




Sorry. I suck at writing what I want. (you have to see the hand gestures!)  :roll:

I think Alan got it. I've made a library of functions I would like to call. Some just take an argument and return something.. a list.. whatever. Just handy I guess.

-ArgV
Title: Re: ADDING a function to VLISP libary
Post by: alanjt on October 29, 2009, 08:45:17 AM
>>>
Sweet, that is a good step in the right direction. Now, of course, to take it a step further, is it possible to include my functions with the (vl-load-com) statement, or can I make my own version of the (vl-load-com) statement to use to import my functions?

Thank you very much. I learned all kinds of stuff looking up these new subrs, but most of it talks about objectARX, which I haven't started using quite yet.

-ArgV



>>>  is it possible to include my functions with the (vl-load-com) statement

Sorry, don't understand your intent.


>>>  can I make my own version of the (vl-load-com) statement to use to import my functions?

Sorry, don't understand your intent.


>>> I learned all kinds of stuff looking up these new subrs, but most of it talks about objectARX

This is just basic VisualLisp, nothing to do with ObjectARX.




Sorry. I suck at writing what I want. (you have to see the hand gestures!)  :roll:

I think Alan got it. I've made a library of functions I would like to call. Some just take an argument and return something.. a list.. whatever. Just handy I guess.

-ArgV

There's one problem with it, if you have one of the same loaded subs localized in a routine and vlide has been opened, it will give the redefine error.

I think my attempt was more proof-of-concept.
Title: Re: ADDING a function to VLISP libary
Post by: ArgV on October 31, 2009, 01:52:48 AM
>>>
Sweet, that is a good step in the right direction. Now, of course, to take it a step further, is it possible to include my functions with the (vl-load-com) statement, or can I make my own version of the (vl-load-com) statement to use to import my functions?

Thank you very much. I learned all kinds of stuff looking up these new subrs, but most of it talks about objectARX, which I haven't started using quite yet.

-ArgV



>>>  is it possible to include my functions with the (vl-load-com) statement

Sorry, don't understand your intent.


>>>  can I make my own version of the (vl-load-com) statement to use to import my functions?

Sorry, don't understand your intent.


>>> I learned all kinds of stuff looking up these new subrs, but most of it talks about objectARX

This is just basic VisualLisp, nothing to do with ObjectARX.




Sorry. I suck at writing what I want. (you have to see the hand gestures!)  :roll:

I think Alan got it. I've made a library of functions I would like to call. Some just take an argument and return something.. a list.. whatever. Just handy I guess.

-ArgV

There's one problem with it, if you have one of the same loaded subs localized in a routine and vlide has been opened, it will give the redefine error.

I think my attempt was more proof-of-concept.

Thats cool. I can roll with it. Now that I'm leaning OOP programming, I'm starting to appreciate the idea of overloaded functions. Oh well. :)