Roberto book, persistance, data structures

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Roberto book, persistance, data structures

Philippe Lhoste
Hello,

I have read two additional chapters of Roberto's book (the draft). I haven't
much time to read it from cover to cover (if I can say for a printed .ps
file...) but it is truly excellent...

First, two remarks, before I forget them:
Page 72 (11.2 Matrices and multi-dimensional arrays), there is a code
snippet that seems incorrect:
there are two similar lines:
  for j=1,M do
and
  while j <= M do
and only one 'end' for both... I guess it is a leftover of the old 3.2
syntax...

Page 74 (11.4 Queues and Double Queues), you state that indices of a double
queue can grow almost infinitely because they are actually doubles, so they
can be quite large.
But since the doubles are handled by the compiler / run-time library, I
suppose they are stored in a limited space (as opposed to large number
libraries). 48 bits, if I recall correctly (and if this is standard, I am not a
specialist here).
So after some time, values will be rounded and manipulated with exponents of
ten, so small increments will be lost.

I made a little test:

val1 = 314159265358979323
val2 = val1 + 1
print(val1, val2, val2 - val1)

result on Windows NT:
3.141592653589793e+017	3.141592653589793e+017	0

OK, I made a small test, the limit seems to be between 9,007,190,000,000,000
and 9,007,200,000,000,000, so you may be quite right finally...
It may be interesting to state this limit (if it is standard induced)
somewhere, I think.

-----

No recent news of the book. I suppose Roberto is focussing on the release of
Lua 4.1... Even more if the book must be updated to this version...
Do you plan to release the whole, finished book in electronic form, in
addition to the printed form?
Somebody (http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html) has done
it before, without reverse effect on the sales, it seems.

-----

I am writing Windows software. The usual options to save user options are:
- use the registry
- use the old .ini file format
- use proprietary format.

I don't like using the registry for such task. It makes it growth, it is
hard to access, it makes hard to backup these data, and if you just remove the
program directory to uninstall it, data remains in the registry.

The .ini format is fine, except it doesn't support multi-users (or you must
handle these by hand), and it is not hierarchical.

I was going to make my own, hierarchical, textual proprietary format, when I
discovered Lua.
I haven't embedded Lua in an application yet, but I find the idea of using
it for storing data is very interesting. Lua is small enough to avoid to bloat
even the smallest programs, and it provides other facilities, like scripting
(!), that are good too.
I mean, some applications may have no use of scripting, but it can be
interesting to embed Lua anyway for its persistance properties alone.

-----

Another though while reading the Data Structures chapter:
I am struggling to make a generic, non-template based, double-linked list
class in C++. Struggling because I am not master of object design... Any
pointer on this would be appreciated, BTW.
So I though: "Can I use Lua to handle such structure?".
I mean, I know I can, but is this practical?
Sorry, I haven't read thouroughly the API section of the manual yet.
I don't intend to use very big datasets, so performance and memory are not
an issue (though it could be interesting to see how this scale).

Do you think it is a viable option (to delegate the use of such data
structures, like lists, dictionaries, etc.)? The purpose is to avoid to reinvent the
wheel and to use a fast and reliable implementation. But access to the data
must be simple and readable, even if I must write some wrapper functions.

Want do you think?

Regards.

-- 
--._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.--
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://jove.prohosting.com/~philho/
--´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`--

Sent through GMX FreeMail - http://www.gmx.net


Reply | Threaded
Open this post in threaded view
|

Re: Roberto book, persistance, data structures

Nicolas Devillard
On Wed, 18 Jul 2001, Philippe Lhoste wrote:
[...]
> The .ini format is fine, except it doesn't support multi-users (or you
> must handle these by hand), and it is not hierarchical.

The ini file format can be made hierarchical by reserving a character as a
separator in the section names. Example: with '/':

[Section/Subsection1]
[Section/Subsection2]
...

Use any character you want as long as it is not used in a section label,
and you have your hierarchical ini file. Not the best but you can find
parsers for ini file all over the place so you do not have to reinvent the
wheel. All depends on how hierarchical you need your file to be. XML might
also be a choice there.

As to making the ini file aware of different users, nothing prevents you
from using a naming scheme to do that, something like appli-user1.ini,
appli-user2.ini, etc.

Many, many solutions for config files out there. Have a look into
freshmeat for starters :-)

Cheers
-- 
Nicolas


Reply | Threaded
Open this post in threaded view
|

lib and tag problems

Jens Wessling
In reply to this post by Philippe Lhoste
I am using Lua 4.0 and Lua complains that there is an error in the Main part
of the chunk.  I have tried making other baselib calls, and they are not
working
either.

>
>> What exactly is the complaint? Which version of Lua you are running?
>> -- Roberto
>>
>>>I am trying to use standard library calls, and lua does not seem to be
>>>finding the functions.  I have called lua_baselibopen() and it does not
seem
>>>to make a difference.  My entire script is:
>>>
>>>collectgarbage(1)
>>>
>>>I step through the code when lua_baselibopen is called, and it looks like
it
>>>is being properly added, but the call still fails.  I have confirmed that
>>>the interpreter being called is the same as the one the functions are
being
>>>added to, but to no avail.  Lua complains that there is an error in the
Main
>>>part of the chunk.
>>>
>>>Does anyone know what the problem might be, or how I could fix it?
>>>
>>>Thanks!



Reply | Threaded
Open this post in threaded view
|

RE: Roberto book, persistance, data structures

Philippe Lhoste
In reply to this post by Philippe Lhoste
Nicolas Devillard wrote:
> On Wed, 18 Jul 2001, Philippe Lhoste wrote:
> [...]
> > The .ini format is fine, except it doesn't support multi-users (or you
> > must handle these by hand), and it is not hierarchical.
> 
> The ini file format can be made hierarchical by reserving a character as a
> separator in the section names. Example: with '/':
> 
> [Section/Subsection1]
> [Section/Subsection2]
> ...

I knew that, as it is the format used for .reg files.
But it is very verbose and not practical.
 
> Use any character you want as long as it is not used in a section label,
> and you have your hierarchical ini file. Not the best but you can find
> parsers for ini file all over the place so you do not have to reinvent the
> wheel.

I agree, that's why I plan to use Lua for that...

> All depends on how hierarchical you need your file to be. XML might
> also be a choice there.

Well, an XML parser like Expat is about the same size than the Lua parser,
but it can't be used for scripting... And XML is a chore to code by hand.
OTOH, it is quite standard.
 
> As to making the ini file aware of different users, nothing prevents you
> >from using a naming scheme to do that, something like appli-user1.ini,
> appli-user2.ini, etc.

That's what I meant by "you must handle these by hand". Either that, or
creating one section by user.
 
> Many, many solutions for config files out there. Have a look into
> freshmeat for starters :-)

Been there, done that. Some interesting solutions, but I still prefer to use
Lua...
 
> Cheers

Thank you for the tips and pointers.

> -- 
> Nicolas

Regards.

-- 
--._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.--
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://jove.prohosting.com/~philho/
--´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`--

Sent through GMX FreeMail - http://www.gmx.net


Reply | Threaded
Open this post in threaded view
|

Re: Roberto book, persistance, data structures

Joshua Jensen
In reply to this post by Nicolas Devillard
I've switched formats for ALL of the data used in my applications to a Lua
compatible form (where practical of course... lots of binary data =
impractical).  This lets anyone who knows Lua the least little bit modify
the data and write it back out.  Scripts can be written to batch process
data or even to write it out in a custom binary format, if needed.

The point is, I find it impractical to write custom parsers for the types of
data Lua handles best.  The power and control given to the user through the
scripting capabilities are unmatched.  The concept of "macros" (as I've
described to some of the people who use Lua to create large amounts of data)
can be implemented to speed data manipulation:

function MakeBoat(color)
    local table =
    {
        Data1 = "blah",
        Data2 = 5,
        Color = color,
    }
    return table
end

Boats =
{
    MakeBoat("red"),
    MakeBoat("blue"),
    MakeBoat("green"),
    MakeBoat("yellow"),
}

4 lines instead of 20 lines to describe the boats, and a lot easier to
maintain.  The best part is, rather than taking the runtime hit for
generation of the boats, the file can be loaded into a Lua state and dumped
back out (say, through my Lua wrapper's Script::SaveText() function...
although it doesn't handle cyclic data)... find it in the Misc. Code section
of http://workspacewhiz.com/.

Anyway, I'd recommend that anyone use Lua FIRST for their data and
scripting, and if needed, custom solutions can be built.  I find the need
for custom solutions to be few and far between.

Just my take,
Josh


----- Original Message -----
From: "Nicolas Devillard" <[hidden email]>
To: "Multiple recipients of list" <[hidden email]>
Sent: Wednesday, July 18, 2001 8:53 AM
Subject: Re: Roberto book, persistance, data structures


>
> On Wed, 18 Jul 2001, Philippe Lhoste wrote:
> [...]
> > The .ini format is fine, except it doesn't support multi-users (or you
> > must handle these by hand), and it is not hierarchical.
>
> The ini file format can be made hierarchical by reserving a character as a
> separator in the section names. Example: with '/':
>
> [Section/Subsection1]
> [Section/Subsection2]
> ...
>
> Use any character you want as long as it is not used in a section label,
> and you have your hierarchical ini file. Not the best but you can find
> parsers for ini file all over the place so you do not have to reinvent the
> wheel. All depends on how hierarchical you need your file to be. XML might
> also be a choice there.
>
> As to making the ini file aware of different users, nothing prevents you
> from using a naming scheme to do that, something like appli-user1.ini,
> appli-user2.ini, etc.
>
> Many, many solutions for config files out there. Have a look into
> freshmeat for starters :-)
>
> Cheers
> --
> Nicolas
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: lib and tag problems

Luiz Henrique de Figueiredo
In reply to this post by Jens Wessling
>I am using Lua 4.0 and Lua complains that there is an error in the Main part
>of the chunk.

Please send us the exact error message and the line of the Lua program where
it happens. Thanks.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: lib and tag problems

Jens Wessling
Hmmm,

The exact line of the script is

collectgarbage()

The error is handled by me, so it probably won't be that informative.

when lua_dostring() is called, it returns LUA_ERRRUN.

Is there better information I can give you?

--jnw


----- Original Message -----
From: "Luiz Henrique de Figueiredo" <[hidden email]>
To: "Multiple recipients of list" <[hidden email]>
Sent: Wednesday, July 18, 2001 2:00 PM
Subject: Re: lib and tag problems


> >I am using Lua 4.0 and Lua complains that there is an error in the Main
part
> >of the chunk.
>
> Please send us the exact error message and the line of the Lua program
where
> it happens. Thanks.
> --lhf


Reply | Threaded
Open this post in threaded view
|

Re: Roberto book, persistance, data structures

Roberto Ierusalimschy
In reply to this post by Philippe Lhoste
> No recent news of the book. I suppose Roberto is focussing on the release of
> Lua 4.1...

Yes. But I am planning to do another release of the current state of the
book, soon.

> Even more if the book must be updated to this version...

It won't (or more exaclty, it doesn't need to).

> Do you plan to release the whole, finished book in electronic form, in
> addition to the printed form?

First I must plan to finish it ;-)

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Roberto book, persistance, data structures

Mario Topf

-----Ursprüngliche Nachricht-----
Von: [hidden email]
[[hidden email] Auftrag von Roberto
Ierusalimschy
Gesendet: Sonntag, 22. Juli 2001 02:41
An: Multiple recipients of list
Betreff: Re: Roberto book, persistance, data structures


> No recent news of the book. I suppose Roberto is focussing on the release
of
> Lua 4.1...

Yes. But I am planning to do another release of the current state of the
book, soon.

> Even more if the book must be updated to this version...

It won't (or more exaclty, it doesn't need to).

> Do you plan to release the whole, finished book in electronic form, in
> addition to the printed form?

First I must plan to finish it ;-)

-- Roberto



I hope you will be extending the part, where the C(++) <-> LUA cooperations
is looked at as LUA is an embeddable language and I think many people are
using lua with the C-API to get their work done.
But the book was great anyway ;)

regards Mario