Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Kozina, David
Message 1 of 42 (43 Views)

APPLY function problem/strangeness...

43 Views, 41 Replies
01-05-2000 03:12 PM
Amigos,

I've come across the following AutoLISP strangeness/inconsistency in
R14.01 and ADT2, and I was wondering if any of you could
confirm/duplicate this behavior. Or perhaps clue me in as to if/where
this has been discussed before.

I noticed it whilst trying to program a check on a list of strings to
verify that no member is equivalent to "0" - but it seems that the
problem lies on a deeper level than that.

Here is a snip of my original function, which is supposed to take a
string like "FR10.0/15.0", split it up, then check to make sure it is
formatted correctly. [The function STD-STRTOK splits up a string (in
this case *FSM_STR*) based on a supplied delimeter (in this case the
"/"), and returns a list containing the substrings... IOW, (STD-STRTOK
"10.0/15.0" "/") -> ("10.0" "15.0")] :

(apply 'not (mapcar 'zerop (mapcar 'atof (STD-STRTOK (substr *FSM_STR*
3) "/"))))))

Perhaps there is a much better way to do this, but my point is that
entire construct is throwing out some strange error messages...

IOW, given any list: , I can't get:

(apply 'not )

to work in either R14.01 or ADT2

However, if I use 'null, instead, as in:

(apply 'null )

this DOES work in R14.01 - but NOT in ADT2. (?!)

I thought that just in case the STDLIB functions might *possibly* have
something to do with this, I decided to try it without them loaded up.
As you can see below, this made no difference.

Here are two snips from my command line
(Tried immediately after starting fresh sessions of AutoCAD):

----------------------------------------------------------------
R14.01 Command Line output:

...

Command: ARX

?/Load/Unload/Commands/Options: ?

Loaded Runtime Extension Programs:

acadapp.arx
acmted.arx
autocell.arx
doslib14.arx
livetext.arx
oleaprot.arx
qpik14.arx
toolr14.arx

End of List.

Command: (apply 'NOT '(1 2 3 4 5))
error: too many arguments
(NOT (<> 1) (<> 2) (<> 3)
(<>
#28f3e40> 4) (<> 5))
(APPLY (QUOTE NOT) (QUOTE (1 2 3 4 5)))
*Cancel*

Command: (apply 'NOT (list 1 2 3 4 5))
error: too many arguments
(NOT (<> 1) (<> 2) (<> 3)
(<>
#28f3e40> 4) (<> 5))
(APPLY (QUOTE NOT) (LIST 1 2 3 4 5))
*Cancel*

Command: (apply 'NULL '(1 2 3 4 5))
nil

Command: (apply 'NULL '(nil nil nil nil nil))
T

Command: (apply 'AND '(1 2 3 4 5))
T

Command: (apply 'AND '(1 NIL 3 4 5))
nil

Command: (apply 'OR '(1 NIL 3 4 5))
T

Command: (apply 'OR '(NIL NIL NIL NIL NLI))
nil

----------------------------------------------------------------
ADT2 Command Line output:

...

Command: arx

Enter an option [?/Load/Unload/Commands/Options]: ?

Loaded Runtime Extension Programs:

acadapp.arx - MDI Aware.
acdim.arx - MDI Aware.
aceplotx.arx - MDI Aware.
acetutil.arx - MDI Aware.
achapi15.dbx - MDI Aware.
achlnkui.arx - MDI Aware.
aecstartup.arx - MDI Aware.
appload.arx - MDI Aware.
doslib2k.arx - MDI Aware.
modemacro.arx - MDI Aware.
oleaprot.arx - MDI Aware.
qpik15.arx - MDI Aware.
stdlib15.arx - MDI Aware.
vl.arx - MDI Aware.

End of List.

Command: arx

Enter an option [?/Load/Unload/Commands/Options]: u

Enter ARX/DBX file name to unload: stdlib15.arx

stdlib15.arx successfully unloaded.

Command: (apply 'NOT '(1 2 3 4 5))
; error: too many arguments

Command: (apply 'NOT (list 1 2 3 4 5))
; error: too many arguments

Command: (apply 'NULL '(1 2 3 4 5))
; error: too many arguments

Command: (apply 'NULL '(nil nil nil nil nil))
; error: too many arguments

Command: (apply 'AND '(1 2 3 4 5))
T

Command: (apply 'AND '(1 nil 3 4 5))
nil

Command: (apply 'OR '(1 nil 3 4 5))
T

Command: (apply 'OR '(nil nil nil nil nil))
nil

----------------------------------------------------------------

This is really weird; (apply 'and... , as well as (apply 'or... ,
both work as I would expect, but not (apply 'not... [as well as (apply
'null... in ADT2)]

BTW, my 'puter OS is WinNT4.0 SP4, FWIW, and I'm using a plenty good
machine w/ plenty o' memory for this paltry exercise.

So, first of all, can anyone duplicate/very this behavior?

Is it possible that the problem could be related to one of the other
third party programs I'm using?
(I truly hope that this isn't the case.) Perhaps NOT (and NULL) have
been setq redefined somehow/somewhere? [I'm 99.999% certain my own
programs have not done this.]

If this is indeed an AutoCAD/AutoLISP bug, does anyone have a good
simple workaround for this?

Sorry for the long post, but I hope I have explained this sufficiently
well.

Appreciative of any assistance/feedback tracking down this problemo,
David Kozina
*Kozina, David
Message 2 of 42 (43 Views)

Re: APPLY function problem/strangeness...

01-06-2000 08:02 AM in reply to: *Kozina, David
So can anyone tell me what their R14 or AutoCAD 2000
Command Line outputs after each of the following inputs?:

(apply 'not '(1 2 3))

(apply 'null '(1 2 3))

Thanks,
David Kozina
*Muñoz, Eduardo
Message 3 of 42 (43 Views)

Re:

01-06-2000 08:14 AM in reply to: *Kozina, David
David Kozina escribió en mensaje <852e6h$9o320@adesknews2.autodesk.com>...
>So can anyone tell me what their R14 or AutoCAD 2000
>Command Line outputs after each of the following inputs?:
>
>
>(apply 'not '(1 2 3))
>
>
>(apply 'null '(1 2 3))
>

Acad 2000 (Plain _VERNUM = "T.0.98")

Command: (apply 'not '(1 2 3))
; error: too many arguments

Command: (apply 'null '(1 2 3))
; error: too many arguments

-------------------------------------------------------------

Acad 2000 (included with MDT 4.0 ; _VERNUM = "T.1.33")

Command: (apply 'not '(1 2 3))
; error: too many arguments

Command: (apply 'null '(1 2 3))
; error: too many arguments

------------------------------------------------------------

MDT 4.0 (_VERNUM = "T.1.33")

Command: (apply 'not '(1 2 3))
; error: too many arguments

Command: (apply 'null '(1 2 3))
; error: too many arguments

---------------------------------------

Acad 14 (Spanish ; _VERNUM = "S.0.80" )

Comando: (apply 'not '(1 2 3))
error: demasiados argumentos
(NOT (<> 1) (<> 2) (<> 3))
(APPLY (QUOTE NOT) (QUOTE (1 2 3)))
*Cancelar*

Comando: (apply 'null '(1 2 3))
nil

Eduardo Muñoz
*Oquendo, Frank
Message 4 of 42 (43 Views)

Re:

01-06-2000 08:44 AM in reply to: *Kozina, David
I keep getting "too many arguments" but it is easily fixed by enclosing your
list in TWO sets of parens:

(apply 'not '((1 2 3)))
(apply 'null '((1 2 3)))

"David Kozina" wrote in message
news:852e6h$9o320@adesknews2.autodesk.com...
> So can anyone tell me what their R14 or AutoCAD 2000
> Command Line outputs after each of the following inputs?:
>
>
> (apply 'not '(1 2 3))
>
>
> (apply 'null '(1 2 3))
>
>
> Thanks,
> David Kozina
>
>
*Bell, R. Robert
Message 5 of 42 (43 Views)

Re:

01-06-2000 09:08 AM in reply to: *Kozina, David
Frank, I think what he is trying to do is get a T when an atom in a list is
nil. By nesting the list within another one, he never gets that test. I
think I see what he is getting at.

If you do an (apply 'and '(1 2)) you get T, expected behavior.
If you do an (apply '+ '(1 2)) you get 3, expected behavior.

If you do an (apply 'null '(1 2)) you get error: too many arguments, _why_?

I think this is a good question. This should be a simple way to test valid
atoms in a list, _if it worked_. How would you perform this test yourself?
--
R. Robert Bell, MCSE
Network Administrator & Top Gun
(remove the not. for e-mail)

Frank Oquendo wrote in message
news:852h0a$bq31@adesknews2.autodesk.com...
> I keep getting "too many arguments" but it is easily fixed by enclosing
your
> list in TWO sets of parens:
>
> (apply 'not '((1 2 3)))
> (apply 'null '((1 2 3)))
>
>
> "David Kozina" wrote in message
> news:852e6h$9o320@adesknews2.autodesk.com...
> > So can anyone tell me what their R14 or AutoCAD 2000
> > Command Line outputs after each of the following inputs?:
> >
> >
> > (apply 'not '(1 2 3))
> >
> >
> > (apply 'null '(1 2 3))
> >
> >
> > Thanks,
> > David Kozina
> >
> >
>
>
*Oquendo, Frank
Message 6 of 42 (43 Views)

Re:

01-06-2000 09:42 AM in reply to: *Kozina, David
The why of the matter was so simple, I chided myself for missing it. Apply
is not meant to be used with unary operators. + as well as AND expect
mutiple operands. NOT and NULL expect only one. Here's a little routine to
indicate whether a list contains one or more nil values:

(defun ContainsNil (lst / item retVal)
(foreach item lst
(if (not item) (setq retVal T))
)
retVal
)

"R. Robert Bell" wrote in message
news:852ia5$bq53@adesknews2.autodesk.com...
> Frank, I think what he is trying to do is get a T when an atom in a list
is
> nil. By nesting the list within another one, he never gets that test. I
> think I see what he is getting at.
>
> If you do an (apply 'and '(1 2)) you get T, expected behavior.
> If you do an (apply '+ '(1 2)) you get 3, expected behavior.
>
> If you do an (apply 'null '(1 2)) you get error: too many arguments,
_why_?
>
> I think this is a good question. This should be a simple way to test valid
> atoms in a list, _if it worked_. How would you perform this test yourself?
> --
> R. Robert Bell, MCSE
> Network Administrator & Top Gun
> (remove the not. for e-mail)
*Buturovic, Adi
Message 7 of 42 (43 Views)

Re: APPLY function problem/strangeness...

01-06-2000 09:54 AM in reply to: *Kozina, David
In r14 both (not item) and (null item) are supposed to accept only one
argument.
(null) doesn't return an error when supplied with more than one argument (is
it bug?), but evaluates only the first one.

So, I wouldn't use (apply 'null [or 'not] list) in the first place.

to check for zeroes in the list, I would use
(apply 'or (mapcar 'zerop numlist))

--
Adi Buturovic
af.buturovic@berwanger.com
****************************************
Berwanger Inc. is not responsible for any opinion, recommendation,
solicitation, offer or agreement or any information contained in this
communication.

David Kozina wrote in message
news:850j2l$7gc7@adesknews2.autodesk.com...
> Amigos,
>
> I've come across the following AutoLISP strangeness/inconsistency in
> R14.01 and ADT2, and I was wondering if any of you could
> confirm/duplicate this behavior. Or perhaps clue me in as to if/where
> this has been discussed before.
>
> I noticed it whilst trying to program a check on a list of strings to
> verify that no member is equivalent to "0" - but it seems that the
> problem lies on a deeper level than that.
[snip]
*Oquendo, Frank
Message 8 of 42 (43 Views)

Re: APPLY function problem/strangeness...

01-06-2000 09:55 AM in reply to: *Kozina, David
Haven't seen you in a while. Did you Enjoy the holidays?

"Michael Puckett" wrote in message
news:852l39$bq413@adesknews2.autodesk.com...
> or ...
>
> (defun HasNil (lst)
> (apply 'or (mapcar 'null lst))
> )
*Puckett, Michael
Message 9 of 42 (43 Views)

Re:

01-06-2000 09:56 AM in reply to: *Kozina, David
or ...

(defun HasNil (lst)
(apply 'or (mapcar 'null lst))
)

________________________________

puckettm@bantrel.com
> Not < an AutoDESK classroom monitor
Imagination makes all things possible
________________________________

Frank Oquendo wrote in message <852kdq$bq310@adesknews2.autodesk.com>...
The why of the matter was so simple, I chided myself for missing it. Apply
is not meant to be used with unary operators. + as well as AND expect
mutiple operands. NOT and NULL expect only one. Here's a little routine to
indicate whether a list contains one or more nil values:

(defun ContainsNil (lst / item retVal)
(foreach item lst
(if (not item) (setq retVal T))
)
retVal
)
*Whaley, Frank
Message 10 of 42 (43 Views)

Re: APPLY function problem/strangeness...

01-06-2000 10:01 AM in reply to: *Kozina, David
David Kozina wrote:

> I've come across the following AutoLISP strangeness/inconsistency in
> R14.01 and ADT2 ...

You've uncovered a difference between AutoLISP and Visual LISP, which might
be considered a defect in AL.

There are a number of AL functions which are defined as taking one
argument, but do not complain if additional arguments are supplied.
'(null)' is one such function.

When you write:

(apply 'null '(nil T))

you are actually evaluating:

(null nil T)

In AL the NIL argument will be evaluated (returning T) and the T argument
will be ignored. In VL you will receive a "too many arguments" error.

Given that your:

(mapcar 'zerop ...)

code returns a list of NIL or T values and any T value indicates an invalid
value, you should use:

(not (apply 'or (mapcar 'zerop ...)))
--
Frank Whaley
Autodesk, Inc.
few@autodesk.com
http://www.autodesk.com/expresstools
Express Tools - Your wish is our (command ...)
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.