Author Topic: Store Lots of Data in Text File  (Read 5004 times)

0 Members and 1 Guest are viewing this topic.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Store Lots of Data in Text File
« Reply #15 on: November 17, 2015, 11:55:15 AM »
hardcoding variable name into lsp data file is not a good idea
as soon as load returns the last expression evaluated, one can do it this way
what is the difference to say that it is not a good idea? The example I posted is what I use to update a global variable whose value, if it changes, is written to a file lsp and reloaded into new file dwg if opened.
I agree Vovka here. Keeping the variable outside the data file is better for two reasons:
1. It is more flexible: You can attach the same data to multiple variables.
2. You are less likely to end up with unlocalized variables.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Store Lots of Data in Text File
« Reply #16 on: November 17, 2015, 12:11:20 PM »
...
I agree Vovka here. Keeping the variable outside the data file is better for two reasons:
1. It is more flexible: You can attach the same data to multiple variables.
2. You are less likely to end up with unlocalized variables.
I agree with you... but before you say it's a bad idea...
Code: [Select]
(defun c:test ( / alist)
  (setq alist '((45 63 23)(74 2 52)(45 34 64)))
  (ALE_Utl_WriteData 'alist "z:\\temp\\Ale.lsp")
  (ALE_Utl_LoadData "z:\\temp\\Ale.lsp")
  (princ)
)
Comando: TEST

Comando: !alist
nil
> You can localize the variable alist.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Store Lots of Data in Text File
« Reply #17 on: November 17, 2015, 01:26:21 PM »
...
I agree Vovka here. Keeping the variable outside the data file is better for two reasons:
1. It is more flexible: You can attach the same data to multiple variables.
2. You are less likely to end up with unlocalized variables.
I agree with you... but before you say it's a bad idea...
Code: [Select]
(defun c:test ( / alist)
  (setq alist '((45 63 23)(74 2 52)(45 34 64)))
  (ALE_Utl_WriteData 'alist "z:\\temp\\Ale.lsp")
  (ALE_Utl_LoadData "z:\\temp\\Ale.lsp")
  (princ)
)
Comando: TEST

Comando: !alist
nil
> You can localize the variable alist.

I'd do it thusly :

In the function that reads the data make the last statement return the list you've read

and assign the returned value to a variable you have control over ...

<...>
(setq myData (readTheDataFile fileName) )
<... >
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Store Lots of Data in Text File
« Reply #18 on: November 17, 2015, 03:05:50 PM »
...
I'd do it thusly :
In the function that reads the data make the last statement return the list you've read
and assign the returned value to a variable you have control over ...
<...>
(setq myData (readTheDataFile fileName) )
<... >
Okay I agree, but I think it's more important to discuss whether it is best to read the data file or load it as lisp file, also because this suggestion seems to have been ignored...