Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting return value of ?() expression #29

Open
johtso opened this issue Jul 5, 2013 · 3 comments
Open

Getting return value of ?() expression #29

johtso opened this issue Jul 5, 2013 · 3 comments

Comments

@johtso
Copy link

johtso commented Jul 5, 2013

I've found myself wanting to get the return value from a ?() expression, for example, when I have a lookup dictionary, and I want the rule to match if the word is present in the dictionary, and I also want to use the returned value. Currently you have to do something like:
thing = word:word !(things.get(word)):thing ?(thing) -> thing

Would be nice if it was possible to do something like:
thing = word:word ?(things.get(word))

Or is there a better way of achieving this functionality? ..would it be possible for ?() to to just return the result rather than True or False?

@MostAwesomeDude
Copy link
Contributor

For sufficiently difficult things, it might be easier to maintain in the long run if you write a utility word:

lookup :k = !(things.get(k)):v ?(v is not None) -> v

Or write a Python method to handle this instead of doing it in Parsley. That said, we probably could change ?() to return the actual value of the expression rather than the bool() of it.

@johtso
Copy link
Author

johtso commented Jul 7, 2013

Ah, of course, didn't think of refactoring it like that. That does make things quite a bit nicer.
I definitely think returning the actual result of the expression would be great. More expressive and more pythonic.

@introom
Copy link
Contributor

introom commented Jul 10, 2013

Yes. This kind of problem shouldn't be eluded. Though may see like syntax sugar, but that will definitely make Parsley sweet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants