Author Topic: ADDING a function to VLISP libary  (Read 10218 times)

0 Members and 1 Guest are viewing this topic.

ArgV

  • Guest
ADDING a function to VLISP libary
« 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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ADDING a function to VLISP libary
« Reply #1 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)
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: ADDING a function to VLISP libary
« Reply #2 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?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ArgV

  • Guest
Re: ADDING a function to VLISP libary
« Reply #3 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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ADDING a function to VLISP libary
« Reply #4 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.

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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ADDING a function to VLISP libary
« Reply #5 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.


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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: ADDING a function to VLISP libary
« Reply #6 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.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ADDING a function to VLISP libary
« Reply #7 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 :
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.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: ADDING a function to VLISP libary
« Reply #8 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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ADDING a function to VLISP libary
« Reply #9 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.
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.

DEVITG

  • Bull Frog
  • Posts: 479
Re: ADDING a function to VLISP libary
« Reply #10 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
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ADDING a function to VLISP libary
« Reply #11 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.  :)
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.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: ADDING a function to VLISP libary
« Reply #12 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?
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ADDING a function to VLISP libary
« Reply #13 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.
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.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: ADDING a function to VLISP libary
« Reply #14 on: October 26, 2009, 10:55:03 AM »
Ah...Gotcha!

Thanks  8-)
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016