Author Topic: Using Apply with SSGET - what am I missing?  (Read 240 times)

0 Members and 1 Guest are viewing this topic.

mkweaver

  • Bull Frog
  • Posts: 344
Using Apply with SSGET - what am I missing?
« on: May 31, 2019, 12:13:34 PM »
I have a routine that builds a list of arguments for SSGET resulting in this:
Code - Auto/Visual Lisp: [Select]
  1. ((0 . "LINE") (-3 ("MyAppName")))

When I try to use Apply to feed these to SSGET, like so:
Code - Auto/Visual Lisp: [Select]
  1. (APPLY 'SSGET '((0 . "LINE") (-3 ("MyAppName"))))

I get this:
Quote
_$ (APPLY 'SSGET '((0 . "LINE") (-3 ("MyAppName"))))
bad point argument

If I drop the APPLY then it works fine:
Code - Auto/Visual Lisp: [Select]
  1. (SSGET '((0 . "LINE") (-3 ("MyAppName"))))

What am I doing wrong?

gile

  • Water Moccasin
  • Posts: 2222
  • Marseille, France
Re: Using Apply with SSGET - what am I missing?
« Reply #1 on: May 31, 2019, 12:49:42 PM »
Hi,

You can think that:
Code - Auto/Visual Lisp: [Select]
  1. (apply 'SomeFunction argList)
works like:
Code - Auto/Visual Lisp: [Select]
  1. (eval (cons 'SomeFunction argList))


So,
Code - Auto/Visual Lisp: [Select]
  1.  (apply 'ssget '((0 . "LINE") (-3 ("MyAppName")))))
works like:
Code - Auto/Visual Lisp: [Select]
  1. (eval (cons 'ssget '((0 . "LINE") (-3 ("MyAppName")))))
>>
Code - Auto/Visual Lisp: [Select]
  1. (eval '(ssget (0 . "LINE)  (-3 ("MyAppName"))))
>>
Code - Auto/Visual Lisp: [Select]
  1. (ssget (0 . "LINE)  (-3 ("MyAppName")))


So, if you need to use apply, you should do:
Code - Auto/Visual Lisp: [Select]
  1. (apply 'ssget '(((0 . "LINE") (-3 ("MyAppName")))))
or, more explicitly:
Code - Auto/Visual Lisp: [Select]
  1. (apply 'ssget (list '((0 . "LINE") (-3 ("MyAppName")))))
« Last Edit: May 31, 2019, 01:01:02 PM by gile »
Speaking English as a French Frog

gile

  • Water Moccasin
  • Posts: 2222
  • Marseille, France
Re: Using Apply with SSGET - what am I missing?
« Reply #2 on: May 31, 2019, 01:17:43 PM »
In other words, when you do:
Code - Auto/Visual Lisp: [Select]
  1. (apply 'SomeFunction argList)
argList is the list of the arguments required by SomeFunction.
In your case, '((0 . "LINE") (-3 ("MyAppName")) is the only argument of the ssget function.
So you need to wrap it in a list when using with apply.
Speaking English as a French Frog

mkweaver

  • Bull Frog
  • Posts: 344
Re: Using Apply with SSGET - what am I missing?
« Reply #3 on: June 03, 2019, 11:57:01 AM »
Thanks, Gile.  That got me looking in the right direction.

Mike