[OT] fortran lib which provide python like data type

Christian Gollwitzer auriocus at gmx.de
Fri Jan 30 08:32:47 CET 2015


Am 30.01.15 um 02:40 schrieb Rustom Mody:
> FORTRAN
> 
>  use dictionary
>  type(dictionary), pointer :: d
>  d=>dict_new()
>  call set(d//'toto',1)
>  v = d//'toto'
>  call dict_free(d)
> 
> The corresponding python
> 
>  d = dict()
>  d['toto'] = 1
>  v = d['toto']
>  del(d)
> 
> In particular note the del in the python.
> 
> Should highlight the point that languages with gc, support data structures
> in a way that gc-less languages - Fortran, C, C++ - do not and cannot.

For C++ this is not correct. Ususally a garbage collector is not used -
though possible - but the constructor/destructor/assignment op in C++
(usually called RAII) provide semantics very similar to the CPython
refcounting behaviour.

For example, I made a set of C++ interface methods to return nested
dicts/list to Python, which is far from complete, but allows to write
something like this:

SWList do_something(SWDict attrs) {
  SWList result;
  for (int i=0; i<5; i++) {
    SWDict entry;			
    entry.insert("count", i);
    entry.insert("name", "something");
    result.push_back(entry);
  }
  return result;
}


There is also Boost::Python which does the same, I think, and much more,
but only supports Python, whereas I use SWIG to interface these
dicts/lists to both CPython and Tcl.

You cannot, however, resolve certain cyclic dependencies with pure
reference counting.

	Christian




More information about the Python-list mailing list