Author Topic: General LISP Question  (Read 2942 times)

0 Members and 1 Guest are viewing this topic.

ChrisCarlson

  • Guest
General LISP Question
« on: July 28, 2015, 08:23:02 AM »
Right now each routine is a separate file, each having it's own sub-functions but I'm finding a lot of my lisp routines utilize some of the same sub-functions eg; Lee's select if, setting of variables for space, doc, objects, error etc.

1) Can sub-functions within a routine be referenced from lisp file to lisp file?
2) Would consolidating routines into a single file be more efficient from a computation standpoint? 

tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Re: General LISP Question
« Reply #1 on: July 28, 2015, 08:32:49 AM »
1) Sure, I've used this.
2) Many different ways, but if it's a sub-function you use every day just put it into your acaddoc.lsp file.
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: General LISP Question
« Reply #2 on: July 28, 2015, 09:36:40 AM »
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.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: General LISP Question
« Reply #3 on: July 28, 2015, 10:20:53 AM »
1.  (defun ...) 's are global to each document.  Last one in wins.  Exploit this wherever possible so you don't rewrite code, and any fixes only need to be made once.

2. Not everything needs to be loaded everywhere.  Split the file content so functions that are required everywhere are in a few files; if there are a lot of functions, split files by general grouping so they are easier for you to manage.  Functions that are only required with a few programs (usually split out by AutoCAD profile) should live in their own group of files.

And anything that is specific to supporting a UI tool (Ribbon, toolbar, menu, etc.) can go into an MNL associated with the matching CUIx file - wherever that's loaded the tools will also be loaded.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: General LISP Question
« Reply #4 on: July 28, 2015, 10:21:19 AM »
What you have developing is a library of sorts.

1. Yes. This can be a huge problem if your organized. -e.g. variables the same name different uses overwriting others, different versions of functions being used at the in correct times, etc. etc.
2. Yes and no. If you organize into several different files and compile them, then you MAY NOTICE a difference but...not a big deal.

Use my LiFP tool and get yourself and your functions organized.

ACADDOC.lsp works only so well. -i.e. it's a very good start but it too can become very unruly.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7527
Re: General LISP Question
« Reply #5 on: July 28, 2015, 10:34:13 AM »
I load all my functions using an *.mnl file associated with my custom menu. Has worked flawlessly for many years.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

andy_lee

  • Newt
  • Posts: 147
Re: General LISP Question
« Reply #6 on: July 28, 2015, 10:46:02 AM »
I load all my functions using an *.mnl file associated with my custom menu. Has worked flawlessly for many years.

Hi ronjonp ,How use *.mnf file load functions ?
andy.
Best regards.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: General LISP Question
« Reply #7 on: July 28, 2015, 10:50:52 AM »
I load all my functions using an *.mnl file associated with my custom menu. Has worked flawlessly for many years.

Hi ronjonp ,How use *.mnf file load functions ?
There are many examples in the link CAB provided.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ChrisCarlson

  • Guest
Re: General LISP Question
« Reply #8 on: July 28, 2015, 12:23:45 PM »
1.  (defun ...) 's are global to each document.  Last one in wins.  Exploit this wherever possible so you don't rewrite code, and any fixes only need to be made once.

2. Not everything needs to be loaded everywhere.  Split the file content so functions that are required everywhere are in a few files; if there are a lot of functions, split files by general grouping so they are easier for you to manage.  Functions that are only required with a few programs (usually split out by AutoCAD profile) should live in their own group of files.

And anything that is specific to supporting a UI tool (Ribbon, toolbar, menu, etc.) can go into an MNL associated with the matching CUIx file - wherever that's loaded the tools will also be loaded.

That solves my main issue, it just seemed counter productive to keep re-writing or using the same sub-functions, when I can simply depend on them. Granted in a per routine world this would not work as the dependencies would be missing but in a enterprise environment it will work just fine.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: General LISP Question
« Reply #9 on: July 30, 2015, 05:54:24 PM »
I have this situation as well and I have tried a few different ways over the years. I think you really need to weigh the pros and cons for yourself of each method:
Putting the subroutine within the definition of the command:
Pros:
  • Consumes memory only while that command is running
  • Keeps it easy to understand the command when you need to edit it later

Cons:
  • If you need to change the subroutine, you have to change it in multiple files

Putting the subroutines in a single file, then loading that file from within the command:
Pros:
  • Makes it easy to edit the subroutines when necessary

Cons:
  • Consumes memory, even when the command isn't running

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: General LISP Question
« Reply #10 on: August 08, 2015, 09:52:02 PM »
I have been programming lisp for around 30 years and almost from day one worked out a library was the way to go, having done commercial software a library of routines is invaluable, drawing multiple lines on various layers from a user database is one example, you can go to the extremes like addline addarc etc

More recently I have been using (if (not to check for defuns and load as required, removing som eof the memory overhead, starting with 386 intel pc's time loading etc was noticeable now we are talking microseconds and really how much memory loss are we talking about.

My recent library addition is a auto create DCL generator for 1, 2, 3, 4 etc line input, only 1 lisp for the dcl and 3 lines in the calling code. No write a 3 line dcl for every time I create a new program. I am in the process now of replacing where possible my Getreal getstrings as the DCLl is in the centre of screen rather at bottom on command line.

What I am suggesting is if your developing a large suite of programs to suite say company standards think about using a library of functions to ensure everything is done to company standard.

A man who never made a mistake never made anything