Jump to content

Recommended Posts

Posted (edited)

Hi.

How do I get the varaible name that holds the resault of "max" function?

 

Example:

(setq var1 1)
(setq var2 8)
(setq var3 2)

(setq lst (list var1 var2 var3))
(setq rsltmx (apply 'max lst))

;;the return is 8
;;I need to get "var2".

 

I'm using this:

           (setq i 1)   
           (foreach cnx lst
             (if (= cnx rsltmx)
               (progn
                (setq titlever (STRCAT "VAR" (rtos i 2 0)))
                (setq ix i) 
               );progn
             );if
             (setq i (1+ i))
           );foreach

This requires that all variables have the same prefix and end with consecutive numbers.

I'm looking for a more "direct" way that will not depends on fixing the names of the variables and their position in the list by their suffix.

 

any ideas?

 

thanks,

aridzv.

Edited by aridzv
Posted (edited)

Hi
' (setq var (max var1 var2 var3... varn)) '

Edited by GLAVCVS
Posted

@GLAVCVS

it gives the max value,

not the var name that holds that value...

 

thanks,

aridzv

Posted
(nth (vl-position (max var1 var2 var3 var4) (list var1 var2 var3 var4) (list "var1" "var2" "var3" "var4")) 

This is one of the possible ways

  • Like 1
Posted

Another way...

 

(strcat "var" (itoa (1+ (vl-position (max var1 var2 var3 var4) (list var1 var2 var3 var4)))) 

 

Posted (edited)

@GLAVCVS

Thanks!!

your first one worked.

 

here:

(setq as 1)
(setq df 8)
(setq io 3)
(setq varx (nth (vl-position (max as df io) (list as df io)) (list "as" "df" "io"))))

 

(The second is the same principle as my function)

 

thanks,

aridzv.

Edited by aridzv

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...