dictation-toolbox / dragonfly-scripts

Dragonfly scripts for Dragon NaturallySpeaking
87 stars 30 forks source link

Formatting functions are not composable #6

Closed nirvdrum closed 10 years ago

nirvdrum commented 10 years ago

I found myself wanting to compose the formatting functions. For example, when setting certain environment variables I'd like to both lowercase them and squash the text. However there is no meaningful way to take the output of one and provide it as the input to another because each of the formatting functions performs actions in-line.

Perhaps it would make sense to introduce a new level of the functions may return strings that can be fed into other functions and then have a final stage in the pipeline that converts to dragonfly actions. Or perhaps I'm just overthinking this and the correct solution is to just introduce my own new formatting function. I'm opening this issue more as a design discussion.

poppe1219 commented 10 years ago

Yes, that makes a lot of sense. The functionality of chainig functions would be great to have, for more than just the formatting functions. When I built the formatting functions, I remember I wanted to return the result at first, but didn't find a good way to get the output into the normal Dragonfly output stream. So I took the easy way out... Do you have an idea on how to solve this?

poppe1219 commented 10 years ago

There is always the possibility of creating commands like "lowercase squash ", and then create a method that does both. I misunderstood at first, thinking of chainable rather than composable methods.

nirvdrum commented 10 years ago

Right. That was my alternative proposal. I'm sorry if I wasn't clear about that. I guess I'll just write my own formatting functions.

poppe1219 commented 10 years ago

Haha, "compostable". (Stupid voice recognition :)

Anyway, I did as you suggested and split the methods into 2 levels, where the lower level returns the result. I also created a new method, that can take a list of formatting types. generic_edit contains one example, "lowercase squash".

poppe1219 commented 10 years ago

Scratch that. The command "< formatType > < text >": Function(format_text) Now replaces all the former commands in the grammar in generic_edit. formatType Is a mapping that allows for all the previous formats as well as combinations. Seems to work very well.

nirvdrum commented 10 years ago

This looks awesome! But, unfortunately I think it broke in 1996a75d156c13a5f070ef816f9a8d26f10dc7ad. I commented on that commit to indicate where I think the problem is.

poppe1219 commented 10 years ago

Yes, you're quite right. My spoken form formatting method introduced the bug. It is working now. This would have been detected if I had bothered to write unit tests for the formatting methods. Some day perhaps...

nirvdrum commented 10 years ago

it was caught early and fixed quickly. I wouldn't get too hung up over testing right now :-)

poppe1219 commented 10 years ago

Seems to be ticking like a clock. :-) Closing.

nirvdrum commented 10 years ago

Thanks! This has been working great.