YAML Syntax for Racket Languages
#lang yaml-exp racket/base - define: - fibbi: [x] - if: - <=: - x - 1 - x - +: - fibbi: - -: - x - 1 - fibbi: - -: - x - 2 - displayln: - fibbi: [10]
1 YAML to Code Mapping
Plain, unquoted strings are converted to symbols when the entire string is a readable symbol as-is. (Otherwise they remain as strings). For example, define would be read as a symbol, but Hello world! would be read as a string (though be careful with commas if you are in a flow-style sequence), and no would be a boolean as usual.
- Mappings are interpreted as a sequence of forms, one for each key-value pair, where each key is simply consed with its associated value. If the map only has one key-value pair, then it is returned alone, otherwise all the key-value pairs are returned as a list. Pairs and improper lists can be constructed this way. These cannot use !!merge tags, use !hash (below) for that. Examples:
Sequences continue to be lists, flow-style or not.
- Finally, there are some tags available:
!kw keyword produces #:keywords, while !sym symbol produces symbols, without any restrictions on the content.
!vector and !hash both produce vector?s and hash?es, from sequences and mappings, respectively.
!char <char-constant> reads as #\<char-constant> does; see Reading Characters.
All the tags (global and local) from base yaml are also available; see YAML Expressions.