Closed anka-213 closed 2 years ago
Newer version of lists:
-- Handling lists
-- This has to be repeated for every category
-- ** Generic, only used inside other macros **
-- Pair_a_b = (a -> b -> r) -> r
#auxfun MkPair_ a b handler : a -> b -> ab2r -> r = handler a b ; head dummy nonexistent
#auxfun UsePair_ handler pair : ab2r -> Pair_a_b -> r = pair handler ; head dummy
#auxfun Compose_ f g x : b2c -> a2b -> a -> c = f (g x) ; head dummy dummy
-- ** NP **
-- cat, horse, capybara and dog
#auxfun CommaNP_ np comma : NP -> Comma -> NPComma = np ; head punct
#auxfun AndDogPair_ and dog : Conj -> NP -> Pair_Conj_NP = MkPair_ and dog ; cc head
#auxfun NP2_ cat andDog : NP -> Pair_Conj_NP -> NP = UsePair_ (NP2_helper_ cat) andDog ; head conj
#auxfun NP2_helper_ cat and dog : NP -> Conj -> NP -> NP = ConjNP and (BaseNP cat dog) ; head dummy nonexistent
The newer version gives the list in the correct order. The older one does not do that with 4 or more elements.
With this, you can write tiny programs in macros, for example to change the shape of a tree between GF and ud.
For example, this code allows ud2gf to handle phrases like "small, fluffy and cute":
This is pretty hacky though, since some of the macros aren't really real macros, but are only used inside other macros during macro expansion, so it would be nice to have a cleaner solution where you aren't forced to write dummy labels and types.