Re: automatically call functions based on arguments



normanj <nii2awh@xxxxxxxxx> writes:


Now, the presence of these digits is strange.  Couldn't they be
parameters to the functions?  Do you have a lot of them?

Sorry, those digits should be replaced with normal strings.
All those parameters have nothing to do with the parameters
of functions/macros, they are only related with their names.
Yes, maybe hundreds.



(defvar *name-to-function-map*
  '((aa func-aa)
    (bb func-bb)
    (cc func-cc)))

(defun call-function (name arguments)
   (let ((fun  (cdr (assoc name *name-to-function-map*))))
      (if fun
        (apply fun arguments)
        (error "No user function named ~S" name))))

(call-function 'aa 1 2)
(call-function (read) (read) (read))


This could be taken as a solution.

Given the number of functions, it might be worthwhile to use a
hash-table for the map.

(defvar *name-to-function-map*
(make-hash-table :test (function equal))) ; case sensitive strings, or else equalp
(dolist (pair '( (func-aa-1-2 . (aa one two)) ; which is the same to write (func-aa aa one two)
(func-bb-3-2 . (bb three two))
... ))
(setf (gethash (cdr pair) *name-to-function-map*) (car pair)))

and then use (gethash name *name-to-function-map*) instead of (cdr (assoc ...)),
with name bound to (aa one two), etc.

--
__Pascal Bourguignon__
.



Relevant Pages

  • Re: What is the problem with this ?
    ... for all arithmetic calculations. ...   First, getting somebody to make you a prototype. ... digits but you would apparently be forced to represent large numbers ... according to some rule and the result stored in another register. ...
    (sci.electronics.design)
  • Re: TWO AMENDMENTS NEEDED IN MACRO - PLEASE HELP
    ... Excel 556987 - Page 1.xlsm ... the button then macro opens that file for me. ... one put 6 digits like "Excel " macro should not open the file and it ...
    (microsoft.public.excel.programming)
  • Re: solving two of nonlinear equations and two unknwons.
    ... Solves a nonlinear least squares problem subject to bounds on the ... digits, and f values in processing are: ... this would yield horribly wrong derivatives and hence chaotic ...
    (sci.math.num-analysis)
  • Re: OT: Got my stimulus money today!
    ... digits of your social security number and not by state. ... specifically put my direct deposit info on my unneeded tax form ...     If you had Direct Deposit ...
    (alt.fan.letterman)
  • Re: float confusion
    ... -- integer type does not raise overflow constraint_error ...    procedure SimpleCompute is ... float grows to the full 13 digits before I stop ...
    (comp.lang.ada)