Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 3
Anonymous
804 Views, 2 Replies

AutoLSP

Help I need somebody [The Beatles]

 

In Common LISP I can write SETQL (set quote literally)

macro like this:

 

(defmacro setql (var val)
     `(setq ,var ',val)             ;;;backquote syntax
)

 

Let's try it:

 

Invocation

(setql a (+ 1 2 3 4 5 6 7 8 9 10))    ;;;Note; Second argument is not quoted

Evaluation

a --> (+ 1 2 3 4 5 6 7 8 9 10)      ;;; not 55

 

Can I write similar DEFUN form in AutoLISP .... ????

 

(defun setql (var val) ..........)

 

Sorry my English is baaaa.......d but I hope that somebody can

understand what I am looking for.

 

KM

 

 

2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

Hi,

 

There's no defmacro function in AutoLISP, but you can create a custom setql function (although you can name it whatever you want). However, in AutoLISP things are a little bit different. Setql won't assign the value to a, which is only an argument and it's lost after being passed to the setql function. So you still have to assign the value returned by setql to another variable (let's say b), by using setq:

(defun setql (var val)
  (setq var val)
)

(setq b (setql a (+ 1 2 3 4 5 6 7 8 9 10)))

Command:(eval b) -> Enter
55

 

HTH

Message 3 of 3
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

....

In Common LISP I can write SETQL (set quote literally) macro....

(defmacro setql (var val)
     `(setq ,var ',val)             ;;;backquote syntax
)

....

Invocation

(setql a (+ 1 2 3 4 5 6 7 8 9 10))    ;;;Note; Second argument is not quoted

Evaluation

a --> (+ 1 2 3 4 5 6 7 8 9 10)      ;;; not 55

....


Am I correct that you want the 'a' variable to be set to (+ 1 2 3 4 5 6 7 8 9 10), not set to 55?  SomeBuddy's suggestion doesn't do that, but sets not just (eval b), but also the 'b' variable itself, to 55.  If that's all you need, you could of course omit the 'b' surroundings and any special (setql) function, and just use your invocation above, but with (setq) without the 'l'.

 

I haven't found a way to do what I think you want, but I expect if there is one, it's going to involve (set) rather than (setq), and some way of converting your 'a' argument perhaps into a string and using (read) on it, or something, so as to get it into a symbol name independent of the argument.  I also tried using (quote val) to put that unquoted list argument, rather than 55, into a variable, but of course that just returns VAL, not the contents of the 'val' argument to the function.

 

I'll keep thinking about it, but you may be stuck with quoting the second argument.  If so, there's no need for a setql function -- you would just use:

 

(setq a '(+ 1 2 3 4 5 6 7 8 9 10))

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost