leonardo
View:Recent Entries.
View:Archive.
View:Friends.
View:User Info.
View:Website (My Website).
You're looking at the latest 3 entries.

Tags:,
Subject:Partially defined structures - Strutture parzialmente definite
Time:07:16 pm
Scheme lists (as the list of Python) can contain any kind of S-expression/object, it suffices to have the sub-expressions correctly written and the brackets balanced:

("hi"  ((((1  2  3  (4)))))  42/7)

What kind of data structures we may have if we allow unbalanced brackets too, like for example:

((1 2)

It may be like a strange way to represent partially undefined trees. For simplicity we can hypothesise that to obtain all the defined trees from that undefined representation we can only add closed brackets, then that may represent any of:

((1) 2)
((1 2))

That is:
+--+
|  2
+
1
Or:
+--+
|  |
+  +
1  2
A way to represent multiple or partially undefined structures may be useful for various purposes (like to express a situation of partial approximation, or to represent a double meaning of natural words, or something like the Koans, where few ideograms can be read in few different ways with different meanings, etc), but this time I haven't found a way to use them for something practical still.

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

Le liste Scheme (come le list Python), possono contenere ogni tipo di oggetto, e' sufficiente che gli atomi siano scritti correttamente e che le parentesi siano bilanciate:

("hi"  ((((1  2  3  (4)))))  42/7)

Che tipo di struttura dati si avrebbe se si permettessero anche scritture con parentesi non bilanciate, ad esempio:

((1 2)

Potrebbe essere un modo strano per rappresentare alberi parzialmente indefiniti. Se per semplicita' ipotizziamo che per ottenere tutti gli alberi definiti a partire da una tale rappresentazione indefinita si possano aggiungere solo parentesi chiuse, allora tale espressione potrebbe rappresentare una qualunque di:

((1) 2)
((1 2))

Cioe':
+--+
|  2
+
1
Oppure:
+--+
|  |
+  +
1  2
Avere modi per rappresentare strutture "multiple" o parzialmente indefinite e' potenzialmente utile per vari scopi (potrebbe essere un modo per esprimere una situazione di parziale approssimazione, o per rappresentare qualcosa di simile ai giochi di parole cioe' a dei doppi sensi matematici, o ai Koan dove degli ideogrammi hanno significati multipli, ecc), ma in questo caso non sono ancora riuscito a trovare una possibile applicazione pratica.
comments: Leave a comment Add to Memories Tell a Friend

Tags:,
Subject:My Odict
Time:10:45 pm
Ordered dict data structure, deletions are O(1) too:
http://www.fantascienza.net/leonardo/so/index.html#odict

Generally Python isn't fit to create such data structures, they come out too much slow and memory-hungry. For such purposes Delphi, C, C++ are probably better.
comments: Leave a comment Add to Memories Tell a Friend

Tags:,
Subject:Odictstr
Time:06:08 pm
A data structure, an ordered dictionary with just strings as keys. This allows random access of elements on the base of their insertion order index:
http://www.fantascienza.net/leonardo/so/index.html#odictstr

Usage example:

>>> d = Odictstr()
>>> d["aa"] = 1
>>> d["bb"] = 2
>>> d["cc"] = 3
>>> print d
{('aa', 1), ('bb', 2), ('cc', 3)}
>>> d["aa"], d[0]
(1, 1)
>>> d[1] = 20
>>> print d
{('aa', 1), ('bb', 20), ('cc', 3)}
>>> d["bb"] = 30
>>> d["dd"] = Odictstr()
>>> d["dd"]["a"] = 5
>>> print d
{('aa', 1), ('bb', 30), ('cc', 3), ('dd', Odictstr([('a', 5)]))}
>>> d.append(6)
>>> d[4]
6

I'm planning of using a variant of such data structure for Agui, to create a tree of Tkinter widgets (where children of each node keep their insertion order). The key is the optional widget name, the append method allows to manage anonymous widgets, and the number-based access allows to access and modify anonymous widgets too. The difference from the Odictstr is that it guards against value rewrite (this often means creating two widgets with the same name, and this is bad).
N. Wirth showed that starting with the right data structures often simplifies a lot the program creation :-)
comments: Leave a comment Add to Memories Tell a Friend

leonardo
View:Recent Entries.
View:Archive.
View:Friends.
View:User Info.
View:Website (My Website).
You're looking at the latest 3 entries.