I'm looking at implimenting a DSL, for managing inventory/orders. In this case it is for a game (Minecraft, with computercraft + Applied Energistics), however it could as reasonably be a real world system, for example manufacturing cars. A large portion of my motivation for making this is to experiment with DSL crafting/design.
It will probably be implemented in Lua, but the user shouldn't nesc realise they are writing Lua code for adding rules.
So I am trying to decide what contructs/functions the DSL should provide.
Current ideas include, as basic primitives:
- Order(qty, item)
- CurrentStock(item) = qty
- OnOrder(item) = true/false
Then I would need some helper functions, KeepStock(qty,item)
which the user could have build out of primitives:
if CurrentStock(item)<qty and not OnOrder(item) then Order(qty-CurrentStock(item), item) end
Examples of how I'm envisioning the DSL could be used:
if CurrentStock("wheat")>100 then Order(10, "Bread") end
KeepStock(100, "Iron Ingots")
Questions
Syntaxtic Sugar:
What functions should I have, in such a DSL?
Perhaps I should have a function StockDeficit(item, qty) helper?
equivalent to: math.max(qty - CurrentStock(item), 0)
- instead of (or as well as) `KeepStock(100, "Iron Ingots")
- have
if StockDeficit("Iron Ingot", 100) then Order("Iron Ingot", StockDeficit("Iron Ingot, 100) end
Perhaps it is important to have methods for querying capacity to have orders filled?
Some kind of FreeCapactityFor(item), that could be used: like If FreeCapacityFor("Bread") then Order(1, Bread) end
Is it worth cleaning the syntax, making it more natural language like: so that:
- instead of:
if CurrentStock("wheat")>100 then Order(10, "Bread") end
- we have:
if CurrentStock(wheat)>100 then Order(10, Bread) end
- or even:
if wheat>100: Order 10 bread
back on the earlier example, is it worth making, the language context sensitive:
- instead of:
if StockDeficit("Iron Ingot", 100) then Order("Iron Ingot", StockDeficit("Iron Ingot, 100) end
- have:
if StockDeficit("Iron Ingot", 100) then Order(StockDeficit) end
Overarching these questions is the general case: How do you determine what functionality a user needs from a DSL? I do not expect an answer to this final question as it it too broad. However, answers might reference it to explain how they came to their conclusions. Determining the syntactic requirements doesn't seem too hard, mostly a matter of judging how technically skilled they are (eg in some domains, they would be fine, knowing they are in fact just writing Lua code with a particular set of functions available) However users are notoriously bad at knowing what they want. Are the good techniques, like User Stories, or survaying their current pactices for a few hours/days, that are better than others for capturing requirements, specifically for DSLs?