using a 'variable' function

Discussion in 'AutoCAD' started by David Kozina, Dec 15, 2003.

  1. David Kozina

    David Kozina Guest

    Say that in a particular context, you need to call a custom or built-in
    function: DoX. In a different context, you need to call function: DoY. In
    yet a different context, you need to call function: DoZ. All the functions
    use a similar set of arguments, but use them in different ways. (I may
    later review how easy it would be to combine the different functions into
    one single function - but for now assume that they are different enough so
    as to justify BEING separate functions, (Example: +, -, * all use numerical
    arguments, but do different things with them)).

    The code below works, but I was wondering if this is the best way to do it,
    or if there is a better or simpler method for doing this...

    What may be obvious to you is most likely invisible to me.

    (setq
    Do_func
    (cond
    ; case Context1 applies
    (Context1
    'DoX
    );_end case
    ; case Context2 applies
    (Context2
    'DoY
    );_end case
    ; case Context3 applies
    (Context3
    'DoZ
    );_end case
    ; default case Unknown Context
    (T
    nil
    );_end case
    );_end cond
    );_end setq
    ; ...function identified?
    (if Do_func
    ; then
    (apply
    Do_func
    (list
    Argument1
    Argument2
    [...]
    )
    )
    )

    Any suggestions appreciated.

    Best regards,
    David Kozina
     
    David Kozina, Dec 15, 2003
    #1
  2. David Kozina

    John Uhden Guest

    I guess you could:
    (defun DoWhat (What Args)
    (apply What Args)
    )

    But it seems a lot easier to just call the right function without another
    wrapper.
     
    John Uhden, Dec 17, 2003
    #2
  3. David Kozina

    David Kozina Guest

    John,

    Nice idea for a wrapper, thanks.
    At least, it looks like I was going about using apply correctly.
    (I wasn't sure if there was another (more compact) way using a different
    built-in function).

    Best regards,
    David Kozina


     
    David Kozina, Dec 17, 2003
    #3
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.