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

English list constructor #177

Open
erkyrath opened this issue May 6, 2015 · 7 comments
Open

English list constructor #177

erkyrath opened this issue May 6, 2015 · 7 comments

Comments

@erkyrath
Copy link
Owner

erkyrath commented May 6, 2015

gentext.conjunct(ls, word='and')

Convenience function: given a bunch of strings (or texts), glue them together with commas and "and". Or "or".

This will have to stream (like print()) rather than returning a text. Oh well.

@erkyrath
Copy link
Owner Author

erkyrath commented May 6, 2015

But wait! This is a pain in the butt! The original case (see http://seltani.shoutwiki.com/wiki/Act_on_Another_Player) is a list of links. Each entry is a set of link(), print(), endlink() calls. We can't do that without generators or lambdas.

I guess we could pass in a list of texts constructed like text('['+name+'|act("'+str(key)+'")]'). I think that works, but it's ugly and fragile (escaping issues in the name and key).

@erkyrath
Copy link
Owner Author

erkyrath commented May 6, 2015

Maybe a form gentext.conjunct(ls, key='prop') which calls prop(val) on every element of ls. This is a terrible idea.

@erkyrath
Copy link
Owner Author

erkyrath commented May 8, 2015

Less terrible: a generator.

conj = gentext.conjunct(ls)  # or len(ls)
for obj in ls:
    print(obj)  # or whatever
    print(conj())

@rocketnia
Copy link

Already, a Seltani user could do markup concatenation, right? Build a list of strings containing well-balanced markup, pass it in, and get back a string containing well-balanced markup. Then pass that to text(_).

@erkyrath
Copy link
Owner Author

You can do that, but it's error-prone -- you have to escape square brackets in your strings. Anyhow I think it's more effort than the naive solution of a messy if statement in your loop.

@FinnStokes
Copy link

How about a generator that yields both the object and the separator, so you can go:

for obj, conj in gentext.conjunct(ls):
    print(obj)  # or whatever
    print(conj)

@erkyrath
Copy link
Owner Author

That's nice, but I think it should be covered by zip().

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

No branches or pull requests

3 participants