views:

102

answers:

3

The graph is arguably the most versatile and valuable data structure of all. I can store single variables, lists, hashes etc., and of course graphs, with it.

Given this, are there any languages that offer inline / native graph support and syntax? I can create variables, arrays, lists and hashes inline in Ruby, Python and Javascript, but if I want a graph, I have to either manage the representation myself with a matrix / list, or select a library, and use the graph through method calls.

Why on earth is this still the case in 2010? And, practically, are there any languages out there which offer inline graph support and syntax?

+2  A: 

The main problem of what you are asking is that a more general solution is not the best one for a specific problem. It's just average for all of them but not a best one.

Ok, you can store a list in a graph assuming its degeneracy but why should you do something like that? And how would you store an hashmap inside a graph? Why would you need such a structure?

And do not forgot that graph implementation must be chosen accordingly to which operations you are going to do on it, otherwise it would be like using a hashtable to store a list of values or a list to store an ordered collection instead that a tree. You know that you can use an adjacency matrix, an edge list or adjacency lists.. every different implementation with it's own strenghts and weaknesses.

Then graphs can have really many properties compared to other collections of data, cyclic, acyclic, directed, undirected, bipartite, and so on.. and for any specific case you can implement them in a different way (assuming some hypothesis on the graph you need) so having them in native syntax would be overkill since you would need to configure them anyway (and language should provide many implementations/optimizations).

If everything is already made you remove the fun of developing :) By the way just look for a language that allows you to write your own graph DSL and live with it!

Jack
To be honest though, I do think the world of programmable math environments is an interesting one. I don't have much exposure to it, but I do assume they exist, and it's an idea worth exploring, IMHO.
Noon Silk
In Java, when I need a list, I use an ArrayList by default and switch to a LinkedList if and when I need to. Why can't I have default 'best general fit' graph implementation to hand, build into the language, which I can adjust if I need to?I really don't have much fun reconsidering the implementation details every time I make a graph, it's a huge waste of time.
Ollie G
Usually when you need graphs you need them for intensive calculations, that's why you will need to think carefully about if use a matrix or an adjacency list (since they are opposite for some operations). My Java implementation is just 600-700 lines of code, wrote that once and I still use it when needed but it just models some properties.. howver like silky suggests many math environments have graphs implementations
Jack
I agree that there are good reasons for choosing different implementations, but not that I usually need to think about them. Sometime I prefer to sketch programs first and solve problems incrementally. When I create a hash in Ruby, I'm happy to have 'a hash', and I'll think about normalisation and query speed / space optimisations if or when problems of space or speed arise.
Ollie G
yes, but an API simply cannot hold everything needed with inline syntax.. that would be overkill. some cuts need to be made and sincerely, although graph is an useful data structure, it's not use SO often to really need inline synax.. for implementations you can find really plenty of them for every language..
Jack
But not inline / syntax level implementation. I'd argue that if these were available, graphs would be more widely used. How often do developers start off with an array, because it's 'to hand' and 'good enough', then upgrade to a list, or an sql database, etc. Why can't I work with graphs in the same way? Why do I have to endure library selection, and cumbersome syntax, when I want to use a graph? I appreciate that a default graph can't do everything, but that doesn't seem a strong enough reason for a language not to make one available to me.
Ollie G
I'll add it to the language I'm developing so you will be happy! But it's an esoteric one so you will need to learn everything else.. however I understand your reasons, it would be a good thing (as any extension in this way to the syntax of a language).
Jack
+1  A: 

Gremlin, a graph-based programming language: http://wiki.github.com/tinkerpop/gremlin/

Ollie G
A: 

GrGen.NET (www.grgen.net) is a programming language for graph transformation plus an environment including a graphical debugger. You can define your graph model, the rewrite rules, and rule control with some nice special purpose languages and use the generated assemblies/C# code from any .NET language you like or from the supplied shell.

To understand why normal languages don't offer such a convenient/built-in interface to graphs, just take a look at the amount of code written for that project: the compiler alone is several man-years of work. That's a price tag too hefty for a feature/data structure only a minority of programmers ever need - so it's not included in general purpose programming languages.