I am looking for a good tutorial on how to implement a basic Datalog interpreter for learning purposes. I have found a lot of papers which discuss how to make them faster or add some features but none that describes how to implement a basic one.
Here is a sample implimentation, Java source code included:
http://abcdatalog.seas.harvard.edu/
The developers explicitly cite facilitation of research and pedagogy among their objectives.
There are also many links to open source projects here:
https://en.wikipedia.org/wiki/Datalog#Systems_implementing_Datalog
Best of luck!
Related
I did some searches on developing a DSL in visual studio. At the beginning, I found out there is a Visualization and Modeling SDK for VS2010. It has a tool called DSL tool. But it seems that it is only for graphical DSL development.
Then I saw some posts saying "Oslo" is a tool for developing textual DSL, which "was" a Microsoft product - Microsoft no longer supports the tool. http://blogs.msdn.com/b/modelcitizen/archive/2010/09/22/update-on-sql-server-modeling-ctp-repository-modeling-services-quot-quadrant-quot-and-quot-m-quot.aspx
Therefore, I would like to know if I want to develop a textual DSL, what tool is the best? What do you think if I implement a DSL parser making use of F# powerpack with FSLex and FSYacc?
I am currently developing several external text-based DSLs using FsLex/FsYacc. I was using a hand parser, but I find the FsLex/FsYacc much easier to maintain in the design stage.
FsLex/FsYacc are not as sophisticated as ANTLR, but since most DSLs are fairly simple, FsLex/FsYacc are a perfectly sound choice for use within Visual Studio. And keeping DSLs simple is a good thing, since they are intended to be restricted and simple to learn.
I find Martin Fowler's book to be a good resource, less for the examples and details than as an encyclopedia of DSL ideas. His discussion of useability and other design aspects of DSLs is also worth reading. As Toumas indicated, it does not cover either F# or functional languages. Mr. Fowler writes that he lacked the experience in those subjects to bring the book to market in a timely way.
Having praised FsLex/FsYacc, I do still wish someone would write a good ANTLR back-end for F#. :)
-Neil
I am a fan of embedded DSLs, a la
http://lorgonblog.wordpress.com/2010/04/15/using-vs2010-to-edit-f-source-code-and-a-little-logo-edsl/
http://lorgonblog.wordpress.com/2010/04/16/fun-with-turtle-graphics-in-f/
where you just use leverage F# syntax with some good function names and possibly other syntax cleverness (lists, workflows, ...) to get code that "looks like maybe it is another language" but is actually just F#.
But yes, for external DSLs, you just need a grammar/parser/etc tool chain, and either FsLex/FsYacc, or maybe ANTLR or FParsec are various choices. (I don't have enough experience with any of these to know trade-offs among them.)
Since having made my earlier post, I have also bought and read parts of Terence Parr’s book “Language Implementation Patterns.” It is excellent, though quite a bit more technical than Martin Fowler’s book (with some additional material it could be a “Dragon Book” for the new millennium). The examples are strongly based in Java and ANTLR, but the text is the main thing, so the book is useful regardless of one’s language development environment.
Interestingly, there is little overlap between the two books. Martin Fowler’s book does a good job of covering the design and implementation of basic DSLs, such as those used for specification and configuration, while Terence Parr’s book is more technical and covers the realm extending all the way up through more sophisticated languages and byte-code machines. I recommend both if you can budget for them, otherwise, either is an excellent choice within its given domain.
Martin Fowler has a new book about DSL:s. Sadly, it won't discuss much about Microsoft's tooling nor functional languages.
Microsoft no longer support the graphical tool "Quadrant", but MGrammar is still supported and integrated to SQL server, right? MGrammar is the "DSL making language".
Still, I would say that functional languages (read: F#) are the way to go.
This book has a simple example of how to make a DSL with F#: http://www.manning.com/petricek/
and also Google finds many other good references about this topic.
Try MBase, but it only worth using if your DSL is complicated enough to require an efficient compiler and a PEG grammar. Otherwise FsYacc is more than enough.
Our DMS Software Reengineering Toolkit is designed to handle arbitrary DSLs (I happen to be the architect).
Most people think if you have a parser you have enough, and it is technically true, in the same sense that if you have transistors you can build a computer.
In my experience you want a lot more than just a parser: you need ways to build symbol tables so that your generator knows what the meaning of a particular identifier is, means to analyze the specification, ways to easily encode your translation and to apply optimizations to generated results.
DMS provides all these capabilities to support building DSLs. And in that sense, it goes much beyond F#.
I'm sitting here writing a function that I'm positive has been written before, somewhere on earth. It's just too common to have not been attempted, and I'm wondering why I can't just go to a website and search for a function that I can then copy and paste into my project in 2 seconds, instead of wasting my day reinventing the wheel.
Sure there are certain libraries you can use, but where do you find these libraries and when they are absent, is there a site like I'm describing?
Possibly a wiki of some type that contains free code that anybody can edit and improve?
Edit: I can code things fine, I just don't know HOW to do them. So for example, right now, I'm trying to localize a robot/car/point in space. I KNOW there is a way to do it, just based off of range and distance. Triangulation and Trilateration. How to code that is a different story. A site that could have psuedo code, step by step how to do that would be ridiculously helpful. It would also ensure the optimal solution since everybody can edit it. I'm also writing in Matlab, which I hate because it's quirky, adding to my desire for creating a website like I describe.
StackOverflow.com. No, I'm not joking.
At its best, people come here saying "hasn't some library done X already", and very often the Collective Wisdom answers "yes". But the biggest obstacle is lack of a description language: even here, a big problem for many posters is describing the problem clearly enough for others to recognize it as something they've seen before.
And if people can't understand what you're trying to do, no search engine will.
Firstly, two caveats:
Copy and pasting code you don't understand is a bad idea. Make sure you understand exactly what the code does before you use it.
Make sure you respect the license of the code you are copying. This is important!
Those caveats aside, it's often language dependent. Languages with an open development ethos (not just an open source implementation, think Python as compared to Java) tend to have official archives of open source libraries. For example:
Perl (which probably started this trend) has CPAN
Python has PyPI and Python Cookbook
PHP has PEAR
C++ has boost
Ruby has gems
R has CRAN.
Haskell has Hoogle and Hackage
Furthermore, don't forget to look in your languages standard library. Some modern languages have massive standard libraries, which have often contained the functionality I am looking for:
Java has its API documentation
C# and VB.NET have the massive MSDN
Non-openly developed languages often have non-official community archives. For example:
C# tends to have a lot of code at CodePlex and CodeProject
MATLAB has the Matlab Central File Exchange
A third category of sites are language agnostic. They are often best search through POG (plain old-fashioned Google). For example:
Stack Overflow
SourceForge
The confusingly language agnostic Java2s
Planet source code
Github
Finally, a fourth category of sites that I find increasingly useful are source-code search engines:
Google Codesearch
Koders
You may also be able to find useful source code, or at least get help writing something, through various pastebins.
Pastebin is language-agnostic
HPaste is mostly Haskell, but has a little in other languages.
Often, at the end of the day it is easiest just to google it, though.
There is a wiki that contains free code that anybody can edit and improve:
Rosetta Code.
As a means of an overview there is the "Solutions by Programming Task" page.
From the former page:
"Rosetta Code is a programming chrestomathy site. The
idea is to present solutions to the same task in as
many different languages as possible, to demonstrate
how languages are similar and different, and to aid a
person with a grounding in one approach to a problem
in learning another."
Cutting and pasting code you find on the Internet into production code would be like chewing gum found in the street. - Mike Johnson
With that in mind, try sites that host opensource projects like GitHub, CodePlex, code.google.com, etc.
I'm not sure this question is language agnostic, but I use GitHub this way ;) Other languages may have places where this is possible.
Safari Bookshelf from O'Reilly has many, many books that contain many implementations from which to choose.
http://my.safaribooksonline.com/
I was a subscriber for a few years before coming to my current job, where we have a corporate account! It's one of the best perks, and one of the best resources I have available. I haven't bought a computer book in years.
Aside from sites like this (Stack Overflow) I don't think there's many, maybe CodePlex, but I almost marked you -1 for assuming that code found on the Internet is yours to copy.
I'd suggest reading about software licencing, I hope you'd at least comment where you got it from.
I'm looking for a site or book or any other source of tiny programming tasks one can implement in preferred language. Would be great if examples are present too. And would be superb if there're people who may review my code. May be there's a wiki of such tasks. I've tried to google, but found nothing that suits my needs.
I want to improve my skills in programming using certain language but don't have specific task at hand. Any advice would be greatly appreciated.
Project Euler and the Facebook Puzzles are oft-touted examples.
There's a book called "Programming Pearls" by Jon Bentley which is definitely worth reading and trying out...
Chris Rathman is one of at least a few people I've seen who are working the exercises in Structure and Interpretation of Computer Programs in multiple languages. I'm currently still in the Scheme phase, but it seems like a neat exercise to me!
Try sourceforge, there are many interesting projects and many of them are looking for volunteers.
Where would one find information or just rather good ideas on what is considered proper programming ethics or methodology of how to format the code, comments, or even variable names so that it is easier to read the code at a later time?
Thanks!
The book Code Complete 2 is a timeless reference for good coding practice.
The absolute 'must-read' for you is Robert C. Martin's book Clean Code. Do give it a try. It makes some awesome points. I keep recommending to everyone ever since I bought it 6 months ago.
Edit
I thought reading my Amazon review could help :)
You're asking for Coding Standards, which are language specific.
For C# check out The IDesign C# Coding Standard (on the right-side of the screen in the middle of the page)
For .NET in general see Design Guidelines for Developing Class Libraries
For C++ check here
For Java see Sun's resource Code Conventions for the JavaTM Programming Language
For C++ I use the C++ google style guide
Including Code Complete and Clean Code I would recommend you to read "The pragmatic programmer" and "Ship it!". The last books mentioned are not so much about how to format the code, comments, ect. but rather about best practices for developers and development.
Three books I consider essential for beginning OO programmers.
"Refactoring: Improving the Design of Existing Code".
Although modern IDEs often support automatic refactor, this book is still useful. By knowing the reason (or code smell) behind a particular refacoring, you can strive to write the correct code the first time.
"Pragmatic Programmer"
A wealth of best practices.
"Design Pattern"
Most advanced book, but still useful.
Clean Code is certainly a good book. Martin's Agile Principles, Patterns, and Practices in C# is my recommendation if you want a more .NET specific book.
What real-world projects would you suggest looking through the sources?
As I'm learning Java Swing, mucommander seems to be a decent example. The code is excessively commented though.
EDIT: No shameless plugs plz :).
I learned a lot from looking at the source code to GoGrinder. It's well thought out, uses MVC correctly, and the comments are helpful (and no, I didn't write it). It's also a fun program to use if you want to learn how to play Go.
For Gui design, Patterns and general good advice I highly reccomend Jeremey Miller's series of articles on building a better CAB. For C#, but equally applicable to Java. Also using
the MVC style which Stackoverflow follows, and Apple uses for Interface Builder.
Build your own CAB
Jeremy's articles/ideas are followed in his own project, which you can download and inspect at http://storyteller.tigris.org/
Take a look at the Windows version of truecrypt. It is one of the best organized open source projects I've ever seen. You can almost tell how the whole thing works just from the directory and file layout.
What I've done to learn some new technologies over the years is to look to open source projects that both match the criteria you're looking for and also interest you.
I'm not a Swing guy, but I'd suggest finding a project that uses Java Swing, does not appear too complicated, and then start digging through the source. The nice thing is you can then see the app before you start poking through it, and then you can see what happens as you change stuff.
The idea behind picking something that interests you is that it will keep you engaged. I am intrigued by content management systems, so I might download a CMS that I can then see how stuff works, and I'm engaged because the problem domain of the project fits in with an interest.
I've done this once or twice when I had to get up to speed on C# and I think it works will. YMMV....
Some of the most well thought out source code ( c++ ) I have seen in an open source project is the Ogre3D graphics engine, I've learned a lot about OOA&D just by looking at the structure and reading the comments. It is also well maintained and the community is very active.. http://ogre3d.org