Format for dtr

Discussion in 'AutoCAD' started by Adesu, Jul 15, 2004.

  1. Adesu

    Adesu Guest

    Dear Lispers.
    I want ask you alls,how the best place of "dtr",before defun (format 1) or
    in defun (format 2),if it see in program procedure,thanks for your reply
    Best regards
    Ade Suharna

    format 1

    (defun dtr (a)
    (* pi (/ a 180.0)))
    (defun c:xx (/)
    bla...bla...
    )

    format 2

    (defun c:xx (/)
    (defun dtr (a)
    (* pi (/ a 180.0)))
    bla...bla...
    )
     
    Adesu, Jul 15, 2004
    #1
  2. Adesu

    Paul Turvill Guest

    It's a matter of preference, I guess. Either will make the (dtr ...)
    function available to other LISP routines, but format 2 will unnecessarily
    redefine the function every time you run command XX. If you're a stickler
    for "efficient" code, use format 1.
    ___
     
    Paul Turvill, Jul 15, 2004
    #2
  3. Adesu

    ECCAD Guest

    Ade,
    My 2 cents:
    I would say it depends. IF you are sending a program to someone (and it needs dtr..) then include it in the program. That way, you won't get beat-up for forgetting it..
    IF you are doing a larger process, using many programs, then, include it in some loaded utility.

    Bob
     
    ECCAD, Jul 15, 2004
    #3
  4. One key point that both Paul and Bob missed was that your sample for format
    2, as shown, will _definitely_ lead to bugs in the long run. Why? Because
    you did not declare the subroutine's symbol as local.

    So imagine this scenario for format 2, with two different .lsp files:

    (defun C:XX (/ x)
    (defun dtr (a)
    (* pi (/ a 180.0)))
    (setq x (dtr 30.0))
    ;| rest of code |;
    )

    (defun C:YY ()
    (defun dtr (a)
    (alert (strcat "My message is " a)))
    (dtr "I'm going to cause a bug.")
    ;| rest of code |;
    )

    The code loaded last will win, breaking the _other_ program.

    So, if you are going to embed subrs, either use names you know/guess will be
    unique, or declare them as local symbols.

    However, with (dtr), the subr will be used in many programs, so the best
    approach is to have that subr in a separate .lsp file altogether, and
    autoload the subr in the main functions. That way you need to maintain the
    actual (dtr) code in one place only.

    --
    R. Robert Bell


    Dear Lispers.
    I want ask you alls,how the best place of "dtr",before defun (format 1) or
    in defun (format 2),if it see in program procedure,thanks for your reply
    Best regards
    Ade Suharna

    format 1

    (defun dtr (a)
    (* pi (/ a 180.0)))
    (defun c:xx (/)
    bla...bla...
    )

    format 2

    (defun c:xx (/)
    (defun dtr (a)
    (* pi (/ a 180.0)))
    bla...bla...
    )
     
    R. Robert Bell, Jul 15, 2004
    #4
  5. Adesu

    ECCAD Guest

    <snip>IF you are doing a larger process, using many programs, then, include it in some loaded utility.<snip>
    I don't think the intention was to 'redefine' the rtd function,
    merely get it available.
    Your sample is 're-writing' the function, and in doing so, yes, the 'last' loaded will survive..perhaps yielding unexpected results.

    Bob
     
    ECCAD, Jul 15, 2004
    #5
  6. X-zarchary! ;^)

    --
    R. Robert Bell


    <snip>IF you are doing a larger process, using many programs, then, include
    it in some loaded utility.<snip>
    I don't think the intention was to 'redefine' the rtd function,
    merely get it available.
    Your sample is 're-writing' the function, and in doing so, yes, the 'last'
    loaded will survive..perhaps yielding unexpected results.

    Bob
     
    R. Robert Bell, Jul 15, 2004
    #6
  7. Adesu

    ECCAD Guest

    <Grin>
     
    ECCAD, Jul 15, 2004
    #7
  8. Adesu

    DEVItG Guest

    What do you mean????

    a degree to radian defun???
     
    DEVItG, Jul 19, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.