crazy_precisian Posted April 6, 2010 Posted April 6, 2010 Hi, I need to convert current function's name (defined by defun) into string and use this string within the function... Is it possible? Thanks a lot for answer! Quote
Lee Mac Posted April 6, 2010 Posted April 6, 2010 Using atoms-family is the only thing I can think of right now - why would you want to do this? Quote
jammie Posted April 6, 2010 Posted April 6, 2010 Could you post a sample code of what you are trying to achieve? Quote
jammie Posted April 6, 2010 Posted April 6, 2010 Something using reactors but I am not sure if its what you are after.. Catch is it only returns the inital function name ;Create a command reactor to watch for lisp functions (vlr-lisp-reactor nil '((:vlr-lispWillStart . storeFunctionName))) ;Store the command name in a global variable called *currentLispFunction* (defun storeFunctionName (<Reactor> <Command>) (setq *currentLispFunction* (car <Command>)) ) (defun c:test () (alert (strcat "\nFunction [" *currentLispFunction* "] started...")) ) Quote
crazy_precisian Posted April 6, 2010 Author Posted April 6, 2010 I am just beginner in AutoLISP and I thought there is easier way than reactors. Maybe I'll try to find different solution... Thanks a lot for your answers! Quote
Lee Mac Posted April 6, 2010 Posted April 6, 2010 Just curious, what are you trying to achieve? Quote
David Bethel Posted April 6, 2010 Posted April 6, 2010 Here's what I have: [color=#8b4513];converts a quoted symbol to a string[/color] [b][color=BLACK]([/color][/b]defun symstr [b][color=FUCHSIA]([/color][/b]name[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]= [b][color=MAROON]([/color][/b]type name[b][color=MAROON])[/color][/b] 'SYM[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b] [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]boundp name[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons '/ [b][color=RED]([/color][/b]atoms-family 0[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons '/ [b][color=RED]([/color][/b]cons name [b][color=PURPLE]([/color][/b]atoms-family 0[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]list setq name 0[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]list car [b][color=BLUE]([/color][/b]list atoms-family 1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] nil [b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] But your profile says LT? -David Quote
Lee Mac Posted April 6, 2010 Posted April 6, 2010 If you have the Symbol, could you not just use: (vl-princ-to-string sym) Quote
David Bethel Posted April 6, 2010 Posted April 6, 2010 If you have the Symbol, could you not just use: (vl-princ-to-string sym) Lee, You've got me. -David Quote
Lee Mac Posted April 6, 2010 Posted April 6, 2010 Nah - I know you don't have access to the VL functions David, it was a bit unfair on you. But, going back to your example - I can't quite understand the method that you are using, if you have a moment, would you mind explaining the thought process please? Quote
David Bethel Posted April 6, 2010 Posted April 6, 2010 Lee, I didn't write this one. But I think it first verifies the argument to be a symbol. Then check to see if it is bound to a value, if not simply add the symbol to atoms-family. I don't quite undertstand the setq name 0 statement. The last returns the newly added symbol as a string. -David Quote
Lee Mac Posted April 6, 2010 Posted April 6, 2010 OK I think I understand it now, this is how I understand it: ;converts a quoted symbol to a string (defun symstr (name) (if (= (type name) 'SYM) ( (list (if (boundp name) (cons '/ (atoms-family 0)) ; ==> (/ sym1 sym2 sym3 ... symN) (cons '/ (cons name (atoms-family 0))) ; ==> (/ name sym1 sym2 sym3 ... symN) ) (list setq name 0) (list car (list atoms-family 1)) ) ; If symbol has value: ; ( (lambda (/ sym1 sym2 sym3 ... symN) ; (setq name 0) ; (car (atoms-family 1)) ; Else: ; ( (lambda (/ name sym1 sym2 sym3 ... symN) ; (setq name 0) ; (car (atoms-family 1)) ) nil ) ) The list structure is that of a lambda function, and it sets all symbols to nil, then bounds the value 0 to the desired symbol - hence atoms-family will only return that symbol. However it seems to fail as "/" is contained in the atoms-family list as a symbol, and hence there is an error as two "/" symbols will be found in the arguments list. Lee Quote
David Bethel Posted April 6, 2010 Posted April 6, 2010 (snvalid "/") returns nil in 2000. Has that changed? (type '/) returns sym So I guess it needs a some additional parameter checking. -David Quote
Lee Mac Posted April 6, 2010 Posted April 6, 2010 (snvalid "/") ==> nil But '/' is a protected symbol and so will appear in the atoms-family list, so perhaps a vl-remove may be needed. Quote
Recommended Posts
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.