Is there any example of Smalltalk being used as a query language?
What I am looking for is: a system or an application where the Smalltalk nature of the application is hidden or irrelevant to the end-user and portions of the language is exposed only for querying the object model underneath (be it application objects, document objects, a simulation or similar). For example a user interface where user defines queries in Smalltalk – either as the predicate portion of the query or the predicate + some other information entered through other user interface elements. The application then wraps it into blocks and applies appropriate filtering functions such as select:
or detect:
depending on the goal of the query.
Analogy would be SQL interface, however that would require relationship model to gain real benefits from it. I’m looking for a language use where the queried model is just a ad-hoc object graph.
@JavierBurroni suggest “GemStone/S 64 Bit Programming Guide chapter 6” (actually Chapter 7 in the 2012 edition) as an example. Which is nicely explained, but still typical smalltalk use within the Smalltalk environment by the Smalltalk developers.
Is there a such thing?
1
.NET already does this; it’s called Linq. Linq is basically SQL for object collections.
In C#, it looks like this:
var q =
customers.
where(c => c.City == "Montreal").
select(c => c.CompanyName);
and in Smalltalk, it looks like this:
q :=
customers
where: [ :c | c city = 'Montreal' ]
select: [ :c | c companyName ].
or this:
((people
select: [ :person | person type = #adult ])
reject: [ :person | person location = 'New York' ])
To hide the Smalltalk representation from your users, you would have to create some sort of domain-specific language that is parsed and processed by Smalltalk. SQL is one such language, but it could be simpler than that. It could merely be a wrapper around the Smalltalk semantics.
For an example of how this might work, look at the Biosmalltalk project.
Of course, all this depends on having some sort of reasonable organizational structure to your data. If your goal is to query data having an arbitrary representation, then you need to look into things like graph databases or dynamically-generated queries.
Further Reading
Is C# turning into Smalltalk?
Your language features are my libraries
Dynamic Linq