Domain Specific Languages in Python
[Pages:48]Domain Specific Languages in Python
Siddharta Govindaraj
siddharta@
What are DSLs?
Specialized mini-languages for specific problem domains that make it easier to work in that domain
Example: SQL
SQL is a mini language specialized to retrieve data from a relational database
Example: Regular Expressions
Regular Expressions are mini languages specialized to express string patterns to match
Life Without Regular Expressions
def is_ip_address(ip_address): components = ip_address_string.split(".") if len(components) != 4: return False try: int_components = [int(component) for component in
components] except ValueError: return False for component in int_components: if component < 0 or component > 255: return False return True
Life With Regular Expressions
def is_ip(ip_address_string): match = re.match(r"^(\d{1,3}).(\d{1,3}).(\d{1,3}).
(\d{1,3})$", ip_address_string) if not match: return False for component in match.groups(): if int(component) < 0 or int(component) > 255:
return False return True
The DSL that simplifies our life
^(\d{1,3}).(\d{1,3}).(\d{1,3}).(\d{1,3})$
Why DSL - Answered
When working in a particular domain, write your code in a syntax that fits the domain.
When working with patterns, use RegEx When working with RDBMS, use SQL When working in your domain ? create your own DSL
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- python mcq multi choice questions neville wadia
- speaking applications
- python introduction for absolute beginners
- python data file hanling
- introduction to python computer science
- domain specific languages in python
- introduction to python programming course notes
- reading and writing vector data with ogr
- working with files in python
- first python program interactive mode programming
Related searches
- most commonly used languages in the world
- hardest languages in the world
- all languages in the world
- duolingo languages in development
- common languages in russia
- most spoken languages in russia
- most spoken languages in india
- most spoken languages in europe
- most spoken languages in us
- how many languages in europe
- number of languages in europe
- languages in spanish