Passing A Function to a Function

Discussion in 'Cadence' started by Edward, Mar 8, 2008.

  1. Edward

    Edward Guest

    (defun ekdToggle (f @optional (valuesPair (list t nil)))
    "When you want the OTHER value a function returns."
    (car (remove (f) valuesPair)))
    *Error* eval: undefined function - f

    Hey! What gives?
     
    Edward, Mar 8, 2008
    #1
  2. Edward

    S. Badel Guest

    (defun ekdToggle (f @optional (valuesPair (list t nil)))
    The value of f is a symbol. The symbol's function slots contains the actual address of the function
    to be called.

    When you do (f) you are accessing the function slot of the symbol f, which is not what you intend to do.

    What you should do is use funcall(f) or apply(f args).

    Note that, when valuePair is '(t nil), it's equivalent to a not(), just a little overkill.

    Cheers,
    Stéphane
     
    S. Badel, Mar 8, 2008
    #2
  3. Edward

    cadence Guest

    If you write this in SKILL++ it will work as long as you omit the
    quote.

    (defun ekdToggle (f @optional (valuesPair (list t nil)))
    (car (remove (f) valuesPair)))

    (ekdToggle leIsInstSelectable) ;; no quote before function name.



    Just but the code in a file with .ils extension or surround the
    code with (inScheme ...)

    In many was the SKILL++ dialect of SKILL is sort of what you
    intuitively expect. I'm not sure why it is not used more often.
     
    cadence, Mar 9, 2008
    #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.