473,722 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Further questions on dictionaries, namespaces, etc.

Thanks to everyone for pointing out my bone-headed errors :) I don't
*usually* make that sort of mistake...

What I'm attempting to do is create an implentation of the unification
algorithm. Now, its fairly straightforward to do unification on my own
custom types, all I have to do is define a unify() method for each class:

def unify( self, other, bindings ):
...

However, this doesn't work so well when the objects being unified are
built-in python types (tuples, integers, etc.) This requires the
"un-pythonic" testing of each individual type and then calling the
appropriate unification function for the given type.

Another thing that is important is that this particular unifier supports
commutative functions (which accept their arguments in any order), which
is what the permutation stuff is for. (I haven't done associativity yet,
still working on it.) The unifier is structured as a stack of
generators, each returning all possible matches. This allows the higher
levels of the unifier to backtrack by processing alternatives produced
by the lower-level generators.

So here's my list of further questions:

1) Is there are better way to do "functional overloading" on built-in
types than using a whole series of "if type( x ) is y".

2) Is there an easy way to determine if a given object has a callable
method named "unify"? I know how to determine if there's an attribute
with a name, but not how to determine whether or not that attribute is
callable.

3) The "bindings" object is a dictionary that is constructed as the
unification proceeds. (So for example, if I attempt to unify "x + 1"
with "2 + 1" it will have the binding "x : 2" in the dictionary.

I want this bindings object to behave like a function call scope - in
that you can "see" the variables in the enclosing scope. In fact, I'd
like to be able to use a regular python namespace (such as a module) as
the enclosing scope, so that the unification algorithm has access to all
of the variable definitions within that module. (Again, this is part of
the notion that I want to be able to do unification operations on normal
python data structures, rather than specially "wrapped" types.)

In fact, I had thought about the idea of the bindings being an actual
Python "module" object, however that doesn't appear to be possible (or
what I want for that matter.) Similarly, being able to take the local
function scope and capture it in a closure and export that to the
outside world was also something I briefly pondered.

Because of the backtracking nature of the matcher, I need to be able to
"undefine" bindings that have been previously defined. The way I am
currently doing this is to create a new "scope" each time I add a new
binding, where the new scope's "parent" is the previous scope. (So in
fact my dictionary has only one entry in it.) Something like this:

for new_bindings in generate_matche s( a, b, old_bindings ):
...

If none of the alternatives pan out, it simply discards "new_bindin gs"
and reverts back to the old_bindings.

So my question here is: Do I want to continue using a subclass of dict
for this, or something more exotic?

4) I've seen a couple of code examples on the net where people use the
idiom "lambda x: (for x in [])" to represent a "null" iterator, i.e. one
that immediately terminates. How is this any different from simply
returning "()"? (Or range( n, n ) for that matter.) Which one is the
most efficient? And if they are different, how about adding a null
iterator to itertools :)

-- Talin

Aug 21 '05 #1
1 1172
Talin a écrit :
(snip)
2) Is there an easy way to determine if a given object has a callable
method named "unify"?


if callable(getatt r(obj, 'unify', None)):
# obj.unify exists and is callable

Br
Aug 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2074
by: Elaine Jackson | last post by:
Two quick newbie questions: 1) Does Python have passing-by-reference? 2) In ordinary parlance, "deep" implies "shallow" but not conversely. In the Python "copy" module (if I understand correctly), the implication goes the other way. Do you find this a nuisance? Peace, EJ
1
1903
by: Limey | last post by:
Hi All, I want to write an application that will talk to a RDBMS. The application needs to be platform neutral from both an operating system and database backend point of view. I have decided to create a prototype in Python, the RDBMS will be PostgreSQL running on a Linux box.
1
1419
by: Tony Johansson | last post by:
Hello I'm trying to learn XML by reading a book. There is some text in the book that I don't understand so I try to ask you out there. My first question is does this statement mean that the character string from is placed into the attribute with name type <contect type = "from">
3
1496
by: Faisal Alquaddoomi | last post by:
Hello, I'm having a bit of trouble isolating my scripts from each other in my embedded Python interpreter, so that their global namespaces don't get all entangled. I've had some luck with PyRun_FileEx(), as you can specify dictionaries to use for the globals and locals, but it seems that you can't do the same for PyEval_CallObject() (which i use for calling the callbacks previously registered by scripts run via PyRun_FileEx()). Is there...
0
9239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9158
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8059
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6685
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4764
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3208
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2606
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2148
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.