See the top rated post in this thread. Click here

View Poll Results: This pole is a mistake, sorry for any inconvenience

Voters
0. You may not vote on this poll
  • na

    0 0%
  • na 2

    0 0%
Results 1 to 5 of 5

Thread: Help with Defun Argument

  1. #1
    Active Member
    Join Date
    2004-10
    Location
    Wheat Ridge, Colorado
    Posts
    97
    Login to Give a bone
    0

    Default Help with Defun Argument

    All,

    At the risk of getting another wrist slapping, I am looking for some help understanding why the attached routine doesn't work. I am sure that my explanation will not use all of the correct technical AutoLISP terminolgy, so please have patience.

    I am simply trying to hand an argument to the routine and print a phase based on the argument supplied. I can get it to work, but only once. After the variable var1 is set it won't change. So if I hand "yes" to the function on the first run, it always prints "yes". I added var1 to the VLIDE watch dialogue, but the value in the display is always nil.

    What am I missing?

    As always, thanks in advance.
    Attached Files Attached Files

  2. #2
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    1

    Default Re: Help with Defun Argument

    Hi Jeff,

    There is a syntax problem with your COND statement, consider the following code:

    Code:
    (defun test ( var1 )
      (print var1)
      (cond
        ( (= var1 "yes")
          "The Variable is YES"
        )
        ( (= var1 "no")
          "The Variable is NO"
        )
      )
    )
    Testing:

    Code:
    _$ (test "yes")
    
    "yes" "The Variable is YES"
    _$ (test "no")
    
    "no" "The Variable is NO"
    _$ (test "Yes")
    
    "Yes" nil
    I would suggest you read the Visual LISP IDE (VLIDE) Help Documentation regarding the syntax of the COND function, if you haven't already done so. A short tutorial detailing how to access this can be found on my site here.

    If you have any questions about anything I have posted, just ask.

    Lee

  3. #3
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default Re: Help with Defun Argument

    The Modifications are shown in colors:
    Code:
    (defun c:test (/ var1)
    ;  (print var1)
    (setq var1 (getstring "\nEnter the value: "))
     
      (progn
    ;   (cond
        (if (= var1 "yes")
         (print "The variable is YES")
         );end if
        (if (= var1 "no")
         (print "The variable is NO")
         );end if
        (if (and (/= var1 "yes")(/= var1 "no"))
       (print "Take care with your input!")
       );end if
     
    ; (nil)
    ;     );end cond
        );end progn
     
    (princ)
      );end defun

  4. #4
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Help with Defun Argument

    BoKirra,

    I believe Jeff was intending to pass an argument (or parameter) to the function defined as 'test':

    Quote Originally Posted by jeff.richards View Post
    I am simply trying to hand an argument to the routine and print a phase based on the argument supplied. I can get it to work, but only once.
    Furthermore, I would argue that a single COND statement for this scenario is far better practice than multiple IF statements.

    Lee

  5. #5
    Active Member
    Join Date
    2004-10
    Location
    Wheat Ridge, Colorado
    Posts
    97
    Login to Give a bone
    0

    Default Re: Help with Defun Argument

    Lee and Bokirra,

    Thanks for the replies. I'm sorry my response has taken so long.

    Lee is correct, I wanted to hand an argument to a function as a test. I have reviewed the documentation and now I understand. I was in a sense trying to test within the test; completely un-needed.

    Bokirra's solution also sheds light on the fact that I misused cond in my example, where only one expression was expected.

    Thanks Again,

    Jeff

Similar Threads

  1. Nesting Defun with Arguments and Variables
    By Jeff@BOC in forum AutoLISP
    Replies: 10
    Last Post: 2014-04-16, 12:46 AM
  2. Defun error
    By Tharwat in forum AutoLISP
    Replies: 10
    Last Post: 2010-07-16, 09:00 AM
  3. Defun Quickie
    By jeff.richards in forum AutoLISP
    Replies: 8
    Last Post: 2010-02-02, 11:31 PM
  4. Having some Issues with defun
    By KGC in forum AutoLISP
    Replies: 10
    Last Post: 2008-05-20, 03:30 PM
  5. Explain the difference between defun and defun c
    By David van Erk in forum AutoLISP
    Replies: 6
    Last Post: 2007-06-08, 09:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •