lousy at math

Discussion in 'AutoCAD' started by sunnysidedown, Jan 28, 2008.

  1. Command: (load "phi")
    ; error: LOAD failed: "phi"

    Command: phi
    1.61803

    Command:
    Command: '_.help
    Command: (* phi 2)
    ; error: bad argument type: numberp: nil

    Command: (* (phi) 2)
    ; error: no function definition: PHI

    Command: phi
    1.61803

    Command:
    Command: PHI 1.61803

    Command:


    my acaddoc.lsp has this in it..... (defun c:phi () (/ (+ 1 (sqrt 5)) 2))

    am scratching head as to why i cant times it by two.. or three, or ....
    which part of code did i write wrong? did it on fly. seems to me, that i should simply be able to
    :: (* phi 2) (times phi by two)

    oh well.
     
    sunnysidedown, Jan 28, 2008
    #1
  2. I think the problem is that you haven't set a variable to hold the real
    number. The function returns the value, but only when you run it, and I
    don't think you can run it when it's a term in another function. Try running
    this:

    (defun c:phunction ( / ) (setq phi (/ (+ 1 (sqrt 5)) 2)))

    Now you can summon the vaule stored in phi from other functions during the
    drawing session. I also think it's a problem to have the function and the
    variable have the same name. If you want to use the value of phi in other
    functions, name this function something else.
     
    Michael Bulatovich, Jan 28, 2008
    #2
  3. sunnysidedown

    Bill DeShawn Guest

    (defun c:phi () (setq phi (/ (+ 1 (sqrt 5)) 2)))
    The function name won't interfere with the variable name, so if
    sunnysidedown wants to have a "phi" function and variable, it'll be
    OK.
     
    Bill DeShawn, Jan 29, 2008
    #3
  4. That's what I thought, but it didn't work until I changed it...That's why I
    said "I think".
    --


    MichaelB
    www.michaelbulatovich.ca

    (defun c:phi () (setq phi (/ (+ 1 (sqrt 5)) 2)))
    The function name won't interfere with the variable name, so if
    sunnysidedown wants to have a "phi" function and variable, it'll be
    OK.
     
    Michael Bulatovich, Jan 29, 2008
    #4
  5. sunnysidedown

    Bill DeShawn Guest

    Not being critical, just factual. You would be correct in assuming
    there would be interference IF the function name did not have "c:" in
    front of it.

    Bill DeShawn
    http://my.sterling.net/~bdeshawn
     
    Bill DeShawn, Jan 30, 2008
    #5
  6. Have you tried it named the same?\

    Not being critical, just factual. You would be correct in assuming
    there would be interference IF the function name did not have "c:" in
    front of it.

    Bill DeShawn
    http://my.sterling.net/~bdeshawn
     
    Michael Bulatovich, Jan 30, 2008
    #6
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.