all repos — h3rald @ b26e779a67ddb0e4187d0c75a391b8d5b046f044

The sources of https://h3rald.com

content/articles/glyph-050-released.glyph

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
----- 
:type: article
:tags: 
- glyph
- ruby
- opensource
:permalink: glyph-050-released
:title: "Glyph 0.5.0 Released"
:subtitle: Featuring Calibre integration, macro composition, Turing-completeness, and more
:pdf: false
:date: 2011-08-28 21:18:00.000000 +02:00
:intro: |
  Too much time passed since the last Glyph release. Way too much. Finally I found the time and will to tidy up the last few remaining bugs, update the docs, and release it!
:extended_intro: |
  This new release was mainly focused on extending the features of Glyph as a _language_. Besides a few improvements that make writing Glyph code easier and more readable (e.g. macro composition), Glyph is now Turing-complete. It supports iterations, recursion, variable assignments, basic arithmetics... you can even write a program to compute the factorial of an integer, if you wanted to.

  Additionally, it also features enhanced content reuse through fragments and output-independent macros, and a few bugfixes.
-----
$[document.intro]

section[
	@title[Calibre Integration]
	txt[
=>[https://github.com/tammycravit|Tammy Cravit] proposed (and more or less implemented) an interesting new feature: integrate =>[http://calibre-ebook.com/|Calibre] to generate ebooks in EPUB and MOBI format from Glyph's native standalone HTML output format.

Although the support is still somewhat rough, you can, as a matter of fact, generate ebooks with Glyph, using Calibre.
  ]
]
section[
	@title[Macro Composition]
	txt[
This release features an update at syntax-level: the possibility of "composing" macros, thereby eliminating nesting provided that containers take only one parameter and no attributes. What? This:
  ]
  highlight[=html|
?[
  not[output?[pdf]]\|
  ...
]
  =]

p[Can be written like this:]

  highlight[=html|
?[
  not/output?[pdf]\|
  ...
]
  =]

txt[
In this case, the @not@ macro was composed with the @output?@ macro, thus removing one level of nesting.

Additionally, I used this features to create an @xml@ macro dispatcher that can be used to render raw XML tags, and an @s@ macro dispatcher that basically is able to call nearly all the instance methods of the Ruby String class. So you can write things like code[=s/sub[This feature makes my life easier\|/my/\|your]=] and similar.
  ]
]
section[
	@title[Turing-Completeness]
	txt[
As of this version, Glyph can be considered _Turing-complete_, as it satisfies the following =>[http://c2.com/cgi/wiki?LanguageRequirementsForTuringCompleteness|requirements for Turing-completeness]:
* A conditional construct, implemented via the @condition@ macro.
* Variable assignment, by setting the value of snippets using the @snippet:@ macro and of attributes using the @attribute:@ macro.
* (infinite) iteration implemented through the new @while@ macro or recursion, which is possible thanks to the new @define:@ macro.
* A memory model which emulates an infinite store: there are no enforced limits on attribute/snippets allocations and number of algorithms or parameters.

Plus, Glyph now understand basic integer arithmetic:
  ]
  highlight[=html|
def:[factorial\|
  ?[
    eq[{{0}}\|0]\|1\|
    multiply[
      {{0}} \| factorial[subtract[{{0}}\|1]]
    ]
  ]
]
  =]
  txt[
Not that you _need_ to be able to calculate factorials in your documents, but know that now you _can_. An you can also define lexically scoped variables, err... _attributes_, like this:
  ]
  highlight[=html|
let[
  @:[a\|bits]
  @:[b\|bobs]
  section[
    @title[Something more about attributes]
Attributes are like lexically scoped variables. You can use them to store @[a] and @[b].
  ]
]
  =]
  p[Handy enough.]
]
section[
  @title[Embeddable fragments]
  txt[
Too lazy to create snippets? Feel the urge to re-use something you already wrote somewhere? Use a _fragment_ and embed it, as follows:
  ]
  highlight[=html|
Snippets and fragments ##[good_way\|are a good way to reuse] small chunks of content, 
while the include and load macros <=[good_way] entire files.
  =]
  txt[...And you can also use a new @load@ macro, to embed entire files without performing any evaluation (like @include@ does).]
]
§txt[
	@title[Incompatibilities with previous versions]
To sum up:
* @snippets.yml@ is no more, define all your snippets inside your document instead.
* New "invisible space separator": @\\/@ instead of @\\.@. Because it's slightly prettier, nothing else.
* The @rewrite:@ macro has been replaced by the @define:@ macro, which also allows recursion, so be careful!
* If you want to render raw XML tags, use @xml/tag_name@ instead of @=tag_name@.
* No more @match@ macro, use @s/match@ instead.

For the full list of the issues fixed in this release, see the =>[http://www.h3rald.com/glyph/book/changelog.html|Changelog].

Hope you'll enjoy this new release of Glyph. If you want to contribute, go ahead and =>[https://github.com/h3rald/glyph|fork the repo]!
]