dsl

Dynamically define named classes in Ruby

亡梦爱人 提交于 2019-11-29 10:53:51
问题 I am writing an internal DSL in Ruby. For this, I need to programmatically create named classes and nested classes. What is the best way to do so? I recon that there are two ways to do so: Use Class.new to create an anonymous class, then use define_method to add methods to it, and finally call const_set to add them as named constants to some namespace. Use some sort of eval I've tested the first way and it worked, but being new to Ruby, I am not sure that putting classes as constants is the

Understanding method_added for class methods

夙愿已清 提交于 2019-11-29 00:59:10
问题 I would like to do some magic in the moment instance and class methods are added to some class. Therefore I tried the following: module Magic def self.included(base) base.extend ClassMethods end module ClassMethods def method_added(name) puts "class method '#{name}' added" end def some_class_method puts "some class method" end end end class Foo include Magic def self.method_added(name) puts "instance method #{name} added" end end This approach works well for instance methods, fails for class

How to construct QueryBuilder from JSON DSL when using Java API in ElasticSearch?

对着背影说爱祢 提交于 2019-11-29 00:14:53
问题 I'm using ElasticSearch as a search service in Spring Web project which using Transport Client to communicate with ES. I'm wondering if there exists a method which can construct a QueryBuilder from a JSON DSL. for example, convert this bool query DSL JSON to a QueryBuilder. { "query" : { "bool" : { "must" : { "match" : {"content" : "quick"}, "should": { "match": {"content" : "lazy"} } } } I need this method because I have to receive user's bool string input from web front-side, and parse this

What is a DSL and where should I use it?

£可爱£侵袭症+ 提交于 2019-11-28 21:17:46
I'm hearing more and more about domain specific languages being thrown about and how they change the way you treat business logic, and I've seen Ayende's blog posts and things, but I've never really gotten exactly why I would take my business logic away from the methods and situations I'm using in my provider. If you've got some background using these things, any chance you could put it in real laymans terms: What exactly building DSLs means? What languages are you using? Where using a DSL makes sense? What is the benefit of using DSLs? DSL's are good in situations where you need to give some

When would I want to use a Free Monad + Interpreter pattern?

我怕爱的太早我们不能终老 提交于 2019-11-28 16:21:34
I'm working on a project that, amongst other things, involves a database access layer. Pretty normal, really. In a previous project, a collaborator encouraged me to use the Free Monads concept for a database layer and so I did. Now I'm trying to decide in my new project what I gain. In the previous project, I had an API that looked rather like this. saveDocument :: RawDocument -> DBAction () getDocuments :: DocumentFilter -> DBAction [RawDocument] getDocumentStats :: DBAction [(DocId, DocumentStats)] etc. About twenty such public functions. To support them, I had the DBAction data structure:

Are there any Clojure DSLs?

蓝咒 提交于 2019-11-28 15:22:02
问题 Is there any DSL (Domain Specific Language) implemented in Clojure ? 回答1: Like any Lisp dialect, Clojure draws a very fuzzy line between API and DSL and therefore the term doesn't hold the same mystique that it does in other languages. Lisp programmers tend to write their programs as layers of DSLs, each layer serving those above it. Having said that, here are a few that you could say display non-trivial levels of DSL-ness (in no particular order): Enlive (HTML templating) LazyTest (Unit

What is a domain specific language? Anybody using it? And in what way?

点点圈 提交于 2019-11-28 13:55:58
问题 I guess I am looking for some kind of intro and see if anybody have used it. Are there any particular advantages of using it? Wikipedia: domain-specific language (DSL) is a programming language or specification language dedicated to a particular problem domain, a particular problem representation technique, and/or a particular solution technique. Can anybody give any specific examples of how you have implemented it or how it can be useful in a given scenario? 回答1: A domain specific language

How Pony (ORM) does its tricks?

此生再无相见时 提交于 2019-11-28 13:10:31
问题 Pony ORM does the nice trick of converting a generator expression into SQL. Example: >>> select(p for p in Person if p.name.startswith('Paul')) .order_by(Person.name)[:2] SELECT "p"."id", "p"."name", "p"."age" FROM "Person" "p" WHERE "p"."name" LIKE "Paul%" ORDER BY "p"."name" LIMIT 2 [Person[3], Person[1]] >>> I know Python has wonderful introspection and metaprogramming builtin, but how this library is able to translate the generator expression without preprocessing? It looks like magic.

'Spread' parameters in Scala?

回眸只為那壹抹淺笑 提交于 2019-11-28 12:29:27
Is there any way to call a Scala function that takes individual parameters, given an array (similar to JavaScript Spreads in ECMAScript 6)? ys = [10.0, 2.72, -3.14] f(x, ...ys); The cleanest syntax would be: f(1, ys) but that does not appear to be possible. Even f(1, ys:_*) does not work (and neither does f(ys:_*) , as the compiler reports too few parameters - only the first one is filled). Example: def f (a:Int, b:Float, c:Float, d:Float): String val x = 1 val ys = List(10.0, 2.72, -3.14) // note: non-Objects val result = f(x, ys) // intuitive, but doesn't work Use Case: injecting test data

Is there a way to write to a text file using Karate

核能气质少年 提交于 2019-11-28 10:58:17
问题 In my karate tests i need to write response id's to txt files (or any other file format such as JSON), was wondering if it has any capability to do this, I haven't seen otherwise in the documentation. In the case of no, is there a simple JavaScript function to do so? 回答1: Try karate.write(value, filename) in JavaScript. We have kept this un-documented because we don't encourage it. Also the file will be written only to the current "build" directory which will be target for Maven projects /