Author Topic: How to loose a (function call  (Read 4193 times)

0 Members and 1 Guest are viewing this topic.

David Bethel

  • Swamp Rat
  • Posts: 656
How to loose a (function call
« on: August 13, 2013, 08:36:53 AM »
For those of us that don't have access to (function) ( it was introduced in the 2000s,  I don't know a Brisicad), I've been using global search and replace with (quote

Code: [Select]
  (defun nw_mid_ptf (s e)
     (mapcar (function (lambda (a b) (* (+ a b) 0.5))) s e))

  (defun nw_mid_pt (s e)
     (mapcar (quote (lambda (a b) (* (+ a b) 0.5))) s e))

  (setq p1 '(0 0 0) p2 '(1 1 0))
  (prin1 (nw_mid_pt p1 p2))


It seems to work fine so far.  Any reason this should fail ?


Finding the matching closing parentheses can be a pain ( and daunting ) if I just try to delete the front of the call.

-David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: How to loose a (function call
« Reply #1 on: August 13, 2013, 08:52:08 AM »
To avoid modifying the code, you could perhaps include the following in your ACADDOC.lsp:

Code: [Select]
(if (null function)
    (setq function quote)
)

David Bethel

  • Swamp Rat
  • Posts: 656
Re: How to loose a (function call
« Reply #2 on: August 13, 2013, 08:58:29 AM »
Thanks Lee,

That should work.  I have something similar for (snvalid).  R12 didn't have it.

-David
R12 Dos - A2K

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to loose a (function call
« Reply #3 on: August 13, 2013, 09:17:04 AM »
Very clever Lee.  8)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: How to loose a (function call
« Reply #4 on: August 13, 2013, 09:31:41 AM »
Cheers guys, happy to help  :-)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to loose a (function call
« Reply #5 on: August 13, 2013, 09:52:08 AM »
Another thing you might have to do: Seeing as defun before the VLisp extension was simply a special way of constructing a list to be used as a list for evaluation, there was a new one introduced called defun-q. You usually use it on special global functions if you want to append to them (e.g. s::startup). So using the same idea as Lee's:
Code: [Select]
(if (null defun-q)
  (setq defun-q defun)
)
Note though, I don't think any vl/vla/vlax functions were available in R12. AFAICR the first time they were available was with the 3rd party addon Vital Lisp for R13, only in R14/2000 did ADesk include Visual Lisp.

There are probably more as well. Would the dictionary routines be available in R12? dictnext, dictsearch, etc.

Another set which are definitely not in there is the layerstate routines. I don't think layer states were available before 2000, perhaps even later.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: How to loose a (function call
« Reply #6 on: August 13, 2013, 10:06:50 AM »
Thanks,
R12 did not have:

  • Any vl   thingys
  • dictionaries
  • *object* functions

(snvalid) was useful enough that I wrote my variation.  I didn't think any of the others were deal busters.  my$0.02

-David
R12 Dos - A2K

JohnK

  • Administrator
  • Seagull
  • Posts: 10655
Re: How to loose a (function call
« Reply #7 on: August 13, 2013, 11:14:55 AM »
Shameless plug:
That little program I wrote (LiFP) has a simplistic search and replace feature; I suppose you can use it to just search and replace for you but if I were you I would set up a project with it and see if it helps you any in the future. [-i.e. it supports all the preprocessor directives like: IFDEF, IFNDEF, DEFINE, ERROR, etc so you can have several outputs based on your current needs and never have to do mass changes like this ].

Example of above statement. Given this, you can call LiFP two different ways and have two different lisp files.
Code - Auto/Visual Lisp: [Select]
  1. ;...
  2. ;#ifdef USEALERT
  3. ;@ use this block if the USEALERT has been given.
  4. (defun sayHello ( str )
  5.   (alert str)
  6.   )
  7. ;#endif
  8.  
  9. (defun myfoo ( / )
  10.   (setq string1 "Hello"
  11.         string2 " world!")
  12.   ;#ifdef USEALERT
  13.   (sayHello (strcat string1 string2))
  14.   ;#endif
  15.   ;#ifndef USEALERT
  16.   (print-line string1)
  17.   (print-string string2)
  18.   ;#endif
  19.   (princ)
  20.  )
  21.  

Like:
Code - Auto/Visual Lisp: [Select]
  1. ;...
  2. (defun myfoo ( / )
  3.   (setq string1 "Hello"
  4.         string2 " world!")
  5.   (print-line string1)
  6.   (print-string string2)
  7.   (princ)
  8.  )
or:
Code - Auto/Visual Lisp: [Select]
  1. ;...
  2. (defun sayHello ( str )
  3.   (alert str)
  4.   )
  5.  
  6. (defun myfoo ( / )
  7.   (setq string1 "Hello"
  8.         string2 " world!")
  9.   (sayHello (strcat string1 string2))
  10.   (princ)
  11.  )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

David Bethel

  • Swamp Rat
  • Posts: 656
Re: How to loose a (function call
« Reply #8 on: August 13, 2013, 12:28:44 PM »
Thanks SeVen,

I must admit, I am totally lost.  I searched high and low for LiFP  NaDa   Sorry  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: How to loose a (function call
« Reply #9 on: August 13, 2013, 12:32:44 PM »
I must admit, I am totally lost.  I searched high and low for LiFP  NaDa   Sorry  -David

http://www.theswamp.org/index.php?topic=37700.0

 :-)

David Bethel

  • Swamp Rat
  • Posts: 656
Re: How to loose a (function call
« Reply #10 on: August 13, 2013, 12:36:24 PM »
Ah Ha !
R12 Dos - A2K

JohnK

  • Administrator
  • Seagull
  • Posts: 10655
Re: How to loose a (function call
« Reply #11 on: August 13, 2013, 03:01:06 PM »
Sorry, if the tool seems daunting but it really isn't. It's quite easy when you get down to it and I think I've included enough examples as to how people work [-i.e. multiple directories, multi-dirs. + library directory, single directory with files, batch files, makefiles, etc., etc.] and I've even given you an example of how I develop (my directory structure for C++ projects) and made a working lisp example project.

...basically the principle is single working file that CAN BE used to create multiple outputs (final products) if needed.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

David Bethel

  • Swamp Rat
  • Posts: 656
Re: How to loose a (function call
« Reply #12 on: August 13, 2013, 03:54:05 PM »
SeVen,

I'm understanding it bit by bit as I reread the original thread.  My programming is limited to autolisp, html, & bbc.  And very very little vba.  I can see where the tool would very useful as a language interpreter / converter.  Or even as you suggest, a forward compatible parser. 

I know there are calls now that have very long names but can be reproduced using vanilla autolisp code ( make an attribute visible if I remember )


Mine for snvalid

Code: [Select]
(if (null snvalid)
    (defun snvalid (s)
      (and (= (type s) 'STR)
           (not (wcmatch s "*[ \\!@#%^&*()+=|`,.<>:;']*")))))

Congrats!  -David

R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: How to loose a (function call
« Reply #13 on: August 13, 2013, 03:58:45 PM »
Mine for snvalid
Code: [Select]
(if (null snvalid)
    (defun snvalid (s)
      (and (= (type s) 'STR)
           (not (wcmatch s "*[ \\!@#%^&*()+=|`,.<>:;']*")))))

Nice one David - though, I thought spaces were allowed:
Code: [Select]
_$ (snvalid_bethel "Lee Mac")
nil
_$ (snvalid "Lee Mac")
T

David Bethel

  • Swamp Rat
  • Posts: 656
Re: How to loose a (function call
« Reply #14 on: August 13, 2013, 04:21:28 PM »
 I think spaces are release specific.

This was probably 1 of ADesk's first attempts to become more MAC like was to allow spaces in table names.

The rules are based on the sysvar EXTNAMES :

Quote
Type: Integer
Saved in: Drawing
Initial value: 1

Sets the parameters for named object names (such as linetypes and layers) stored in definition tables.


0 Uses Release 14 parameters, which limit names to 31 characters in length. Names can include the letters A to Z, the numerals 0 to 9, and the special characters, dollar sign ($), underscore (_), and hyphen (-).

1 Uses AutoCAD 2000 (and later releases) parameters. Names can be up to 255 characters in length, and can include the letters A to Z, the numerals 0 to 9, spaces, and any special characters not used by Microsoft® Windows® and AutoCAD for other purposes.

-David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: How to loose a (function call
« Reply #15 on: August 13, 2013, 04:44:56 PM »
I see - thanks  :-)