Lately, I wrote a small text in markdown and felt the need to share it with someone (non-technical). I searched for solutions to convert markdown to PDF and was very surprised, that there were only so-so solutions. After some googling and coding I found an easy to use solution which comprises a markdown tool for converting markdown to html and phantomJS (a headless WebKit scriptable) for converting html to pdf. The cool things: hyperlinks and custom css work.
In my last post I described how to cope with generic types in a meta model regarding the scoping mechanism of XText. This post is about the oddities (not meant in a bad way) of XTexts object creation strategy.
Let us take the entity model example from my last post and refine it a little bit. Since we are creating a textual DSL (domain-specific language) and not a GPL (general-purpose language), we would like to add (further) abstractions to our language. Therefore, we do not use the language itself to describe collection types, but integrate it into the language. In contrast, in Java a
List is an interface with several implementations like
ArrayList. They are all implemented in Java and not part of the language features itself. Of course, there are some general-purpose languages like Python, which integrate collections directly into the language, or others like Google Dart which semi-integrate them via syntactic sugar, but still have implemented them as normal classes. But this is not the point here: We would like to integrate collections as a concept into our language…
This post is about some juggling with technologies in the EMF ecosystem, namely XText and XCore. Consider a small (and not completely realistic) DSL for defining entity types (like the introductory grammar example of the XText documentation). Often there are two different kinds of types in such a language:
- primitive/native types, provided by the system, e.g., String, Integer, Boolean, …
- composite/complex types, which have been modeled in the language and can have attributes of primitive type or refer to other complex types
So we might model these variants of properties as
Attribute for primitive types and
Association for complex types…
A major part of my research/work at the university and in some of my personal projects is about integrating business experts into the development process. You can read more about it in my dissertation. We reincarnated a very ambitious project, which now focuses on modeling complete web applications. We defined different interconnected graphical DSLs (Domain-Specific Languages) with Cinco and allow to one-click generate and deploy it on an application server. I am very excited about this great project and some of my posts are (and will be) inspired by it.
As of recently, we use XText as an alternative serialization format to XMI for our graphical DSLs. XText languages have some nice properties over XMI, like syntax highlighting, scoping, validation, just not being XML, compatibility with VCS, etc.. But most important it is much easier to “repair” XText models after a format/meta model change, than with a graphical editor (which just ignores friendly inquiries to open an incompatible file), or with XMI (trust me it is a 😵).
This brings me near to a dream I already have for quite some time: Bringing together textual and graphical DSLs to describe the same model. This is so great because all these integration efforts of business experts (i.e. non-programmers) into the development process is up-to-now a one-way approach. But with a textual representation both the technical and the business experts are likely to use (different views on) the same modeling artifact. Since December 2015 XText (2.9.x) supports IntelliJ IDEA, some web editors as well as standalone usage besides Eclipse. This is great news again (although I have some problems to get it up and running the way I would like to. But more on that later)!
So stay tuned, to news regarding this great new project called DIME (Dynamic web application Integrated Modeling Environment).
The Java 8 Stream API is pretty cool as you can see in my last post BFS with Streams. But there is a catch. You cannot reuse Streams. Consider the following code Java-Code:
final List<String> helloList = Arrays.asList("H", "e", "l", "l", "o", ", ", "W", "o", "r", "l", "d", "!"); final Stream<String> helloStream = helloList.stream(); final Predicate<String> checkUpper = s -> !s.isEmpty() && !s.substring(0,1).toUpperCase().equals(s.substring(0, 1)); helloStream.filter(checkUpper); helloStream.filter(s -> !checkUpper.test(s));
This results in
IllegalStateException: stream has already been operated upon or closed.
The problem with Java 8’s Stream API is that they are designed for parallel execution. This decision introduced some constraints. Unfortunately, there is no sequential only-switch. What you can do is collect the results with
groupBy into a map and then create two new streams from that. But collecting is a terminal operation, not lazy, and therefore inefficient (especially in combination, with early-exit operations like
limit). You can also try to do the first filter, chain it with a
peek, and finally do the second filter. But since only elements matching the first filter will reach the second filter (i.e.
a && !a which is equal to
false), you won’t get any elements past the second filter. If you have a so called cold source (i.e. like a collection), you can just use two different streams which results in two iterations. But for hot sources (like a network or file i/o stream), this is not that easy. A possible solution is to cache the input in a collection, i.e., cool it down. But this comes with a space and performance penalty. So let us see, what our options are…
I recently had the problem to walk through some data and collect elements on the go. I thought it would be nice to use the (relatively) new Stream API in Java 8. After a short search in “the internet” I found a solution in this blog post for tree structures and in this one for recursing through a file system (which is a tree structure again). So, story told? No way! I needed to walk through graph structures (i.e., there might be cycles in it). In contrary, the solutions above will run forever, or more precisely they will terminate relatively fast with a
I really do like the Swift programming language, because of features like multiple return types, nice support for optionals, value types (i.e., structs), enums with associated values, method overloading just with the return type, operator overloading, and many more.
But there are some language decision that are quite alien to me and I want to write them down (and my workarounds to them, which might help you), starting with this post. Perhaps you (yes I mean you 🙂 ) have a better answer for me, then please comment.
If you ever had the problem that your LaTeX document contains wrongly formatted quotation marks (either in a german or english text), you most likely went all the way through your document searching for quotation marks and replacing them accordingly. Here are easy vim commands using the substitution feature (similar to the unix sed command) to replace all occurrences of quotation marks with the correct replacement for english texts:
And this one for german texts:
This article is only a short one, that tells an obvious fact, but I love it; hence, I will let you participate. Currently, I am doing a project with the new language Swift from Apple. Swift is a object-functional language like e.g. Scala.
Both languages have the nice functionality partial application of functions. This means you can set some of the parameters which returns a function that has the remaining parameters, only. So, it is not yet executed, but the already passed parameters are stored into the partial applied function and used if it is called with the rest of the parameters. Just for the seek of completeness, currying is then, when a function with multiple parameters is decomposed into a chain of functions that each has exactly one parameter (this is not the same).
But hey, this should be a short one. Here comes the punch line: You can partially apply functions, so that they have only one parameter, but what if I would like to preset all the parameters? It is very simple: Use a closure to create a new anonymous function, that simply executes the function of interest with all its parameters.
In this article about how to track the logins and logouts of users the
AppModule has been used to add some configuration to a Tapestry application. The current article is about adding a product line to a Tapestry application in terms of localized message strings dependent on the language as well as the chosen product. The corresponding project may be found on github.