Page 1 of 1

yes = true

PostPosted: Thu Jul 07, 2011 9:00 am
by ebaker355
I'm brand new to Cobra, and it looks fantastic! Is there a way I can substitute (like 'typedef', '#define', macro, etc.) the "true" keyword with "yes", and "false" with "no"? It's just a personal preference, but for my poor brain, code like:

Code: Select all
success = yes
failed = no

is more readable than:

Code: Select all
success = true
failed = false

Any way to do this type of keyword substitution in Cobra?
Thanks!

Re: yes = true

PostPosted: Thu Jul 07, 2011 3:03 pm
by Charles
Thanks. Regarding the keyword substitution, no. In fact, Cobra's syntax generally prefers fewer ways to do a particular thing so that it's easier to read code between developers, examples, wiki pages, etc.

But if you really wanted to, you could try this:
extend Object

def yes as bool
return true

def no as bool
return false

# ...

success = .yes

Note that you need the leading period to access the extension methods. Also, Cobra does not look inside methods, so it won't really "know" that .yes is always true. Probably not a big deal, but something to consider.

Re: yes = true

PostPosted: Fri Jul 08, 2011 9:55 am
by ebaker355
Great! Thanks for the reply! Extending object is a nice workaround. Very helpful.