You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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.
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.
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 thanTrue
orFalse
?The text was updated successfully, but these errors were encountered: